|
| 1 | +name: Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - 'main' |
| 12 | + |
| 13 | +jobs: |
| 14 | + docker: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + env: |
| 18 | + IMAGE_NAME: spaceapi-service |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + ref: ${{ github.ref }} |
| 25 | + # Needed for correct version detection |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Docker meta |
| 29 | + id: meta |
| 30 | + uses: docker/metadata-action@v3 |
| 31 | + with: |
| 32 | + images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} |
| 33 | + tags: | |
| 34 | + # 1.2.3 |
| 35 | + type=semver,pattern={{version}} |
| 36 | + # disabled if major zero |
| 37 | + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} |
| 38 | + # generate lates from default branch |
| 39 | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} |
| 40 | +
|
| 41 | + - name: Set up QEMU |
| 42 | + uses: docker/setup-qemu-action@v1 |
| 43 | + |
| 44 | + - name: Set up Docker Buildx |
| 45 | + uses: docker/setup-buildx-action@v1 |
| 46 | + |
| 47 | + - name: Login to DockerHub |
| 48 | + if: github.event_name != 'pull_request' |
| 49 | + uses: docker/login-action@v1 |
| 50 | + with: |
| 51 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 52 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Build and push |
| 55 | + uses: docker/build-push-action@v2 |
| 56 | + with: |
| 57 | + context: . |
| 58 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 59 | + push: ${{ github.event_name != 'pull_request' }} |
| 60 | + tags: ${{ steps.meta.outputs.tags }} |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments