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 - pub-mirror - rubygems-mirror - rustup-mirror - shadowmire - tsumugu - tunasync-scripts # - freighter os: - ubuntu-latest - ubuntu-24.04-arm include: - image: tunasync-scripts dockerfile_dir: . # - image: julia-mirror # dockerfile: dockerfiles/julia 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: ${{ runner.os }}-${{ runner.arch }}-buildx-${{ matrix.image }}-${{ matrix.os }}-${{ github.sha }} restore-keys: | ${{ runner.os }}-${{ runner.arch }}-buildx-${{ matrix.image }}-${{ matrix.os }}- ${{ runner.os }}-${{ runner.arch }}-buildx-${{ matrix.image }}- - name: Cache Docker layers uses: actions/cache@v4 if: github.event_name == 'pull_request' with: path: /tmp/.buildx-cache key: ${{ runner.os }}-${{ runner.arch }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}-${{ matrix.os }}-${{ github.sha }} restore-keys: | ${{ runner.os }}-${{ runner.arch }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}-${{ matrix.os }}- ${{ runner.os }}-${{ runner.arch }}-buildx-${{ matrix.image }}-${{ matrix.os }}- ${{ runner.os }}-${{ runner.arch }}-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: dockerbuild 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.dockerbuild.outputs.digest }}" touch "${{ runner.temp }}/digests/${{ matrix.image }}/${digest#sha256:}" - name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-${{ matrix.image }}-${{ matrix.os }} 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 buildx imagetools inspect "tunathu/$i:${{ steps.docker_tag.outputs.docker_tag }}" done