chore(deps): lock file maintenance (#483) #450
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 Container to ECR | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main] | |
env: | |
AWS_REGION: ca-central-1 | |
GITHUB_SHA: ${{ github.sha }} | |
REGISTRY: ${{ secrets.AWS_ACCOUNT }}.dkr.ecr.ca-central-1.amazonaws.com/security-tools | |
permissions: | |
id-token: write | |
contents: write | |
pull-requests: write | |
actions: write | |
checks: write | |
statuses: write | |
security-events: write | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
images: ${{ steps.filter.outputs.changes }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: dorny/paths-filter@7267a8516b6f92bdb098633497bad573efdbf271 # v2.12.0 | |
id: filter | |
with: | |
filters: | | |
cloud_asset_inventory/cloudquery: 'images/cloud_asset_inventory/cloudquery/**' | |
csp_violation_report_service: 'images/csp_violation_report_service/**' | |
build-push-and-deploy: | |
if: needs.changes.outputs.images != '[]' | |
runs-on: ubuntu-latest | |
needs: changes | |
strategy: | |
fail-fast: false | |
matrix: | |
image: ${{ fromJSON(needs.changes.outputs.images) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: configure aws credentials using OIDC | |
uses: aws-actions/configure-aws-credentials@master | |
with: | |
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/security-tools-apply | |
role-session-name: ECRPush | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1 | |
- name: Build container | |
working-directory: ./images/${{ matrix.image }} | |
run: | | |
docker build \ | |
--build-arg git_sha=$GITHUB_SHA \ | |
-t $REGISTRY/${{ matrix.image }}:$GITHUB_SHA \ | |
-t $REGISTRY/${{ matrix.image }}:latest . | |
- name: Push containers to ECR | |
run: | | |
docker push $REGISTRY/${{ matrix.image }}:$GITHUB_SHA | |
docker push $REGISTRY/${{ matrix.image }}:latest | |
- name: Generate ${{ matrix.image }} docker SBOM | |
uses: cds-snc/security-tools/.github/actions/generate-sbom@598deeaed48ab3bb0df85f0ed124ba53f0ade385 # v3.1.0 | |
with: | |
docker_image: ${{ env.REGISTRY }}/${{ matrix.image }}:${{ env.GITHUB_SHA }} | |
sbom_name: ${{ matrix.image }} | |
dockerfile_path: "${{ matrix.image }}/Dockerfile" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Logout of Amazon ECR | |
run: docker logout ${{ steps.login-ecr.outputs.registry }} | |
- name: Deploy lambda | |
if: matrix.image == 'csp_violation_report_service' | |
run: | | |
aws lambda update-function-code \ | |
--function-name "${{ matrix.image }}" \ | |
--image-uri $REGISTRY/${{ matrix.image }}:$GITHUB_SHA > /dev/null 2>&1 |