diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 1f25f59d..22316d72 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -27,6 +27,8 @@ concurrency: permissions: packages: write + + jobs: build: runs-on: ubuntu-latest @@ -42,11 +44,15 @@ jobs: echo "BUILD_ARCH=${build_arch//\//-}" >> ${GITHUB_ENV} echo "REPOSITORY_LC=${REPOSITORY,,}" >> ${GITHUB_ENV} + # Get the repository's code - name: Checkout uses: actions/checkout@v4 - - uses: actions/setup-python@v3 + + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -71,6 +77,7 @@ jobs: - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 + - name: Login to GHCR uses: docker/login-action@v3 with: @@ -80,12 +87,12 @@ jobs: - name: Build and push id: build-and-push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./docker/Dockerfile platforms: ${{ matrix.docker_build_arch }} - no-cache: ${{ inputs.clean_build == true }} + no-cache: ${{ inputs.clean_build == true || false }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=ghcr.io/${{ env.REPOSITORY_LC }},push-by-digest=true,name-canonical=true,push=true cache-from: type=gha @@ -96,6 +103,7 @@ jobs: mkdir -p /tmp/digests digest="${{ steps.build-and-push.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest uses: actions/upload-artifact@v4 with: @@ -104,6 +112,8 @@ jobs: if-no-files-found: error retention-days: 1 + + merge: runs-on: ubuntu-latest needs: @@ -114,14 +124,17 @@ jobs: REPOSITORY: '${{ github.repository }}' run: | echo "REPOSITORY_LC=${REPOSITORY,,}" >> ${GITHUB_ENV} + - name: Download digests uses: actions/download-artifact@v4 with: path: /tmp/digests pattern: digests-* merge-multiple: true + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -137,17 +150,20 @@ jobs: type=semver,pattern={{major}} type=sha images: ghcr.io/${{ env.REPOSITORY_LC }} + - name: Login to Docker Hub uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf 'ghcr.io/${{ env.REPOSITORY_LC }}@sha256:%s ' *) + - name: Inspect image run: | docker buildx imagetools inspect ghcr.io/${{ env.REPOSITORY_LC }}:${{ steps.meta.outputs.version }} diff --git a/docker/Dockerfile b/docker/Dockerfile index ec41b993..de55cda4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # Get a base image -FROM docker.io/ros:noetic-ros-base-focal as base +FROM docker.io/ros:noetic-ros-base-focal AS base ENV DEBIAN_FRONTEND=noninteractive # Install required packages @@ -20,7 +20,7 @@ COPY --link ./docker/assets/nginx.conf /etc/nginx/conf.d/default.conf RUN rosdep update --rosdistro $ROS_DISTRO # First stage: Pull the git and all submodules, other stages depend on it -FROM base as fetch +FROM base AS fetch ENV DEBIAN_FRONTEND=noninteractive @@ -33,7 +33,7 @@ RUN git submodule update --init --recursive # Get slic3r_coverage_planner and build that. We will pull the finished install folder from this. # This stage should cache most of the time, that's why it's not derived from the fetch stage, but copies stuff instead. -FROM base as slic3r +FROM base AS slic3r ENV DEBIAN_FRONTEND=noninteractive @@ -53,7 +53,7 @@ RUN bash -c "source /opt/ros/$ROS_DISTRO/setup.bash && source /opt/slic3r_covera # If the package list is the same as last time, the apt install step is cached as well which saves a lot of time. # Since the list gets sorted, it will be the same each time and the cache will know that by file checksum in the COPY command. # We can't use this stage as base for the next, because this stage is run every time and would therefore invalidate the cache of the next stage. -FROM fetch as dependencies +FROM fetch AS dependencies ENV DEBIAN_FRONTEND=noninteractive @@ -67,7 +67,7 @@ RUN apt-get update && \ # We can't derive this from "dependencies" because "dependencies" will be rebuilt every time, but apt install should only be done if needed -FROM base as assemble +FROM base AS assemble ENV DEBIAN_FRONTEND=noninteractive