From 880b42ea61853d999c5b87d79264572b1fa07c15 Mon Sep 17 00:00:00 2001 From: Vito Date: Wed, 8 Jan 2025 07:00:10 +0000 Subject: [PATCH] refactor(ci): Use docker/build-push-action to build docker images Replace the build-docker.sh script with a GitHub action to standardize the ci workflow and reduce complexity. --- .github/scripts/build-docker-alpine.sh | 27 ---------- .github/scripts/build-docker.sh | 29 ----------- .github/workflows/ci.yml | 68 ++++++++++++++++++-------- 3 files changed, 47 insertions(+), 77 deletions(-) delete mode 100755 .github/scripts/build-docker-alpine.sh delete mode 100755 .github/scripts/build-docker.sh diff --git a/.github/scripts/build-docker-alpine.sh b/.github/scripts/build-docker-alpine.sh deleted file mode 100755 index 8aa226ca64..0000000000 --- a/.github/scripts/build-docker-alpine.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -set -eux - -APK_FILE="$1" -TAG="$2" -ARCHITECTURE="$3" - -docker build \ - --pull \ - --no-cache \ - --provenance false \ - --build-arg "APK_FILE=$APK_FILE" \ - --file .github/docker/alpine.dockerfile \ - --tag "savonet/liquidsoap-ci-build:${TAG}_alpine_${ARCHITECTURE}" \ - . - -if [ "${PUBLISH_DOCKER_IMAGE}" != "true" ]; then - exit 0 -fi - -docker tag \ - "savonet/liquidsoap-ci-build:${TAG}_alpine_${ARCHITECTURE}" \ - "ghcr.io/savonet/liquidsoap-ci-build:${TAG}_alpine_${ARCHITECTURE}" - -docker push "savonet/liquidsoap-ci-build:${TAG}_alpine_${ARCHITECTURE}" -docker push "ghcr.io/savonet/liquidsoap-ci-build:${TAG}_alpine_${ARCHITECTURE}" diff --git a/.github/scripts/build-docker.sh b/.github/scripts/build-docker.sh deleted file mode 100755 index e312c47f86..0000000000 --- a/.github/scripts/build-docker.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -set -eux - -DEB_FILE="$1" -DEB_DEBUG_FILE="$2" -TAG="$3" -ARCHITECTURE="$4" - -docker build \ - --pull \ - --no-cache \ - --provenance false \ - --build-arg "DEB_FILE=$DEB_FILE" \ - --build-arg "DEB_DEBUG_FILE=$DEB_DEBUG_FILE" \ - --file .github/docker/debian.dockerfile \ - --tag "savonet/liquidsoap-ci-build:${TAG}_${ARCHITECTURE}" \ - . - -if [ "${PUBLISH_DOCKER_IMAGE}" != "true" ]; then - exit 0 -fi - -docker tag \ - "savonet/liquidsoap-ci-build:${TAG}_${ARCHITECTURE}" \ - "ghcr.io/savonet/liquidsoap-ci-build:${TAG}_${ARCHITECTURE}" - -docker push "savonet/liquidsoap-ci-build:${TAG}_${ARCHITECTURE}" -docker push "ghcr.io/savonet/liquidsoap-ci-build:${TAG}_${ARCHITECTURE}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1ff92e14e..18f65bb9df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -651,10 +651,18 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build docker image - env: - PUBLISH_DOCKER_IMAGE: ${{ needs.build_details.outputs.publish_docker_image }} - run: .github/scripts/build-docker.sh "${{ steps.debian_package.outputs.deb-file }}" "${{ steps.debian_debug_package.outputs.deb-file }}" "${{ needs.build_details.outputs.branch }}" "${{ matrix.platform }}" + - name: Build and push docker image + uses: docker/build-push-action@v6 + with: + build-args: | + "DEB_FILE=${{ steps.debian_package.outputs.deb-file }}" + "DEB_DEBUG_FILE=${{ steps.debian_debug_package.outputs.deb-file }}" + context: . + file: .github/docker/debian.dockerfile + tags: | + "savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}_${{ matrix.platform }}" + "ghcr.io/savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}_${{ matrix.platform }}" + push: ${{ needs.build_details.outputs.publish_docker_image }} build_docker_alpine: runs-on: ${{ matrix.runs-on }} @@ -691,10 +699,17 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build docker image - env: - PUBLISH_DOCKER_IMAGE: ${{ needs.build_details.outputs.publish_docker_image }} - run: .github/scripts/build-docker-alpine.sh "${{ steps.alpine_package.outputs.apk-file }}" "${{ needs.build_details.outputs.branch }}" "${{ matrix.platform }}" + - name: Build and push docker image + uses: docker/build-push-action@v6 + with: + build-args: | + "APK_FILE=${{ steps.alpine_package.outputs.apk-file }}" + context: . + file: .github/docker/alpine.dockerfile + tags: | + "savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}_alpine_${{ matrix.platform }}" + "ghcr.io/savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}_alpine_${{ matrix.platform }}" + push: ${{ needs.build_details.outputs.publish_docker_image }} build_docker_minimal: runs-on: ${{ matrix.runs-on }} @@ -734,14 +749,22 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build docker image - env: - PUBLISH_DOCKER_IMAGE: ${{ needs.build_details.outputs.publish_docker_image }} - run: .github/scripts/build-docker.sh "${{ steps.debian_package.outputs.deb-file }}" "${{ steps.debian_debug_package.outputs.deb-file }}" "${{ needs.build_details.outputs.branch }}-minimal" "${{ matrix.platform }}" + - name: Build and push docker image + uses: docker/build-push-action@v6 + with: + build-args: | + "DEB_FILE=${{ steps.debian_package.outputs.deb-file }}" + "DEB_DEBUG_FILE=${{ steps.debian_debug_package.outputs.deb-file }}" + context: . + file: .github/docker/debian.dockerfile + tags: | + "savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}-minimal_${{ matrix.platform }}" + "ghcr.io/savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}-minimal_${{ matrix.platform }}" + push: ${{ needs.build_details.outputs.publish_docker_image }} build_docker_alpine_minimal: runs-on: ${{ matrix.runs-on }} - needs: [build_details, run_tests, build_posix, fetch_s3_artifacts] + needs: [build_details, build_posix, fetch_s3_artifacts] if: needs.build_details.outputs.is_fork != 'true' strategy: fail-fast: false @@ -761,10 +784,6 @@ jobs: run: | echo "apk-file=$(find artifacts/${{ needs.build_details.outputs.sha }} -type f | grep minimal | grep 'apk$' | grep -v dbg | grep ${{ matrix.alpine-arch }})" >> "${GITHUB_OUTPUT}" id: alpine_package - - name: Get alpine debug package - run: | - echo "apk-file=$(find artifacts/${{ needs.build_details.outputs.sha }} -type f | grep minimal | grep 'apk$' | grep dbg | grep ${{ matrix.alpine-arch }})" >> "${GITHUB_OUTPUT}" - id: alpine_dbg_package - name: Login to Docker Hub if: needs.build_details.outputs.publish_docker_image == 'true' uses: docker/login-action@v3 @@ -778,10 +797,17 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build docker image - env: - PUBLISH_DOCKER_IMAGE: ${{ needs.build_details.outputs.publish_docker_image }} - run: .github/scripts/build-docker-alpine.sh "${{ steps.alpine_package.outputs.apk-file }}" "${{ steps.alpine_dbg_package.outputs.apk-file }}" "${{ needs.build_details.outputs.branch }}-minimal" "${{ matrix.platform }}" + - name: Build and push docker image + uses: docker/build-push-action@v6 + with: + build-args: | + "APK_FILE=${{ steps.alpine_package.outputs.apk-file }}" + context: . + file: .github/docker/alpine.dockerfile + tags: | + "savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}-minimal_alpine_${{ matrix.platform }}" + "ghcr.io/savonet/liquidsoap-ci-build:${{ needs.build_details.outputs.branch }}-minimal_alpine_${{ matrix.platform }}" + push: ${{ needs.build_details.outputs.publish_docker_image }} build_docker_release: runs-on: ubuntu-latest