name: Build push ECR
on:
workflow_dispatch:
inputs:
ENV:
description: "Target env"
required: true
type: choice
options:
- "dev"
default: "dev"
ECR_REPO_NAME:
description: "ECR repository name"
required: true
type: choice
options:
- "cassandre_job"
default: "cassandre_job"
env:
AWS_REGION: eu-central-1
IMAGE_TAG: "latest"
permissions:
actions: write # This is required to read/write workflows, workflow runs and artifacts.
contents: write # This is required for actions/checkout and to read/write repository contents, commits, branches, downloads, releases, and merges.
id-token: write # This is required for requesting the JWT for OIDC. => Checkmarx Issue High : Passwords And Secrets - Generic Token (Query to find passwords and secrets in infrastructure code.) but needed by aws-actions/configure-aws-credentials@v2
pull-requests: write # This is required to read/write pull requests and related comments, assignees, labels, milestones, and merges.
security-events: write # This is required for the Checkov composite action to upload report to the GitHub Advanced Security tab
jobs:
build:
name: Build, tag and push to ECR
runs-on: ubuntu-latest
environment: ${{ inputs.ENV }}
steps:
- uses: actions/checkout@v2
- name: Generate token for GitHub App
id: generate-token
uses: getsentry/action-github-app-token@v2.0.0
with:
app_id: ${{ secrets.UNIVERSAL_GH_APP_ID_CODE }}
private_key: ${{ secrets.UNIVERSAL_GH_APP_PRIVATE_KEY_CODE }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ASSUME_ROLE }}
aws-region: ${{ env.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: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPO_NAME: ${{ inputs.ECR_REPO_NAME }}
run: |
# Build a docker container and push it to ECR so that it can be deployed to ECS.
docker build --file DockerfileJob --tag $ECR_REGISTRY/$ECR_REPO_NAME:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPO_NAME:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPO_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT
|