-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (70 loc) · 2.46 KB
/
docker_job.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
on:
workflow_call:
inputs:
tag:
description: 'Tag for docker image'
required: true
type: string
defaults:
run:
shell: bash
jobs:
docker_build_scan_push:
runs-on: ubuntu-latest
defaults:
run:
working-directory: service-maintenance
steps:
- uses: actions/checkout@v3
- name: Extract branch name
id: extract_branch
run: |
if [ "$GITHUB_EVENT_NAME" == "push" ]; then
echo BRANCH_NAME=main >> $GITHUB_ENV
else
echo BRANCH_NAME=${{ github.head_ref }} >> $GITHUB_ENV
fi
- name: Build Image
id: build_image
run: |
docker build -t maintenance-app .
- name: Trivy Image Vulnerability Scanner
id: trivy_scan
uses: aquasecurity/trivy-action@0.11.2
with:
image-ref: maintenance-app:latest
severity: 'HIGH,CRITICAL'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
id: trivy_upload_sarif
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
- uses: unfor19/install-aws-cli-action@v1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1.7.0
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
aws-region: eu-west-1
role-to-assume: arn:aws:iam::311462405659:role/opg-maintenance-ci
role-duration-seconds: 900
role-session-name: OPGMaintenanceECRGithubAction
- name: ECR Login
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1.6.1
with:
registries: 311462405659
- name: Push Container
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
MAINTENANCE_ECR_REPOSITORY: maintenance/maintenance_app
run: |
docker tag maintenance-app:latest $ECR_REGISTRY/$MAINTENANCE_ECR_REPOSITORY:${{ inputs.tag }}
if [ $BRANCH_NAME == "main" ]; then
docker tag maintenance-app:latest $ECR_REGISTRY/$MAINTENANCE_ECR_REPOSITORY:main-${{ inputs.tag }}
docker tag maintenance-app:latest $ECR_REGISTRY/$MAINTENANCE_ECR_REPOSITORY:latest
fi
docker push --all-tags $ECR_REGISTRY/$MAINTENANCE_ECR_REPOSITORY