|
| 1 | +name: Embedded Gateway Builder |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Tag to push on Docker Hub' |
| 8 | + required: true |
| 9 | + push_image: |
| 10 | + description: 'Push Docker image' |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: false |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - main |
| 17 | + paths: |
| 18 | + - .github/workflows/build-docker.yml |
| 19 | + - Dockerfile |
| 20 | + tags: |
| 21 | + - 'v*' |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: Build and push embedded-gateway-builder image |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Clone |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v2 |
| 37 | + |
| 38 | + - name: Log in to the Container registry |
| 39 | + uses: docker/login-action@v3 |
| 40 | + with: |
| 41 | + registry: ghcr.io |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Set tags based on event |
| 46 | + env: |
| 47 | + IMAGE_NAME: "ghcr.io/wirepas/embedded-gateway-builder" |
| 48 | + run: | |
| 49 | + # For a push triggered event, use the edge tag and push |
| 50 | + if [[ "${{ github.event_name }}" == "push" ]]; then |
| 51 | + echo "TAG=${IMAGE_NAME}:edge" >> $GITHUB_ENV |
| 52 | + echo "PUSH_IMAGE=true" >> $GITHUB_ENV |
| 53 | +
|
| 54 | + # For a manually triggered event, use the provided input prefixed by "manual_" for the tag and push if needed |
| 55 | + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 56 | + echo "TAG=${IMAGE_NAME}:manual_${{ github.event.inputs.tag }}" >> $GITHUB_ENV |
| 57 | + echo "PUSH_IMAGE=${{ github.event.inputs.push_image || 'false' }}" >> $GITHUB_ENV |
| 58 | +
|
| 59 | + # For a tag triggered event, use the version for the tag and push |
| 60 | + elif [[ "${{ github.event_name }}" == "tag" ]]; then |
| 61 | + echo "TAG=${IMAGE_NAME}:${{ github.ref_name }}" >> $GITHUB_ENV |
| 62 | + echo "PUSH_IMAGE=true" >> $GITHUB_ENV |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Build and push embedded-gateway-builder to GitHub Packages |
| 66 | + uses: docker/build-push-action@v6 |
| 67 | + with: |
| 68 | + push: ${{ env.PUSH_IMAGE }} |
| 69 | + tags: ${{ env.TAG }} |
0 commit comments