-
Notifications
You must be signed in to change notification settings - Fork 5
74 lines (64 loc) · 3.37 KB
/
cd-v2.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
name: CD
on:
push:
branches: [ "main" ]
env:
PROJECT_NAME: gream-v2
BUCKET_NAME: bc1-gream-s3-01
CODE_DEPLOY_APP_NAME: gream-v2
DEPLOYMENT_GROUP_NAME: gream-developer-v2
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build --stacktrace
shell: bash
- name: aws configure
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: build docker file and setting deploy files
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: gream
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
mkdir scripts
touch scripts/deploy.sh
echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh
echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
echo "docker run -p 8080:8080 -e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} -e REDIS_URL=${{ secrets.REDIS_URL }} -e DB_ID=${{ secrets.DB_ID }} \
-e BUCKET_NAME=${{ secrets.BUCKET_NAME }} -e REGION=${{ secrets.REGION }} -e S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \
-e S3_SECRET_ACCESS_KEY=${{ secrets.S3_SECRET_ACCESS_KEY }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e DB_URL=${{ secrets.DB_URL }} -e DB_READ_ONLY_URL=${{ secrets.DB_READ_ONLY_URL }} \
-e KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} -e KAKAO_REDIRECT_URL=${{ secrets.KAKAO_REDIRECT_URL }} \
-e KAKAO_TOKEN_URI=${{ secrets.KAKAO_TOKEN_URI }} -e KAKAO_USER_INFO_URI=${{ secrets.KAKAO_USER_INFO_URI }} \
-e TOSS_CLIENT_API_KEY=${{ secrets.TOSS_CLIENT_API_KEY }} -e TOSS_FAIL_URL=${{ secrets.TOSS_FAIL_URL }} \
-e TOSS_SECRET_API_KEY=${{ secrets.TOSS_SECRET_API_KEY }} -e TOSS_SUCCESS_URL=${{ secrets.TOSS_SUCCESS_URL }} \
-e PROFILE=prod -d --restart always --name csbroker-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
echo "docker run -d -p 9090:9090 -v home/ubuntu/docker-compose/prometheus/prometheus.yml --name prometheus prom/prometheus"
- name: upload to s3
env:
IMAGE_TAG: ${{ github.sha }}
run: |
zip -r $IMAGE_TAG.zip ./scripts appspec.yml
aws s3 cp --region ap-northeast-2 --acl private ./$IMAGE_TAG.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
- name: start deploy
env:
IMAGE_TAG: ${{ github.sha }}
run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-group-name $DEPLOYMENT_GROUP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$IMAGE_TAG.zip