-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (87 loc) · 3.17 KB
/
build-and-push-ecr-dev-server.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
88
89
90
91
92
93
94
95
96
name: Build and push to ECR(tokenguard-dev)
on:
push:
branches: ["dev"]
pull_request:
branches: ["dev"]
workflow_dispatch:
env:
AWS_REGION: eu-west-1
jobs:
run-tests:
name: Run tests
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t db-api .
- name: Run tests with temp db
run: docker-compose -f docker-compose-test.yaml run db-api npm test
- name: Remove docker and volumes
run: docker-compose -f docker-compose-test.yaml down -v
build-push:
name: Build image and push to ECR(tokenguard-dev)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: run-tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
# Setup hardware emulator using QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/arm64,linux/amd64
# Setup Docker Builderx for multi-arch images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
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 to Amazon ECR
id: build-push-ecr
uses: docker/build-push-action@v3
with:
push: true
file: Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.login-ecr.outputs.registry }}/tokenguard-dev-db-api:${{ github.sha }}
- name: Image digest
run: echo ${{ steps.build-push-ecr.outputs.digest }}
deploy-eks:
name: Deploy image on EKS(tokenguard-dev)
needs: build-push
runs-on: self-hosted
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Deploy to tokenguard-dev
uses: christallire/kubectl-aws-eks@1.1.0-arm64-fix2
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA_DEV }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: tokenguard-dev-db-api
IMAGE_TAG: ${{ github.sha }}
with:
args: -n dev set image deployment/db-api db-api=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: verify deployment
uses: christallire/kubectl-aws-eks@1.1.0-arm64-fix2
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA_DEV }}
with:
args: -n dev rollout status deployment/db-api