Fix working directory approach for multi-module builds #1
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 | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| runner-size: | ||
| required: false | ||
| type: string | ||
| default: 'normal' | ||
| description: 'Runner size (normal or large)' | ||
| stage: | ||
| required: true | ||
| type: string | ||
| description: 'stage being released (dev,staging,production)' | ||
| service-name: | ||
| required: true | ||
| type: string | ||
| description: 'Proper name for your service i.e OCPP Service, Vehicle Service' | ||
| service-emoji: | ||
| required: true | ||
| type: string | ||
| description: 'An emoji to identify your service by :)' | ||
| service-identifier: | ||
| required: true | ||
| type: string | ||
| description: 'Identifier of the service being released i.e ocpp, vehicle, server, wallet.' | ||
| gradle-module: | ||
| required: false | ||
| type: string | ||
| description: 'Name of the Gradle module (for multi-module projects). Used as base directory for finding Dockerfile and source code.' | ||
| region: | ||
| required: false | ||
| type: string | ||
| default: "eu-west-1" | ||
| description: 'AWS region to deploy to (defaults to "eu-west-1")' | ||
| docker-file-name: | ||
| required: false | ||
| type: string | ||
| description: Name of the docker file to be built | ||
| default: "Dockerfile" | ||
| additional-build-args: | ||
| required: false | ||
| type: string | ||
| description: "Optional additional build arguments to pass to the Docker build process. Specify each argument on a new line in the format KEY=VALUE." | ||
| ecr-repository-name: | ||
| required: false | ||
| type: string | ||
| description: 'Custom ECR repository name. If not specified, defaults to service-identifier' | ||
| slack-message-id: | ||
| required: false | ||
| type: string | ||
| description: 'Existing Slack message ID to update' | ||
| secrets: | ||
| AWS_ACCOUNT_ID: | ||
| required: true | ||
| description: 'AWS account id' | ||
| SLACK_APP_TOKEN: | ||
| required: true | ||
| description: 'Slack app token' | ||
| GHL_USERNAME: | ||
| required: false | ||
| description: 'Github Username (Required for Kotlin builds)' | ||
| GHL_PASSWORD: | ||
| required: false | ||
| description: 'Github Password (Required for Kotlin builds)' | ||
| SENTRY_AUTH_TOKEN: | ||
| required: false | ||
| description: "Sentry Auth Token, this value is injected into the secrets of a docker image" | ||
| AWS_CDN_ACCESS_KEY_ID: | ||
| required: false | ||
| description: "AWS CDN Secret Access ID, this value is injected into the secrets of a docker image" | ||
| AWS_CDN_SECRET_ACCESS_KEY: | ||
| required: false | ||
| description: "AWS CDN Secret Access Key, this value is injected into the secrets of a docker image" | ||
| LOKALISE_TOKEN: | ||
| required: false | ||
| description: 'Lokalise token for Lokalise API, this value is injected into the secrets of a docker image' | ||
| LOKALISE_PROJECT_ID: | ||
| required: false | ||
| description: 'Lokalise project ID for Lokalise API, this value is injected into the secrets of a docker image' | ||
| outputs: | ||
| image-tag: | ||
| description: 'The image tag that was built' | ||
| value: ${{ jobs.create-manifest.outputs.image-tag }} | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| jobs: | ||
| setup: | ||
| name: Setup | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| outputs: | ||
| runner-x64: ${{ steps.runner-x64.outputs.runner-name }} | ||
| runner-arm64: ${{ steps.runner-arm64.outputs.runner-name }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Get x64 runner name | ||
| id: runner-x64 | ||
| uses: monta-app/github-workflows/.github/actions/runner-size-converter@main | ||
| with: | ||
| runner-size: ${{ inputs.runner-size }} | ||
| architecture: x64 | ||
| - name: Get arm64 runner name | ||
| id: runner-arm64 | ||
| uses: monta-app/github-workflows/.github/actions/runner-size-converter@main | ||
| with: | ||
| runner-size: ${{ inputs.runner-size }} | ||
| architecture: arm64 | ||
| - name: Update existing slack message | ||
| uses: monta-app/slack-notifier-cli-action@main | ||
| with: | ||
| job-type: "build" | ||
| job-status: "progress" | ||
| service-name: ${{ inputs.service-name }} | ||
| service-emoji: ${{ inputs.service-emoji }} | ||
| slack-app-token: ${{ secrets.SLACK_APP_TOKEN }} | ||
| slack-channel-id: "C01KL9FUPNK" | ||
| slack-message-id: ${{ inputs.slack-message-id }} | ||
| build: | ||
| name: Build Multi-Arch | ||
| needs: setup | ||
| runs-on: ${{ matrix.runner }} | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - platform: linux/amd64 | ||
| arch: amd64 | ||
| runner: ${{ needs.setup.outputs.runner-x64 }} | ||
| - platform: linux/arm64 | ||
| arch: arm64 | ||
| runner: ${{ needs.setup.outputs.runner-arm64 }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Configure AWS credentials via assumed role | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecr-put-image | ||
| role-session-name: push-new-image-to-${{ inputs.service-identifier }}-${{inputs.stage}} | ||
| aws-region: ${{ inputs.region }} | ||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v2 | ||
| - name: Docker meta | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr-repository-name || format('{0}-{1}', inputs.service-identifier, inputs.stage) }} | ||
| tags: | | ||
| type=sha,format=long,prefix=,suffix=-${{ matrix.arch }} | ||
| type=raw,value=latest,suffix=-${{ matrix.arch }} | ||
| - name: Build and push | ||
| id: build | ||
| uses: docker/build-push-action@v6 | ||
| working-directory: ${{ inputs.gradle-module || '.' }} | ||
| with: | ||
| context: . | ||
| file: ${{ inputs.docker-file-name }} | ||
| push: true | ||
| no-cache: true | ||
| build-args: | | ||
| ${{ inputs.additional-build-args }} | ||
| labels: | | ||
| GITHUB_RUN_ID=${{ github.run_id }} | ||
| ${{ steps.meta.outputs.labels }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| secrets: | | ||
| GHL_USERNAME=${{ secrets.GHL_USERNAME }} | ||
| GHL_PASSWORD=${{ secrets.GHL_PASSWORD }} | ||
| SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} | ||
| AWS_CDN_ACCESS_KEY_ID=${{ secrets.AWS_CDN_ACCESS_KEY_ID }} | ||
| AWS_CDN_SECRET_ACCESS_KEY=${{ secrets.AWS_CDN_SECRET_ACCESS_KEY }} | ||
| LOKALISE_TOKEN=${{ secrets.LOKALISE_TOKEN }} | ||
| LOKALISE_PROJECT_ID=${{ secrets.LOKALISE_PROJECT_ID }} | ||
| create-manifest: | ||
| name: Create Multi-Arch Manifest | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| outputs: | ||
| image-tag: ${{ github.sha }} | ||
| steps: | ||
| - name: Configure AWS credentials via assumed role | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecr-put-image | ||
| role-session-name: create-manifest-${{ inputs.service-identifier }}-${{inputs.stage}} | ||
| aws-region: ${{ inputs.region }} | ||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v2 | ||
| - name: Create and push manifest | ||
| run: | | ||
| # Enable experimental features | ||
| export DOCKER_CLI_EXPERIMENTAL=enabled | ||
| # Define the base image name and tag | ||
| BASE_IMAGE="${{ steps.login-ecr.outputs.registry }}/${{ inputs.ecr-repository-name || format('{0}-{1}', inputs.service-identifier, inputs.stage) }}" | ||
| SHA_TAG="${{ github.sha }}" | ||
| # Create manifest list | ||
| docker manifest create ${BASE_IMAGE}:${SHA_TAG} \ | ||
| ${BASE_IMAGE}:${SHA_TAG}-amd64 \ | ||
| ${BASE_IMAGE}:${SHA_TAG}-arm64 | ||
| # Push the manifest | ||
| docker manifest push ${BASE_IMAGE}:${SHA_TAG} | ||
| # Create and push latest manifest | ||
| docker manifest create ${BASE_IMAGE}:latest \ | ||
| ${BASE_IMAGE}:latest-amd64 \ | ||
| ${BASE_IMAGE}:latest-arm64 | ||
| docker manifest push ${BASE_IMAGE}:latest | ||
| notify-build-finished: | ||
| name: Notify Build Finished | ||
| needs: | ||
| - setup | ||
| - build | ||
| - create-manifest | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| if: always() | ||
| steps: | ||
| - name: Publish result message to slack | ||
| uses: monta-app/slack-notifier-cli-action@main | ||
| with: | ||
| job-type: "build" | ||
| job-status: ${{ needs.build.result }} | ||
| service-name: ${{ inputs.service-name }} | ||
| service-emoji: ${{ inputs.service-emoji }} | ||
| slack-app-token: ${{ secrets.SLACK_APP_TOKEN }} | ||
| slack-channel-id: "C01KL9FUPNK" | ||
| slack-message-id: ${{ inputs.slack-message-id }} | ||