Skip to content

Commit 62dcd6d

Browse files
authored
chore: update container.yaml, cleanup (#58)
* chore: update container.yaml, cleanup * add assume role * fix cache path * add tags * fix registry name * fix repo names everywhere * removing inputs
1 parent 1bb6f4c commit 62dcd6d

3 files changed

Lines changed: 54 additions & 69 deletions

File tree

.github/workflows/build-image.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,6 @@ on:
2222
description: If provided, runs a script after repo checkout and before the docker image is built. Useful in case that you need to build a package outside of the docker image (and load the artifacts via copy).
2323
default: ""
2424
type: string
25-
registryHostname:
26-
required: false
27-
description: The hostname for the container registry
28-
default: ghcr.io
29-
type: string
30-
registryOrg:
31-
required: false
32-
description: The registry organization
33-
default: parcellab
34-
type: string
35-
registryUsername:
36-
required: false
37-
description: The username for the container registry
38-
default: parcellab-dev-bot
39-
type: string
40-
repository_kind:
41-
required: false
42-
description: Using as a dummy, to be removed in the future versions
43-
type: string
4425
enableContainerScan:
4526
required: false
4627
description: Apply the container scan

.github/workflows/container.yaml

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ name: Reusable Container
22
on:
33
workflow_call:
44
inputs:
5+
appName:
6+
required: true
7+
description: The container image name
8+
type: string
59
contextPath:
610
required: false
711
description: The container context to build the image
812
default: .
913
type: string
14+
enableContainerScan:
15+
required: false
16+
description: Apply the container scan
17+
default: true
18+
type: boolean
1019
extraBuildArgs:
1120
required: false
1221
description: Extra build arguments for building the docker image (KEY=VALUE separated by new lines)
@@ -17,25 +26,6 @@ on:
1726
description: The file path for the Container image
1827
default: Containerfile
1928
type: string
20-
name:
21-
required: true
22-
description: The container image name
23-
type: string
24-
registryHostname:
25-
required: false
26-
description: The hostname for the container registry
27-
default: ghcr.io
28-
type: string
29-
registryOrg:
30-
required: false
31-
description: The registry organization
32-
default: parcellab
33-
type: string
34-
registryUsername:
35-
required: false
36-
description: The username for the container registry
37-
default: parcellab-dev-bot
38-
type: string
3929
runner:
4030
required: false
4131
description: Runner type
@@ -49,38 +39,64 @@ on:
4939
npmGithubReadToken:
5040
required: false
5141
description: The Github token with permissions to read NPM private packages
52-
registryPassword:
42+
AWS_ROLE_TO_ASSUME:
5343
required: true
54-
description: The password for the container registry
44+
description: AWS OIDC role for GitHub to assume
45+
5546
jobs:
56-
container:
47+
build-ecr-single:
48+
permissions:
49+
id-token: write
50+
contents: read
5751
runs-on: ${{ inputs.runner }}
5852
steps:
5953
- name: Checkout current git repository
60-
uses: actions/checkout@v3
54+
uses: actions/checkout@v4
6155
- name: Set up Docker Buildx
62-
uses: docker/setup-buildx-action@v1
63-
- name: Login to Container Registry
64-
uses: docker/login-action@v1
56+
uses: docker/setup-buildx-action@v2
57+
- name: Configure AWS credentials
58+
uses: aws-actions/configure-aws-credentials@v2
6559
with:
66-
registry: ${{ inputs.registryHostname }}
67-
username: ${{ inputs.registryUsername }}
68-
password: ${{ secrets.registryPassword }}
69-
- name: Build and push latest version
70-
uses: docker/build-push-action@v4
60+
aws-region: eu-central-1
61+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
62+
- name: Create ECR repository if it doesn't exist
63+
run: |
64+
aws ecr describe-repositories --repository-names ${{ inputs.appName }} || \
65+
aws ecr create-repository --repository-name ${{ inputs.appName }}
66+
LIFECYCLE_POLICY='{"rules":[{"rulePriority":1,"description":"Keep last 500 images","selection":{"tagStatus":"any","countType":"imageCountMoreThan","countNumber":500},"action":{"type":"expire"}}]}'
67+
aws ecr put-lifecycle-policy --repository-name ${{ inputs.appName }} --lifecycle-policy-text "$LIFECYCLE_POLICY"
68+
- name: Login to Amazon ECR
69+
id: login-ecr
70+
uses: aws-actions/amazon-ecr-login@v2
71+
- name: Build image
72+
uses: docker/build-push-action@v6
7173
with:
7274
build-args: |
7375
GITHUB_SHA=${{ github.sha }}
74-
NPM_GITHUB_TOKEN=${{ secrets.npmGithubReadToken }}
7576
VERSION=${{ inputs.version }}
77+
NPM_GITHUB_TOKEN=${{ secrets.npmGithubReadToken }}
7678
${{ inputs.extraBuildArgs }}
77-
cache-from: type=registry,ref=${{ inputs.registryHostname }}/${{ inputs.registryOrg }}/${{ inputs.name }}
78-
cache-to: type=inline
79+
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:cache
80+
cache-to: mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:cache
7981
context: ${{ inputs.contextPath }}
82+
load: true
8083
file: ${{ inputs.filePath }}
8184
platforms: linux/amd64
82-
push: true
8385
tags: |
84-
${{ inputs.registryHostname }}/${{ inputs.registryOrg }}/${{ inputs.name }}:latest
85-
${{ inputs.registryHostname }}/${{ inputs.registryOrg }}/${{ inputs.name }}:${{ inputs.version }}
86-
${{ inputs.registryHostname }}/${{ inputs.registryOrg }}/${{ inputs.name }}:${{ github.sha }}
86+
${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:latest
87+
${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:${{ inputs.version }}
88+
${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:${{ github.sha }}
89+
- name: Scan for vulnerabilities
90+
if: inputs.enableContainerScan
91+
uses: crazy-max/ghaction-container-scan@v3
92+
with:
93+
image: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}:latest
94+
dockerfile: Containerfile
95+
severity: ${{ env.IMAGE_SCAN_SEVERITY }}
96+
severity_threshold: ${{ env.IMAGE_SCAN_SEVERITY_THRESHOLD }}
97+
annotations: ${{ env.IMAGE_SCAN_ANNOTATIONS }}
98+
env:
99+
TRIVY_TIMEOUT: ${{ env.IMAGE_SCAN_TRIVY_TIMEOUT }}
100+
- name: Push image to ECR
101+
run: |
102+
docker push -a ${{ steps.login-ecr.outputs.registry }}/${{ inputs.appName }}

.github/workflows/kubernetes.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ on:
4242
description: If provided, runs a script after repo checkout and before the docker image is built. Useful in case that you need to build a package outside of the docker image (and load the artifacts via copy).
4343
default: ""
4444
type: string
45-
registryHostname:
46-
required: false
47-
description: The hostname for the container registry
48-
default: ghcr.io
49-
type: string
50-
registryOrg:
51-
required: false
52-
description: The registry organization
53-
default: parcellab
54-
type: string
5545
registryUsername:
5646
required: false
5747
description: The username for the container registry
@@ -178,8 +168,6 @@ jobs:
178168
artifactPath: ${{ inputs.artifactPath }}
179169
imageTargets: ${{ inputs.imageTargets }}
180170
preScript: ${{ inputs.preScript }}
181-
registryHostname: ${{ inputs.registryHostname }}
182-
registryOrg: ${{ inputs.registryOrg }}
183171
registryUsername: ${{ inputs.registryUsername }}
184172
enableContainerScan: ${{ inputs.enableContainerScan }}
185173
runner: ${{ inputs.runner }}

0 commit comments

Comments
 (0)