Skip to content

[CI] CI/CD 구축 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .ebextensions-dev/00-makeFiles.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
files:
"/sbin/appstart":
mode: "000755"
owner: webapp
group: webapp
content: |
JAR_PATH=/var/app/current/application.jar

killall java
java -Dfile.encoding=UTF-8 -jar $JAR_PATH
3 changes: 3 additions & 0 deletions .ebextensions-dev/01-set-timezone.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime/code
67 changes: 67 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ttakkeun dev CI/CD

on:
pull_request:
types: [closed] # merge가 됐을 때 작동하도록 함
workflow_dispatch: # (2).수동 실행도 가능하도록

jobs:
build:
runs-on: ubuntu-latest # (3).OS환경
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
# develop 브랜치에 merge가 됐을 때 작동하도록 설정

steps:
- name: Checkout # 위에서 기재한 develop 브랜치의 코드를 가져옴
uses: actions/checkout@v2 # (4).코드 check out

- name: Set up JDK 17 # 깃허브 자체적으로 자바 jdk를 설치함
uses: actions/setup-java@v3
with:
java-version: 17 # (5).자바 설치
distribution: 'adopt'

- name: Grant execute permission for gradlew # gradle이 들어갈 대상에 권한을 부여함
run: chmod +x ./gradlew
shell: bash # (6).권한 부여

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # (7).build시작
# (5), (6), (7) - Github Actions를 이용해서 Jar 파일을 만드는 과정

- 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).확보한 시간 보여주기
# (8), (9) - 타임스탬프를 기록하기 위한 과정

- name: Generate deployment package
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions-dev deploy/.ebextensions
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .
# Github Action을 통해 깃허브가 자체적으로 리눅스 가상 환경을 만들어서
# 배포에 필요한 빌드 과정을 진행하는 과정

- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} # 깃허브에 secrets로 설정함
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} # 깃허브에 secrets로 설정함
application_name: ttakkeun-dev
environment_name: Ttakkeun-dev-env # Elastic Beanstalk명
version_label: github-action-${{ steps.current-time.outputs.formattedTime }} # 타임스탬프
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_deployment: false
# Elastic beanstalk에 배포 요청
63 changes: 63 additions & 0 deletions .platform/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
user 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_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

include conf.d/*.conf;

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

upstream springboot {
server 127.0.0.1:8080; // 스프링이므로 8080번 포트 사용
keepalive 1024;
}

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

location / {
proxy_pass http://springboot;
# CORS 관련 헤더 추가
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
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 @@ -37,3 +37,7 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public String test1() {
return "Hello, ttakkeun!";
}

@GetMapping("/health")
public String healthCheck() {
// health check용
return "I'm healthy!";
}
}
Loading