Build docker images
parent
6d193dd8ae
commit
7355ffa75c
|
@ -242,7 +242,9 @@ jobs:
|
||||||
prerelease:
|
prerelease:
|
||||||
name: Create a pre-release
|
name: Create a pre-release
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
needs: build
|
needs:
|
||||||
|
- build
|
||||||
|
- docker
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
@ -311,3 +313,88 @@ jobs:
|
||||||
body: ${{ steps.changelog_reader.outputs.changes }}
|
body: ${{ steps.changelog_reader.outputs.changes }}
|
||||||
files: ${{ steps.artifacts.outputs.files }}
|
files: ${{ steps.artifacts.outputs.files }}
|
||||||
gzip: false
|
gzip: false
|
||||||
|
|
||||||
|
docker:
|
||||||
|
needs:
|
||||||
|
- tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ github.repository }}
|
||||||
|
ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=sha,format=short
|
||||||
|
type=edge,branch=main
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}},enable=${{ !contains(github.ref, 'v0.') }}
|
||||||
|
type=ref,enable=true,priority=600,prefix=br-,suffix=,event=branch
|
||||||
|
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
|
||||||
|
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=pr
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta-alpine
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
flavour:
|
||||||
|
suffix=-alpine
|
||||||
|
images: |
|
||||||
|
${{ github.repository }}
|
||||||
|
ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=sha,format=short
|
||||||
|
type=edge,branch=main
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}},enable=${{ !contains(github.ref, 'v0.') }}
|
||||||
|
type=ref,enable=true,priority=600,prefix=br-,suffix=,event=branch
|
||||||
|
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
|
||||||
|
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=pr
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push (alpine)
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: |
|
||||||
|
linux/arm64
|
||||||
|
linux/amd64
|
||||||
|
push: true
|
||||||
|
file: Dockerfile.alpine
|
||||||
|
tags: ${{ steps.meta-alpine.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta-alpine.outputs.labels }}
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: |
|
||||||
|
linux/arm/v7
|
||||||
|
linux/arm64
|
||||||
|
linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
16
Dockerfile
16
Dockerfile
|
@ -1,8 +1,11 @@
|
||||||
# -*- mode: dockerfile -*-
|
# -*- mode: dockerfile -*-
|
||||||
|
|
||||||
FROM rust:1.63-alpine AS builder
|
FROM rust:1.63 AS builder
|
||||||
|
|
||||||
RUN apk add --no-cache musl-dev
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
|
apt update && apt-get --no-install-recommends install -y \
|
||||||
|
libudev-dev
|
||||||
|
|
||||||
# Build a cacheable layer with project dependencies
|
# Build a cacheable layer with project dependencies
|
||||||
RUN USER=rust cargo new /home/rust/sungrow-winets
|
RUN USER=rust cargo new /home/rust/sungrow-winets
|
||||||
|
@ -22,8 +25,13 @@ ADD --chown=rust:rust . ./
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
# Now, we need to build our _real_ Docker container, copying in `bump-api`.
|
# Now, we need to build our _real_ Docker container, copying in `bump-api`.
|
||||||
FROM alpine:latest
|
FROM debian:bullseye-slim
|
||||||
RUN apk --no-cache add ca-certificates
|
|
||||||
|
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
|
||||||
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
|
apt update && apt-get --no-install-recommends install -y \
|
||||||
|
libudev1
|
||||||
|
|
||||||
COPY --from=builder \
|
COPY --from=builder \
|
||||||
/home/rust/modbus-mqtt/target/release/modbus-mqtt \
|
/home/rust/modbus-mqtt/target/release/modbus-mqtt \
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# -*- mode: dockerfile -*-
|
||||||
|
|
||||||
|
FROM rust:1.63-alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev
|
||||||
|
|
||||||
|
# Build a cacheable layer with project dependencies
|
||||||
|
RUN USER=rust cargo new /home/rust/sungrow-winets
|
||||||
|
RUN USER=rust cargo new /home/rust/tokio_modbus-winets
|
||||||
|
RUN USER=rust cargo new /home/rust/modbus-mqtt
|
||||||
|
WORKDIR /home/rust/modbus-mqtt
|
||||||
|
ADD --chown=rust:rust Cargo.lock modbus-mqtt/Cargo.toml ./
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
# # Delete files & directories which shouldn't exist for the workspace
|
||||||
|
# RUN rm -rf src
|
||||||
|
|
||||||
|
# Add our source code.
|
||||||
|
ADD --chown=rust:rust . ./
|
||||||
|
|
||||||
|
# Build our application.
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
# Now, we need to build our _real_ Docker container, copying in `bump-api`.
|
||||||
|
FROM alpine:latest
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
COPY --from=builder \
|
||||||
|
/home/rust/modbus-mqtt/target/release/modbus-mqtt \
|
||||||
|
/usr/local/bin/
|
||||||
|
|
||||||
|
ENV RUST_LOG=warn,modbus_mqtt=info
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/modbus-mqtt"]
|
Loading…
Reference in New Issue