Merge pull request #402 from tmfg/sonar_cleanup #361
This file contains 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 ECR" | |
on: | |
workflow_run: | |
workflows: [ "Release new version" ] | |
types: | |
- completed | |
push: | |
branches: ['main'] | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
BuildAndPushImageToECR: | |
name: "Build and Push to ECR" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if Actor is a Member of one of the teams | |
uses: im-open/[email protected] | |
with: | |
github-actor: ${{ github.actor }} | |
github-organization: tmfg | |
github-team-slugs: | | |
["digitraffic-tis-solita"] | |
github-usernames: | | |
["dependabot[bot]"] | |
github-token: ${{ secrets.ORG_MEMBER_READ }} | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.OIDC_DEPLOY_ROLE_ARN }} | |
aws-region: eu-north-1 | |
role-duration-seconds: 7200 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
with: | |
mask-password: 'true' | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version-file: '.java-version' | |
distribution: 'temurin' | |
cache: maven | |
- name: Extract CURRENT version | |
id: version | |
if: ${{ github.event_name == 'workflow_run' }} | |
run: | | |
echo "version=$(mvn --quiet -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: "digitraffic-tis-vaco" | |
IMAGE_TAG: ${{ steps.version.outputs.version }} | |
run: | | |
mvn --quiet clean compile jib:dockerBuild -Djib-maven-plugin.image-name=$ECR_REGISTRY/$ECR_REPOSITORY:latest | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
echo "image_latest=$ECR_REGISTRY/$ECR_REPOSITORY:latest" >> $GITHUB_OUTPUT | |
if [[ -n "$IMAGE_TAG" ]] | |
then | |
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image_versioned=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
fi |