From 9f25fa432539955b229f453ffd5849aa2cb2f9c5 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 17 Dec 2020 15:27:24 +0700 Subject: [PATCH 1/2] Do docker in three stages --- .github/workflows/docker.yml | 46 +++++++++++++++++++++++++++++---- Dockerfile | 50 +++++++++++++++++++++++++++--------- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a6393157..39a7136d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,12 +29,48 @@ jobs: uses: ASzc/change-string-case-action@v1 with: string: ${{ github.repository }} - - name: Push to Docker Hub - uses: docker/build-push-action@v1 + - name: Set up QEMU + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/setup-buildx-action@v1 + - name: Login to dockerhub if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/login-action@v1 with: username: ${{ steps.string_user.outputs.lowercase }} password: ${{ secrets.DOCKER_TOKEN }} - registry: docker.io - repository: ${{ steps.string_repo.outputs.lowercase }} - tag_with_ref: true + - name: Get tag name + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + id: tags + run: | + branch="${GITHUB_REF#refs/heads/}" + tags="${REPO_NAME}:${branch}" + if [ "${branch}" == "master" ]; then + tags="${tags},${REPO_NAME}:latest" + fi + echo "::set-output name=TAGS::${tags}" + env: + REPO_NAME: ${{ steps.string_repo.outputs.lowercase }} + - name: Install toml-cli + uses: actions-rs/install@v0.1 + with: + crate: toml-cli + version: latest + - name: Get project version + id: toml + run: | + NEOLINK_VERSION="$(toml get Cargo.toml package.version | sed 's|"||g')" + echo "::set-output name=version::${NEOLINK_VERSION}" + - name: Push to Docker Hub + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + push: true + file: Dockerfile + tags: ${{ steps.tags.outputs.TAGS }} + build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ github.repository_owner }} + env: + DOCKER_BUILDKIT: 1 diff --git a/Dockerfile b/Dockerfile index 400feb2a..508519cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,27 @@ # Copyright (c) 2020 George Hilliard # SPDX-License-Identifier: AGPL-3.0-only -FROM docker.io/rust:1-alpine AS build -MAINTAINER thirtythreeforty@gmail.com +################################# +## SETUP ## +################################# +FROM docker.io/alpine:edge AS setup +ARG TARGETPLATFORM + +RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing libgcc \ + tzdata \ + gstreamer \ + gst-plugins-base \ + gst-plugins-good \ + gst-plugins-bad \ + gst-plugins-ugly \ + gst-rtsp-server + + +################################# +## BUILD ## +################################# +FROM setup AS build +ARG TARGETPLATFORM # Until Alpine merges gst-rtsp-server into a release, pull all Gstreamer packages # from the "testing" release @@ -12,6 +31,7 @@ RUN apk add --no-cache \ -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ gst-rtsp-server-dev RUN apk add --no-cache musl-dev gcc +RUN apk add --no-cache rust cargo # Use static linking to work around https://github.com/rust-lang/rust/pull/58575 ENV RUSTFLAGS='-C target-feature=-crt-static' @@ -22,23 +42,29 @@ WORKDIR /usr/local/src/neolink COPY . /usr/local/src/neolink RUN cargo build --release + +################################# +## PUBLISH ## +################################# # Create the release container. Match the base OS used to build -FROM docker.io/alpine:latest +FROM setup +ARG TARGETPLATFORM +ARG REPO +ARG VERSION +ARG OWNER -RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing libgcc \ - tzdata \ - gstreamer \ - gst-plugins-base \ - gst-plugins-good \ - gst-plugins-bad \ - gst-plugins-ugly \ - gst-rtsp-server +LABEL description="An image for the neolink program which is a reolink camera to rtsp translator" +LABEL repository="$REPO" +LABEL version="$VERSION" +LABEL maintainer="$OWNER" COPY --from=build \ /usr/local/src/neolink/target/release/neolink \ /usr/local/bin/neolink + COPY docker/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh CMD ["/usr/local/bin/neolink", "--config", "/etc/neolink.toml"] ENTRYPOINT ["/entrypoint.sh"] -EXPOSE 8554 +EXPOSE 8554 From b86d6eee9fe368fc3160fb01a59dec335914eb01 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 18 Dec 2020 13:28:34 +0700 Subject: [PATCH 2/2] Add armv7 and armv6 --- .github/workflows/docker.yml | 2 +- Dockerfile | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 39a7136d..77e39f7b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -67,7 +67,7 @@ jobs: if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v2 with: - platforms: linux/amd64 + platforms: linux/amd64,linux/arm/v7,linux/arm/v6 push: true file: Dockerfile tags: ${{ steps.tags.outputs.TAGS }} diff --git a/Dockerfile b/Dockerfile index 508519cc..2a80221a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,9 @@ ################################# ## SETUP ## ################################# +# This is the generic base for # +# all other dockers to follow # +################################# FROM docker.io/alpine:edge AS setup ARG TARGETPLATFORM @@ -21,6 +24,9 @@ RUN apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing libg ################################# ## BUILD ## ################################# +# Install dev packages and # +# with cargo # +################################# FROM setup AS build ARG TARGETPLATFORM @@ -46,7 +52,9 @@ RUN cargo build --release ################################# ## PUBLISH ## ################################# -# Create the release container. Match the base OS used to build +# Copy from build neolink and # +# prepares for execution # +################################# FROM setup ARG TARGETPLATFORM ARG REPO