generated from be-student/nestjs_template
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (81 loc) · 3.27 KB
/
deploy.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
name: Deploy Prography
on:
push:
branches:
- master
env:
ECR_REGISTRY: 594292838648.dkr.ecr.ap-northeast-2.amazonaws.com/prography-homepage-renewal
ECR_REPOSITORY: prography-homepage-renewal
APPLICATION_NAME: prography-homepage-renewal
ENVIRONMENT_NAME: PrographyHomepageRenewal-env
AWS_REGION: ap-northeast-2
GIT_SHA: ${{ github.sha }}
jobs:
deploy-prod:
name: Deploy to production
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout
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: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Create .env file
run: |
touch .env
echo PORT=${{ secrets.PORT }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_USERNAME=${{ secrets.DB_USERNAME }} >> .env
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env
echo DB_DATABASE=${{ secrets.DB_DATABASE }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo SENTRY_DSN=${{ secrets.SENTRY_DSN }} >> .env
echo ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
echo JWT_EXPIRES_IN_SECONDS=${{ secrets.JWT_EXPIRES_IN_SECONDS }} >> .env
echo AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY_ID }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} >> .env
cat .env
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
GIT_SHA: ${{ env.GIT_SHA }}
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYYMMDD_HH-mm-ss
utcOffset: '+09:00'
- name: Generate deployment package
run: |
mkdir -p deploy
mkdir -p deploy/.platform/nginx/conf.d
cp Dockerrun.aws.json deploy/Dockerrun.aws.json
cp .platform/nginx/conf.d/proxy.conf deploy/.platform/nginx/conf.d/proxy.conf
cd deploy && zip -r deploy.zip .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v14
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ env.APPLICATION_NAME }}
environment_name: ${{ env.ENVIRONMENT_NAME }}
version_label: egg-docker-${{steps.current-time.outputs.formattedTime}}
region: ${{ env.AWS_REGION }}
deployment_package: deploy/deploy.zip
wait_for_environment_recovery: 200