-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (69 loc) · 2.66 KB
/
deploy-staging.yaml
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
name: Deploy with AWS CDK
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
env:
FUNCTION_NAME: ${{ vars.FUNCTION_NAME_STAGING }}
BASE_URL: ${{ vars.BASE_URL_STAGING }}
FROM: ${{ vars.FROM_STAGING }}
NO_OF_POSTS_SENT_TO_USERS: ${{ vars.NO_OF_POSTS_SENT_TO_USERS_STAGING }}
OPENAI_API_KEY: ${{ vars.OPENAI_API_KEY }}
SENDGRID_API_KEY: ${{ vars.SENDGRID_API_KEY }}
SYNC_HOURS: ${{ vars.SYNC_HOURS_STAGING }}
AWS_ECR_REGISTRY: ${{ vars.AWS_ECR_REGISTRY }}
steps:
- name: Print Set Environment variables
run: |
echo "FUNCTION_NAME: $FUNCTION_NAME"
echo "BASE_URL: $BASE_URL"
echo "FROM: $FROM"
echo "NO_OF_POSTS_SENT_TO_USERS: $NO_OF_POSTS_SENT_TO_USERS"
echo "OPENAI_API_KEY: $OPENAI_API_KEY"
echo "SENDGRID_API_KEY: $SENDGRID_API_KEY"
echo "SYNC_HOURS: $SYNC_HOURS"
echo "AWS_ECR_REGISTRY: $AWS_ECR_REGISTRY"
transformed_text=$(echo "$FUNCTION_NAME" | sed -E 's/(^|_)(\w)/\U\2/g')
transformed_text+="Stack"
export STACK_NAME=$transformed_text
echo STACK_NAME: $STACK_NAME
- name: Checkout code
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.FUNCTION_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
echo "ECR_REGISTRY: $ECR_REGISTRY"
echo "ECR_REPOSITORY: $ECR_REPOSITORY"
echo "IMAGE_TAG: $IMAGE_TAG"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install CDK dependencies
run: npm ci
- name: Deploy CDK stack
run: npx cdk deploy $STACK_NAME --require-approval never
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: eu-west-2
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.FUNCTION_NAME }}
IMAGE_TAG: ${{ github.sha }}