Skip to content

Commit

Permalink
ci/cd 구축 및 eureka 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlee-29 committed Dec 18, 2023
1 parent 1b8b9c6 commit 680cec8
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .ebextensions-first/00-makeFiles.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
files:
"/sbin/appstart" :
mode: "000755"
owner: webapp
group: webapp
content: |
#!/usr/bin/env bash
JAR_PATH=/var/app/current/application.jar

# run app
killall java
java -Dfile.encoding=UTF-8 -Dspring.profiles.active=first -jar $JAR_PATH
12 changes: 12 additions & 0 deletions .ebextensions-second/00-makeFiles.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
files:
"/sbin/appstart" :
mode: "000755"
owner: webapp
group: webapp
content: |
#!/usr/bin/env bash
JAR_PATH=/var/app/current/application.jar

# run app
killall java
java -Dfile.encoding=UTF-8 -Dspring.profiles.active=second -jar $JAR_PATH
61 changes: 61 additions & 0 deletions .github/workflows/first_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: minju first Server CI/CD

on:
pull_request:
types: [closed]
workflow_dispatch: # (2).수동 실행도 가능하도록

jobs:
build:
runs-on: ubuntu-latest # (3).OS환경
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'first'

steps:
- name: Checkout
uses: actions/checkout@v2 # (4).코드 check out

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17 # (5).자바 설치
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash # (6).권한 부여

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # (7).build 시작

- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (8).build 시점의 시간확보

- name: Show Current Time
run: echo "CurrentTime=$"
shell: bash # (9).확보한 시간 보여주기

- name: Generate deployment package
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions-first deploy/.ebextensions
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }}
application_name: first-api-server
environment_name: First-api-server-env
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-1
deployment_package: deploy/deploy.zip
wait_for_deployment: false
61 changes: 61 additions & 0 deletions .github/workflows/second_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: minju second Server CI/CD

on:
pull_request:
types: [closed]
workflow_dispatch: # (2).수동 실행도 가능하도록

jobs:
build:
runs-on: ubuntu-latest # (3).OS환경
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'second'

steps:
- name: Checkout
uses: actions/checkout@v2 # (4).코드 check out

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17 # (5).자바 설치
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash # (6).권한 부여

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # (7).build 시작

- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (8).build 시점의 시간확보

- name: Show Current Time
run: echo "CurrentTime=$"
shell: bash # (9).확보한 시간 보여주기

- name: Generate deployment package
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions-second deploy/.ebextensions
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }}
application_name: second-api-server
environment_name: Second-api-server-env
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-1
deployment_package: deploy/deploy.zip
wait_for_deployment: false
58 changes: 58 additions & 0 deletions .platform/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
member nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 33282;

events {
use epoll;
worker_connections 1024;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_member [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_member_agent" "$http_x_forwarded_for"';

include conf.d/*.conf;

map $http_upgrade $connection_upgrade {
default "upgrade";
}

upstream springboot {
server 127.0.0.1:8080;
keepalive 1024;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
proxy_pass http://springboot;
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

access_log /var/log/nginx/access.log main;

client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;

# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: appstart
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ tasks.named('bootBuildImage') {
tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package api_server.spring_server.web.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RootController {

@GetMapping("/")
public String health(){
return "I'm healthy!";
}
}
52 changes: 47 additions & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# default profile
spring:
application:
name: briefing-dev
name: spring-server
profiles:
active: dev
active: first
springdoc:
swagger-ui:
tags-sorter: alpha # alpha: 알파벳 순 태그 정렬, method: HTTP Method 순 정렬
Expand Down Expand Up @@ -39,10 +39,10 @@ spring:
---
spring:
application:
name: dev
name: first
config:
activate:
on-profile: dev
on-profile: first
datasource:
username: ${aws.db.username}
password: ${aws.db.password}
Expand All @@ -61,5 +61,47 @@ spring:
hbm2ddl:
auto: update
default_batch_fetch_size: 1000
eureka:
instance:
# 표기되는 규칙 변경
instance-id: first_server
hostname: first.profithub.store
ip-address: first.newsbreifing.store
client:
service-url:
defaultZone: http://gateway.profithub.store:8761/eureka


---
spring:
application:
name: second
config:
activate:
on-profile: second
datasource:
username: ${aws.db.username}
password: ${aws.db.password}
url: ${aws.db.url}
driver-class-name: com.mysql.cj.jdbc.Driver
sql:
init:
mode: never
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
# show_sql: true
# format_sql: true
use_sql_comments: true
hbm2ddl:
auto: update
default_batch_fetch_size: 1000
eureka:
instance:
# 표기되는 규칙 변경
instance-id: second_server
hostname: second.profithub.store
ip-address: second.newsbreifing.store
client:
service-url:
defaultZone: http://gateway.profithub.store:8761/eureka

0 comments on commit 680cec8

Please sign in to comment.