From aead6ccbff406e785b0fd6a528bb656f1c41ab7a Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 5 Jan 2023 19:09:07 +0700 Subject: [PATCH] Rework dockerfile to reduce uneeded builds if not compiling --- .github/workflows/build.yml | 5 +++-- Dockerfile | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8513fa3..132ae6d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -198,6 +198,7 @@ jobs: run: | mkdir linux mkdir linux/arm + mkdir linux/arm64 - name: Download Linux x86_64 uses: actions/download-artifact@v3 with: @@ -212,7 +213,7 @@ jobs: uses: actions/download-artifact@v3 with: name: release-arm64-buster - path: linux/arm64 + path: linux/arm64/v8 - name: Download Linux i386 uses: actions/download-artifact@v3 with: @@ -222,7 +223,7 @@ jobs: if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} uses: docker/build-push-action@v3 with: - platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386 + platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/386 push: true file: Dockerfile tags: ${{ steps.tags.outputs.TAGS }} diff --git a/Dockerfile b/Dockerfile index a7caccf..cfdfb9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,25 +8,28 @@ FROM docker.io/rust:slim-buster AS build ARG TARGETPLATFORM ENV DEBIAN_FRONTEND=noninteractive -# hadolint ignore=DL3008 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential \ - libgstrtspserver-1.0-dev \ - libgstreamer1.0-dev \ - libgtk2.0-dev \ - libglib2.0-dev && \ - apt-get clean -y && rm -rf /var/lib/apt/lists/* + WORKDIR /usr/local/src/neolink - -# Build the main program or copy from github build ones COPY . /usr/local/src/neolink -RUN echo "TARGETPLATFORM; ${TARGETPLATFORM}"; \ + +# Build the main program or copy from artifact +# hadolint ignore=DL3008 +RUN echo "TARGETPLATFORM: ${TARGETPLATFORM}"; \ if [ -f "${TARGETPLATFORM}/neolink" ]; then \ + echo "Restoring from artifact"; \ mkdir -p /usr/local/src/neolink/target/release/; \ cp "${TARGETPLATFORM}/neolink" "/usr/local/src/neolink/target/release/neolink"; \ else \ + echo "Building from scratch"; \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libgstrtspserver-1.0-dev \ + libgstreamer1.0-dev \ + libgtk2.0-dev \ + libglib2.0-dev && \ + apt-get clean -y && rm -rf /var/lib/apt/lists/* ; \ cargo build --release; \ fi