|
| 1 | +name: Build and push docker image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +env: |
| 7 | + REGISTRY: ghcr.io |
| 8 | + IMAGE_NAME: nilchain-devnet |
| 9 | + |
| 10 | +jobs: |
| 11 | + docker-build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Extract metadata (tags, labels) for Docker |
| 20 | + id: meta |
| 21 | + uses: docker/metadata-action@v4 |
| 22 | + with: |
| 23 | + images: ${{ env.REGISTRY }}/NillionNetwork/${{ env.IMAGE_NAME }} |
| 24 | + tags: | |
| 25 | + type=ref,event=branch |
| 26 | + type=ref,event=tag |
| 27 | + flavor: | |
| 28 | + latest=false # Ensure 'latest' tag is not generated |
| 29 | +
|
| 30 | + - name: Set VERSION environment variable |
| 31 | + run: | |
| 32 | + # Extract the first tag from the generated tags |
| 33 | + TAG=$(echo ${{ steps.meta.outputs.tags }} | cut -d ',' -f 1) |
| 34 | + TAG=$(echo $TAG | cut -d ':' -f 2) |
| 35 | + echo "VERSION=$TAG" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: Build Docker image |
| 38 | + uses: docker/build-push-action@v2 |
| 39 | + with: |
| 40 | + context: . |
| 41 | + tags: ${{ steps.meta.outputs.tags }} |
| 42 | + build-args: | |
| 43 | + VERSION=${{ env.VERSION }} |
| 44 | +
|
| 45 | + - name: Debug tags |
| 46 | + run: | |
| 47 | + echo "Generated tags: ${{ steps.meta.outputs.tags }}" |
| 48 | + echo "Generated labels: ${{ steps.meta.outputs.labels }}" |
| 49 | +
|
| 50 | + - name: List Docker images |
| 51 | + run: docker images |
| 52 | + |
| 53 | + - name: Log in to the Container registry |
| 54 | + uses: docker/login-action@v2 |
| 55 | + with: |
| 56 | + registry: ${{ env.REGISTRY }} |
| 57 | + username: ${{ github.actor }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Push Docker image |
| 61 | + uses: docker/build-push-action@v2 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + push: true |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
| 66 | + build-args: | |
| 67 | + VERSION=${{ env.VERSION }} |
0 commit comments