Modify README #15
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-Main | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- 'code/flyway-example/**' | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
tags: | |
description: 'Test scenario tags' | |
required: false | |
type: boolean | |
environment: | |
description: 'Environment to run tests against' | |
type: environment | |
required: true | |
jobs: | |
build: | |
environment: ECR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ vars.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push image to Amazon ECR | |
id: image-info | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
IMAGE_TAG: v1 | |
working-directory: ./code/flyway-example | |
run: | | |
echo "ecr_registry=$ECR_REGISTRY" >> $GITHUB_OUTPUT | |
echo "ecr_repository=${{ vars.ECR_REPOSITORY }}" >> $GITHUB_OUTPUT | |
./gradlew clean build | |
cp ./build/libs/*.jar ./app.jar | |
docker build --file Dockerfile --build-arg CI_ENVIRONMENT=${{ vars.CI_ENVIRONMENT }} -t main-${{github.run_number}} . | |
docker image tag main-${{github.run_number}} $ECR_REGISTRY/${{ vars.ECR_REPOSITORY }}:main-${{github.run_number}} | |
- name: Run Trivy vulnerability scanner | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ steps.image-info.outputs.ecr_repository }} | |
IMAGE_TAG: ${{ steps.image-info.outputs.image_tag }} | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:main-${{github.run_number}} | |
format: 'table' | |
exit-code: '0' | |
ignore-unfixed: true | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
- name: Push image to Amazon ECR | |
id: image-push | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ steps.image-info.outputs.ecr_repository }} | |
IMAGE_TAG: ${{ steps.image-info.outputs.image_tag }} | |
run: | | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:main-${{github.run_number}} |