-
Notifications
You must be signed in to change notification settings - Fork 11
105 lines (94 loc) · 3.87 KB
/
node.js-dev.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
97
98
99
100
101
102
103
104
105
name: Node.js develop CI - Backend
on:
push:
branches: [ develop ]
paths:
- "backend/**"
- ".github/workflows/node.js-dev.yml"
- "helm/staging/**"
jobs:
build-deploy:
runs-on: ubuntu-latest
env:
REGION: us-east-2
CLUSTER_NAME: maker-staging
SERVICE_NAME: mips-backend
AWS_ECR_NAME: mips-backend-staging
ENVIRONMENT_TAG: staging
HELM_FILE: helm/staging/backend.yaml
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Running the Test Suit
env:
REQUEST_GITHUB_URL_API_ENDPOINT: ${{ secrets.REQUEST_GITHUB_URL_API_ENDPOINT }}
GIT_ACCESS_API_TOKEN: ${{ secrets.GIT_ACCESS_API_TOKEN }}
MIP_GITHUB_REPOSITORY: ${{ secrets.MIP_GITHUB_REPOSITORY_DEV }}
MIP_GITHUB_REPOSITORY_OWNER: ${{ secrets.MIP_GITHUB_REPOSITORY_OWNER_DEV }}
run: |
cp '.env example' .env
npm install
npm run pre-start-develop
npm test
working-directory: backend
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.REGION }}
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Extract commit hash
id: vars
if: ${{ !contains(github.event.head_commit.message , '[skip build]') }}
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build, tag, and push image to ECR
id: build-image
if: ${{ !contains(github.event.head_commit.message , '[skip build]') }}
working-directory: backend
env:
SHA_TAG: ${{ steps.vars.outputs.sha_short }}
LATEST_TAG: latest
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REQUEST_GITHUB_URL_API_ENDPOINT: ${{ secrets.REQUEST_GITHUB_URL_API_ENDPOINT }}
GIT_ACCESS_API_TOKEN: ${{ secrets.GIT_ACCESS_API_TOKEN }}
MIP_GITHUB_REPOSITORY: ${{ secrets.MIP_GITHUB_REPOSITORY_DEV }}
MIP_GITHUB_REPOSITORY_OWNER: ${{ secrets.MIP_GITHUB_REPOSITORY_OWNER_DEV }}
run: |
# Build Docker containers and push them to ECR ${{ env.AWS_ECR_NAME }}
docker pull $ECR_REGISTRY/$AWS_ECR_NAME:$LATEST_TAG || true
docker build -t $AWS_ECR_NAME \
-t $ECR_REGISTRY/$AWS_ECR_NAME:$SHA_TAG \
-t $ECR_REGISTRY/$AWS_ECR_NAME:$LATEST_TAG \
-t $ECR_REGISTRY/$AWS_ECR_NAME:$ENVIRONMENT_TAG \
--build-arg REQUEST_GITHUB_URL_API_ENDPOINT=$REQUEST_GITHUB_URL_API_ENDPOINT \
--build-arg GIT_ACCESS_API_TOKEN=$GIT_ACCESS_API_TOKEN \
-f Dockerfile \
.
docker push $ECR_REGISTRY/$AWS_ECR_NAME --all-tags
- name: Replace variables in the Helm values file
id: replace-vars
if: ${{ !contains(github.event.head_commit.message , '[skip deploy]') }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
sed -i 's/${ECR_REGISTRY}/'$ECR_REGISTRY/ $HELM_FILE
- name: Deploying Service to Kubernetes with Helm
id: deploy
if: ${{ !contains(github.event.head_commit.message , '[skip deploy]') }}
uses: bitovi/[email protected]
with:
values: image.repository=${{ steps.login-ecr.outputs.registry }}/${{ env.AWS_ECR_NAME }},image.tag=${{ steps.vars.outputs.sha_short }}
cluster-name: ${{ env.CLUSTER_NAME }}
config-files: ${{ env.HELM_FILE }}
chart-path: techops-services/common
namespace: mips
timeout: 5m0s
name: ${{ env.SERVICE_NAME }}
chart-repository: https://techops-services.github.io/helm-charts
version: 0.0.31
atomic: true