-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (99 loc) · 3.61 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: climbing
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
# CI
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'corretto'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Pull Redis Docker image
run: docker pull redis
- name: Run Redis container
run: docker run --name my-redis -d -p 6379:6379 redis
- name: Set AwsS3 Key at yaml
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/application-ci.yml, ./src/main/resources/application-prod.yml
env:
aws.s3.bucket: ${{ secrets.AWS_S3_BUCKET }}
aws.s3.accessKey: ${{ secrets.AWS_S3_ACCESS_KEY }}
aws.s3.secretKey: ${{ secrets.AWS_S3_SECRET_KEY }}
- name: Set RDS & REDIS at prod yaml
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/application-prod.yml
env:
spring.datasource.url: ${{ secrets.DB_URL }}
spring.datasource.username: ${{ secrets.DB_USERNAME }}
spring.datasource.password: ${{ secrets.DB_PASSWORD }}
spring.data.redis.host: ${{ secrets.REDIS_HOSTNAME }}
- name: Grant execute permission to gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYYMMDDHHmmss # 시간 정보 가져오기
utfOffset: "+09:00"
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: climbing
IMAGE_TAG: climbing_${{ steps.current-time.outputs.formattedTime }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Generate Dockerrun.aws.json
run: |
echo '{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "533266961412.dkr.ecr.ap-northeast-2.amazonaws.com/climbing:climbing_${{ steps.current-time.outputs.formattedTime }}",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "5000",
"HostPort": "5000"
}
]
}' > Dockerrun.aws.json
- name: Generate deployment package
run: |
mkdir -p deploy
cp Dockerrun.aws.json deploy/Dockerrun.aws.json
cd deploy && zip -r deploy.zip .
# EB에 배포
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
application_name: climbing-api
environment_name: Climbing-api-env
version_label: climbing_${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-2
deployment_package: deploy/deploy.zip