|
| 1 | +--- |
| 2 | +name: CI |
| 3 | + |
| 4 | +'on': |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + paths-ignore: |
| 8 | + - 'README.md' |
| 9 | + |
| 10 | +jobs: |
| 11 | + docker: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Convert repository name ot image name |
| 18 | + id: image_name |
| 19 | + run: | |
| 20 | + sed -E -e 's/docker-//' -e 's/^/image_name=/' <<<"${{ github.repository }}" >> "$GITHUB_OUTPUT" |
| 21 | +
|
| 22 | + - name: Generate Docker tag names |
| 23 | + id: meta |
| 24 | + uses: docker/metadata-action@v5 |
| 25 | + with: |
| 26 | + # list of Docker images to use as base name for tags |
| 27 | + images: | |
| 28 | + ghcr.io/${{ steps.image_name.outputs.image_name }} |
| 29 | + ${{ steps.image_name.outputs.image_name }} |
| 30 | + # generate Docker tags based on the following events/attributes |
| 31 | + tags: | |
| 32 | + # set edge tag for default branch |
| 33 | + type=edge,enable={{is_default_branch}} |
| 34 | + # set dev tag for dev branch |
| 35 | + type=raw,value=dev,enable=${{ github.ref == format('refs/heads/{0}', 'dev') }},branch=dev |
| 36 | + # set build-test tag for any branch not dev or the default one |
| 37 | + type=raw,value=build-test,enable=${{ github.ref != format('refs/heads/{0}', 'dev') && github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }},branch=dev |
| 38 | +
|
| 39 | + - name: Set up QEMU |
| 40 | + uses: docker/setup-qemu-action@v3 |
| 41 | + |
| 42 | + - name: Set up Docker Buildx |
| 43 | + uses: docker/setup-buildx-action@v3 |
| 44 | + |
| 45 | + - name: Login to GHCR |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ghcr.io |
| 49 | + username: ${{ github.repository_owner }} |
| 50 | + password: ${{ secrets.REGISTRY_TOKEN }} |
| 51 | + |
| 52 | + - name: Login to Docker Hub |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 56 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Build and push |
| 59 | + uses: docker/build-push-action@v5 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + platforms: linux/arm64/v8,linux/amd64 |
| 63 | + # Push only for default branch or dev branch |
| 64 | + push: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.ref == format('refs/heads/{0}', 'dev') }} |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
0 commit comments