|
| 1 | +name: Build Docker Image |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: "0 0 */6 * *" |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - latest |
| 8 | + - develop |
| 9 | + paths: |
| 10 | + - Dockerfile |
| 11 | + - .github/workflows/docker.yml |
| 12 | + pull_request: |
| 13 | + paths: |
| 14 | + - Dockerfile |
| 15 | + - .github/workflows/docker.yml |
| 16 | + workflow_dispatch: |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v3 |
| 23 | + - name: Set up QEMU |
| 24 | + uses: docker/setup-qemu-action@v2 |
| 25 | + with: |
| 26 | + platforms: arm64 #all |
| 27 | + - name: Set up Docker Buildx |
| 28 | + uses: docker/setup-buildx-action@v2 |
| 29 | + with: |
| 30 | + driver-opts: env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 |
| 31 | + - name: Login to DockerHub |
| 32 | + if: ${{ github.event_name != 'pull_request' }} |
| 33 | + uses: docker/login-action@v2 |
| 34 | + with: |
| 35 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 36 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 37 | + - name: Convert Username |
| 38 | + id: un |
| 39 | + run: echo "un=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT |
| 40 | + - name: Login to GitHub Container Registry |
| 41 | + uses: docker/login-action@v2 |
| 42 | + with: |
| 43 | + registry: ghcr.io |
| 44 | + username: ${{ steps.un.outputs.un }} |
| 45 | + password: ${{ github.token }} |
| 46 | + - name: Build |
| 47 | + uses: docker/build-push-action@v4 |
| 48 | + if: ${{ github.event_name != 'pull_request' }} |
| 49 | + with: |
| 50 | + context: . |
| 51 | + file: ./Dockerfile |
| 52 | + platforms: linux/amd64,linux/arm64 #,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4 #,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 |
| 53 | + push: ${{ github.event_name != 'pull_request' }} |
| 54 | + tags: | |
| 55 | + ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} |
| 56 | + ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} |
| 57 | + ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} |
| 58 | + ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} |
| 59 | + build-args: | |
| 60 | + "BUILD=${{ github.event.repository.name }}" |
| 61 | + - name: show version |
| 62 | + if: ${{ github.event_name != 'pull_request' }} |
| 63 | + run: | |
| 64 | + docker run --rm ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} -V |
| 65 | + docker run --rm ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} -V |
| 66 | + docker run --rm ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} -V |
| 67 | + docker run --rm ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} -V |
| 68 | + - name: copy nginx binary |
| 69 | + if: ${{ github.event_name != 'pull_request' }} |
| 70 | + run: | |
| 71 | + docker run -d --pull always --platform amd64 --name nginx-x86_64 ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} |
| 72 | + docker cp nginx-x86_64:/usr/local/nginx/sbin/nginx nginx-x86_64 |
| 73 | + docker run -d --pull always --platform arm64 --name nginx-aarch64 ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} |
| 74 | + docker cp nginx-aarch64:/usr/local/nginx/sbin/nginx nginx-aarch64 |
| 75 | + - uses: actions/upload-artifact@v3 |
| 76 | + if: ${{ github.event_name != 'pull_request' }} |
| 77 | + with: |
| 78 | + name: artifacts |
| 79 | + path: | |
| 80 | + nginx-x86_64 |
| 81 | + nginx-aarch64 |
| 82 | + - uses: "marvinpinto/action-automatic-releases@latest" |
| 83 | + if: ${{ github.event_name != 'pull_request' }} |
| 84 | + with: |
| 85 | + prerelease: false |
| 86 | + repo_token: ${{ github.token }} |
| 87 | + title: ${{ github.run_number }} |
| 88 | + automatic_release_tag: ${{ github.run_number }} |
| 89 | + files: | |
| 90 | + nginx-x86_64 |
| 91 | + nginx-aarch64 |
| 92 | + - name: Set PR-Number (PR) |
| 93 | + if: ${{ github.event_name == 'pull_request' }} |
| 94 | + id: pr |
| 95 | + run: echo "pr=$(echo pr-${{ github.ref_name }} | sed "s|refs/pull/:||g" | sed "s|/merge||g")" >> $GITHUB_OUTPUT |
| 96 | + - name: Build (PR) |
| 97 | + uses: docker/build-push-action@v4 |
| 98 | + if: ${{ github.event_name == 'pull_request' }} |
| 99 | + with: |
| 100 | + context: . |
| 101 | + file: ./Dockerfile |
| 102 | + platforms: linux/amd64,linux/arm64 #,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4 #,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 |
| 103 | + push: ${{ github.event_name == 'pull_request' }} |
| 104 | + tags: ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ steps.pr.outputs.pr }} |
| 105 | + build-args: | |
| 106 | + "BUILD=${{ github.event.repository.name }}" |
| 107 | + - name: show version (PR) |
| 108 | + if: ${{ github.event_name == 'pull_request' }} |
| 109 | + run: docker run --rm ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ steps.pr.outputs.pr }} -V |
| 110 | + - name: add comment (PR) |
| 111 | + uses: mshick/add-pr-comment@v2 |
| 112 | + if: ${{ github.event_name == 'pull_request' }} |
| 113 | + with: |
| 114 | + message: "The Docker Image can now be found here: `ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ steps.pr.outputs.pr }}`" |
| 115 | + repo-token: ${{ github.token }} |
0 commit comments