|
| 1 | +name: Docker multiarch publish |
| 2 | + |
| 3 | +on: push |
| 4 | + |
| 5 | +env: |
| 6 | + REPOSITORY: moodle-php-apache |
| 7 | + DOCKERHUB_OWNER: moodlehq |
| 8 | + GH_OWNER: moodlehq |
| 9 | + |
| 10 | +jobs: |
| 11 | + Build: |
| 12 | + # Completely avoid forks to try this workflow. |
| 13 | + if: github.repository_owner == 'moodlehq' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + # Calculate the tags to be pussed to the registries. |
| 20 | + - name: Calculate image tag names |
| 21 | + id: calculatetags |
| 22 | + uses: docker/metadata-action@v3 |
| 23 | + with: |
| 24 | + images: | |
| 25 | + ${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }} |
| 26 | + ghcr.io/${{ env.GH_OWNER }}/${{ env.REPOSITORY }} |
| 27 | + flavor: | |
| 28 | + latest=false |
| 29 | + tags: | |
| 30 | + type=raw,value=dev |
| 31 | +
|
| 32 | + # https://github.com/docker/setup-qemu-action#usage |
| 33 | + - name: Set up QEMU |
| 34 | + uses: docker/setup-qemu-action@v1 |
| 35 | + |
| 36 | + # https://github.com/marketplace/actions/docker-setup-buildx |
| 37 | + - name: Set up Docker Buildx |
| 38 | + uses: docker/setup-buildx-action@v1 |
| 39 | + |
| 40 | + # https://github.com/docker/login-action#docker-hub |
| 41 | + - name: Login to Docker Hub |
| 42 | + uses: docker/login-action@v1 |
| 43 | + with: |
| 44 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 45 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 46 | + |
| 47 | + # https://github.com/docker/login-action#github-container-registry |
| 48 | + - name: Login to GitHub Container Registry |
| 49 | + uses: docker/login-action@v1 |
| 50 | + with: |
| 51 | + registry: ghcr.io |
| 52 | + username: ${{ secrets.GH_USERNAME }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + # https://github.com/docker/build-push-action#multi-platform-image |
| 56 | + - name: Build and push to Docker Hub and Github registries |
| 57 | + uses: docker/build-push-action@v2 |
| 58 | + with: |
| 59 | + context: . |
| 60 | + file: Dockerfile |
| 61 | + platforms: linux/amd64,linux/arm64 |
| 62 | + push: true |
| 63 | + tags: ${{ steps.calculatetags.outputs.tags }} |
| 64 | + |
| 65 | + # https://github.com/peter-evans/dockerhub-description |
| 66 | + # It's horrible that we need to use password here instead of PAT, because |
| 67 | + # that's only available via CLI what defeats 2FA. Anyway, we need to |
| 68 | + # auto-update de description, so using it (till available via PAT). |
| 69 | + # Link: https://github.com/peter-evans/dockerhub-description/issues/10 |
| 70 | + # Note that we only update the description with the master branch version. |
| 71 | + - name: Set Docker Hub description from README.md |
| 72 | + if: github.ref == 'refs/heads/master' |
| 73 | + uses: peter-evans/dockerhub-description@v2 |
| 74 | + with: |
| 75 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 76 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 77 | + repository: ${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }} |
0 commit comments