set to true for now #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push to ACR | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| push_image: | ||
| description: "Push image to ACR (false = build test only)" | ||
| required: true | ||
| default: false | ||
| type: boolean | ||
| push: | ||
| branches: | ||
| - "main" | ||
| - | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| env: | ||
| IMAGE_NAME: ship-traffic-generator | ||
| jobs: | ||
| build-and-optional-push: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Read package version and create image tags | ||
| id: meta | ||
| run: | | ||
| if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then | ||
| IMAGE_TAG=$(python -c "import tomllib, pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text(encoding='utf-8'))['project']['version'])") | ||
| else | ||
| IMAGE_TAG=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E 's|[^a-z0-9._-]+|-|g') | ||
| fi | ||
| echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT | ||
| echo "image=${{ secrets.ACR_LOGIN_SERVER }}/${IMAGE_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT | ||
| - name: Build only (test mode) | ||
| if: ${{ github.ref != 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.push_image) }} | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: false | ||
| tags: ${{ steps.meta.outputs.image }} | ||
| - name: Azure login (OIDC) | ||
| if: ${{ github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && inputs.push_image) }} | ||
| uses: azure/login@v2 | ||
| with: | ||
| client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
| - name: ACR login | ||
| if: ${{ github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && inputs.push_image) }} | ||
| run: az acr login --name ${{ secrets.ACR_NAME }} | ||
| - name: Build and push | ||
| if: ${{ github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && inputs.push_image) }} | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.image }} | ||