Skip to content

Commit 037e6b3

Browse files
authored
Merge pull request #7 from Team-Shaka/ci/4
[CI] 👷 ci/cd 파이프라인 구축
2 parents 24f5097 + 248444e commit 037e6b3

File tree

5 files changed

+353
-1
lines changed

5 files changed

+353
-1
lines changed

.github/workflows/dev_deploy.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: docker ci/cd
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
branches:
9+
- develop
10+
types: [closed]
11+
workflow_dispatch: # (2).수동 실행도 가능하도록
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest # (3).OS환경
16+
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
17+
18+
19+
steps:
20+
- name: Checkout current repository
21+
uses: actions/checkout@v2
22+
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v1
25+
with:
26+
java-version: 17
27+
28+
- name: Grant execute permission for gradlew
29+
run: chmod +x ./gradlew
30+
shell: bash
31+
32+
- name: Build with Gradle
33+
run: ./gradlew clean build
34+
shell: bash
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v1
38+
with:
39+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
aws-region: ap-northeast-2
42+
43+
- name: Login to Amazon ECR
44+
id: login-ecr
45+
uses: aws-actions/amazon-ecr-login@v1
46+
47+
- name: Build, tag, and push image to Amazon ECR
48+
id: build-image
49+
env:
50+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
51+
ECR_REPOSITORY: tree-dev
52+
IMAGE_TAG: latest
53+
run: |
54+
# Docker 이미지 빌드
55+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
56+
57+
# 빌드한 이미지를 Amazon ECR로 푸시
58+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
59+
60+
# 빌드된 이미지의 정보 출력
61+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
62+
63+
- name: Get current time
64+
uses: 1466587594/get-current-time@v2
65+
id: current-time
66+
with:
67+
format: YYYYMMDD_HH-mm-ss
68+
utcOffset: "+09:00"
69+
70+
- name: Generate deployment package
71+
run: |
72+
mkdir -p deploy
73+
cp -r .ebextensions deploy/.ebextensions
74+
cp Dockerrun.aws.json deploy/Dockerrun.aws.json
75+
cp -r .platform deploy/.platform
76+
cd deploy && zip -r deploy.zip .
77+
78+
- name: Beanstalk Deploy
79+
uses: einaregilsson/beanstalk-deploy@v14
80+
with:
81+
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
82+
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
83+
application_name: tree-dev
84+
environment_name: Tree-dev-env
85+
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
86+
region: ap-northeast-2
87+
deployment_package: deploy/deploy.zip
88+
wait_for_deployment: false

.platform/nginx.conf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
user nginx;
2+
error_log /var/log/nginx/error.log warn;
3+
pid /var/run/nginx.pid;
4+
worker_processes auto;
5+
worker_rlimit_nofile 33282;
6+
7+
events {
8+
use epoll;
9+
worker_connections 1024;
10+
multi_accept on;
11+
}
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
18+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19+
'$status $body_bytes_sent "$http_referer" '
20+
'"$http_user_agent" "$http_x_forwarded_for"';
21+
22+
include conf.d/*.conf;
23+
24+
map $http_upgrade $connection_upgrade {
25+
default "upgrade";
26+
}
27+
28+
upstream springboot {
29+
server 127.0.0.1:8080;
30+
keepalive 1024;
31+
}
32+
33+
server {
34+
listen 80 default_server;
35+
listen [::]:80 default_server;
36+
37+
location / {
38+
proxy_pass http://springboot;
39+
# CORS 관련 헤더 추가
40+
add_header 'Access-Control-Allow-Origin' '*';
41+
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
42+
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
43+
proxy_http_version 1.1;
44+
proxy_set_header Connection $connection_upgrade;
45+
proxy_set_header Upgrade $http_upgrade;
46+
47+
proxy_set_header Host $host;
48+
proxy_set_header X-Real-IP $remote_addr;
49+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
50+
}
51+
52+
access_log /var/log/nginx/access.log main;
53+
54+
client_header_timeout 60;
55+
client_body_timeout 60;
56+
keepalive_timeout 60;
57+
gzip off;
58+
gzip_comp_level 4;
59+
60+
# Include the Elastic Beanstalk generated locations
61+
include conf.d/elasticbeanstalk/healthd.conf;
62+
}
63+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package treehouse.server.api.root.presentation;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class RootApi {
8+
9+
@GetMapping("/health")
10+
public String healthCheck(){
11+
return "I'm healthy!";
12+
}
13+
}

src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/resources/application.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# default profile
2+
spring:
3+
application:
4+
name: tree-server
5+
profiles:
6+
group:
7+
dev: common, dev
8+
---
9+
spring:
10+
profiles:
11+
active: dev
12+
servlet:
13+
multipart:
14+
maxFileSize: 10MB
15+
maxRequestSize: 20MB
16+
enabled: true
17+
---
18+
spring:
19+
config:
20+
activate:
21+
on-profile: "common"
22+
springdoc:
23+
swagger-ui:
24+
tags-sorter: alpha # alpha: 알파벳 순 태그 정렬, method: HTTP Method 순 정렬
25+
operations-sorter: alpha # alpha: 알파벳 순 태그 정렬, method: HTTP Method 순 정렬
26+
cache:
27+
disabled: true
28+
use-fqn: true
29+
---
30+
logging:
31+
level:
32+
org.springframework.security.web.FilterChainProxy: DEBUG
33+
spring:
34+
application:
35+
name: tree-server-dev
36+
config:
37+
activate:
38+
on-profile: "dev"
39+
datasource:
40+
username: ${aws.db.username}
41+
password: ${aws.db.password}
42+
url: jdbc:mysql://${aws.db.url}/${aws.db.name}?autoReconnect=true&setTimezone=Asia/Seoul
43+
driver-class-name: com.mysql.cj.jdbc.Driver
44+
sql:
45+
init:
46+
mode: never
47+
jpa:
48+
properties:
49+
hibernate:
50+
dialect: org.hibernate.dialect.MySQLDialect
51+
show_sql: true
52+
format_sql: true
53+
use_sql_comments: true
54+
hbm2ddl:
55+
auto: update
56+
default_batch_fetch_size: 1000
57+
data:
58+
redis:
59+
host: ${REDIS_URL}
60+
port: 6379
61+
jwt:
62+
header: Authorization
63+
# dev server
64+
secret:
65+
key: ${JWT_SECRET}
66+
# secret : ${JWT_SECRET}
67+
authorities-key: authoritiesKey
68+
access-token-validity-in-seconds: 30000 # 30 s
69+
refresh-token-validity-in-seconds: 60000 # 1 min
70+
71+
72+
73+
cloud:
74+
aws:
75+
s3:
76+
bucket: elasticbeanstalk-ap-northeast-2-851725177732
77+
#s3 bucket
78+
region:
79+
static: ap-northeast-2
80+
auto: false
81+
stack:
82+
auto: false
83+
credentials:
84+
access-key: ${ACCESS_KEY}
85+
secret-key: ${SECRET_KEY}
86+
#aws access key, secret key
87+
88+
naver-sms:
89+
accessKey: ${NAVER_SMS_ACCESSKEY}
90+
secretKey: ${NAVER_SMS_SECRET}
91+
serviceId: ${NAVER_SMS_SERVICEID}
92+
senderPhone: ${NAVER_SMS_PHONE}
93+
---
94+
spring:
95+
application:
96+
name: tree-server-local
97+
config:
98+
activate:
99+
on-profile: "local"
100+
datasource:
101+
username: ${aws.db.username}
102+
password: ${aws.db.password}
103+
url: jdbc:mysql://${aws.db.url}/${aws.db.name}?autoReconnect=true&setTimezone=Asia/Seoul
104+
driver-class-name: com.mysql.cj.jdbc.Driver
105+
sql:
106+
init:
107+
mode: never
108+
data:
109+
redis:
110+
host: localhost
111+
port : 6379
112+
jpa:
113+
properties:
114+
hibernate:
115+
dialect: org.hibernate.dialect.MySQLDialect
116+
show_sql: true
117+
format_sql: true
118+
use_sql_comments: true
119+
hbm2ddl:
120+
auto: update
121+
default_batch_fetch_size: 1000
122+
jwt:
123+
header: Authorization
124+
# dev server
125+
secret:
126+
key: ${JWT_SECRET}
127+
# secret : ${JWT_SECRET}
128+
authorities-key: authoritiesKey
129+
access-token-validity-in-seconds: 20000 # 30 m
130+
refresh-token-validity-in-seconds: 30000 # 14 d
131+
132+
cloud:
133+
aws:
134+
s3:
135+
bucket: elasticbeanstalk-ap-northeast-2-851725177732
136+
#s3 bucket
137+
region:
138+
static: ap-northeast-2
139+
auto: false
140+
stack:
141+
auto: false
142+
credentials:
143+
access-key: ${ACCESS_KEY}
144+
secret-key: ${SECRET_KEY}
145+
146+
naver-sms:
147+
accessKey: ${NAVER_SMS_ACCESSKEY}
148+
secretKey: ${NAVER_SMS_SECRET}
149+
serviceId: ${NAVER_SMS_SERVICEID}
150+
senderPhone: ${NAVER_SMS_PHONE}
151+
#spring:
152+
# config:
153+
# activate:
154+
# on-profile: release
155+
# datasource:
156+
# username: ${aws.db.username}
157+
# password: ${aws.db.password}
158+
# url: ${aws.db.url}
159+
# driver-class-name: com.mysql.cj.jdbc.Driver
160+
# sql:
161+
# init:
162+
# mode: never
163+
# jpa:
164+
# properties:
165+
# hibernate:
166+
# dialect: org.hibernate.dialect.MySQLDialect
167+
# # show_sql: true
168+
# # format_sql: true
169+
# use_sql_comments: true
170+
# hbm2ddl:
171+
# auto: update
172+
# default_batch_fetch_size: 1000
173+
# data:
174+
# redis:
175+
# host: ${release.redis.host}
176+
# port: 6379
177+
#jwt:
178+
# header: Authorization
179+
# # dev server
180+
# secret: ${JWT_SECRET}
181+
# # secret : ${JWT_SECRET}
182+
# authorities-key: authoritiesKey
183+
# access-token-validity-in-seconds: 1210000000 # 30 m
184+
# refresh-token-validity-in-seconds: 1210000000 # 14 d
185+
#
186+
#openai:
187+
# token: ${OPEN_API_TOKEN}
188+
# url:
189+
# chat: https://api.openai.com/v1/chat/completions

0 commit comments

Comments
 (0)