1
0
Fork 0

Build docker images

docker
Bo Jeanes 2022-09-11 18:43:55 +10:00
parent 6d193dd8ae
commit 7355ffa75c
3 changed files with 135 additions and 6 deletions

View File

@ -242,7 +242,9 @@ jobs:
prerelease:
name: Create a pre-release
if: github.ref == 'refs/heads/main'
needs: build
needs:
- build
- docker
runs-on: ubuntu-latest
steps:
- name: Checkout code
@ -310,4 +312,89 @@ jobs:
name: "Unstable (built from master)"
body: ${{ steps.changelog_reader.outputs.changes }}
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 }}

View File

@ -1,8 +1,11 @@
# -*- 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
RUN USER=rust cargo new /home/rust/sungrow-winets
@ -22,8 +25,13 @@ ADD --chown=rust:rust . ./
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
FROM debian:bullseye-slim
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 \
/home/rust/modbus-mqtt/target/release/modbus-mqtt \

34
Dockerfile.alpine 100644
View File

@ -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"]