Rebuild docker images #349
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: docker-images | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - docker-test | |
| pull_request: | |
| branches: | |
| - master | |
| - docker-test | |
| workflow_dispatch: | |
| jobs: | |
| multi: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - ftpsync | |
| - nix-channels | |
| - rubygems-mirror | |
| - rustup-mirror | |
| # - shadowmire | |
| - tsumugu | |
| - tunasync-scripts | |
| # - freighter | |
| os: | |
| - ubuntu-latest | |
| - ubuntu-24.04-arm | |
| include: | |
| - image: tunasync-scripts | |
| dockerfile_dir: . | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - | |
| name: Determine dockerfile dir | |
| id: docker_file_dir | |
| env: | |
| DF: ${{ matrix.dockerfile_dir }} | |
| IMG: ${{ matrix.image }} | |
| run: | | |
| if [ -z "${DF}" ]; then | |
| DF="dockerfiles/${IMG}" | |
| fi | |
| echo "docker_file_dir=${DF}" >> $GITHUB_OUTPUT | |
| - | |
| name: Checkout | |
| uses: actions/checkout@v5 | |
| - | |
| name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - | |
| name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| if: github.event_name == 'push' | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ matrix.os }}-buildx-${{ matrix.image }}-${{ github.sha }} | |
| restore-keys: | | |
| ${{ matrix.os }}-buildx-${{ matrix.image }}-${{ matrix.os }}- | |
| ${{ matrix.os }}-buildx-${{ matrix.image }}- | |
| - | |
| name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ matrix.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}-${{ github.sha }} | |
| restore-keys: | | |
| ${{ matrix.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}- | |
| ${{ matrix.os }}-buildx-${{ matrix.image }}- | |
| ${{ matrix.os }}-buildx-${{ matrix.image }}- | |
| - | |
| name: Cache Docker layers | |
| if: github.event_name != 'push' && github.event_name != 'pull_request' | |
| run: | | |
| echo "I do not know how to setup cache" | |
| exit -1 | |
| - | |
| name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| if: github.event_name == 'push' | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - | |
| name: Build and push | |
| uses: docker/build-push-action@v6 | |
| id: docker_build | |
| with: | |
| context: . | |
| file: ${{ steps.docker_file_dir.outputs.docker_file_dir }}/Dockerfile | |
| push: ${{ github.event_name == 'push' }} | |
| tags: tunathu/${{ matrix.image }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache | |
| outputs: ${{ github.event_name == 'push' && 'type=image,push-by-digest=true,name-canonical=true,push=true' || 'type=image' }} | |
| - | |
| name: Export digest | |
| run: | | |
| mkdir -p ${{ runner.temp }}/digests/${{ matrix.image }} | |
| digest="${{ steps.docker_build.outputs.digest }}" | |
| touch "${{ runner.temp }}/digests/${{ matrix.image }}/${digest#sha256:}" | |
| - | |
| name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ matrix.image }}-${{ runner.arch }} | |
| path: ${{ runner.temp }}/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - multi | |
| if: always() && github.event_name == 'push' | |
| steps: | |
| - | |
| name: Determine docker tag | |
| id: docker_tag | |
| env: | |
| TAG_NAME: ${{ github.ref }} | |
| run: | | |
| if [ "${TAG_NAME##*/}" = "master" ]; then | |
| tag=latest | |
| else | |
| tag=build-test | |
| fi | |
| echo "docker_tag=${tag}" >> $GITHUB_OUTPUT | |
| - | |
| name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ runner.temp }}/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - | |
| name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - | |
| name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - | |
| name: Create manifest list and push | |
| working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| for i in *; do | |
| docker buildx imagetools create -t "tunathu/$i:${{ steps.docker_tag.outputs.docker_tag }}" \ | |
| $(printf "tunathu/$i@sha256:%s " $(ls $i)) | |
| done | |
| - name: Inspect images | |
| working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| for i in *; do | |
| DOCKER_IMG="tunathu/$i:${{ steps.docker_tag.outputs.docker_tag }}" | |
| echo "## $DOCKER_IMG" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| docker buildx imagetools inspect "$DOCKER_IMG" | tee -a $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| done |