-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (75 loc) · 2.66 KB
/
push-container.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Push Container
on:
push:
branches: [main]
paths:
- 'container/**'
- './.github/workflows/push-container.yml'
workflow_dispatch:
env:
AWS_REGISTRY_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com
AWS_REGION: us-east-1
AWS_ROLE_TO_ASSUME: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/coderunner-pipeline-role
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
- uses: actions/checkout@v4
- name: Run tests
run: |
cd container
npm ci
npm run test
get-ecr-repository:
runs-on: ubuntu-latest
outputs:
deploy_repository: ${{ steps.cmd.outputs.deploy_repository }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Was ECR Repository deployed
id: cmd
run: |
deploy_repository=0
aws ecr describe-repositories --repository-names coderunner || deploy_repository=1
echo "deploy_repository=$deploy_repository" >> "$GITHUB_OUTPUT"
upsert-ecr-repository:
needs: [get-ecr-repository]
if: ${{ needs.get-ecr-repository.outputs.deploy_repository == '1' }}
uses: ./.github/workflows/ecr-repository.yml
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
push-image:
runs-on: ubuntu-latest
needs: [unit-test, upsert-ecr-repository]
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: "false"
- name: Set CONTAINER_TAG and AWS_IMAGE_URI
run: |
CONTAINER_TAG=coderunner:${{ github.run_id }}
AWS_IMAGE_URI="$AWS_REGISTRY_URI/$CONTAINER_TAG"
- name: Push Image
run: |
cd container
docker build --platform linux/amd64 -t $CONTAINER_TAG .
docker tag $CONTAINER_TAG $AWS_IMAGE_URI
docker push $AWS_IMAGE_URI