Skip to content

Commit

Permalink
feat: ci/cd 구축
Browse files Browse the repository at this point in the history
  • Loading branch information
Enble committed Nov 5, 2024
1 parent ace5bb5 commit 1a7a17a
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 38 deletions.
12 changes: 12 additions & 0 deletions .ebextensions/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
killalljava
java -Dfile.encoding=UTF-8 -Dspring.profiles.active=dev -jar $JAR_PATH
3 changes: 3 additions & 0 deletions .ebextensions/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
63 changes: 63 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: UMC Dev CI/CD # workflow 이름

on: # 이벤트 설정
pull_request:
types: [ closed ]
workflow_dispatch: # 수동 실행도 가능하도록 설정

jobs:
build: # job 이름
runs-on: ubuntu-latest # OS환경
# PR이 merge되었고, 'dev' 브랜치일 경우 수행
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'

steps:
- name: Checkout
uses: actions/checkout@v2 # 코드 check-out
# '.github' 디렉토리가 포함된 디렉토리의 하위 코드들

- name: Set up JDK 17
uses: actions/setup-java@v4.0.0 # 자바 설치
with:
java-version: 17 # 버전
distribution: 'adopt' # 배포판

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

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash # gradle build

- name: Get current time
uses: 1466587594/get-current-time@v2 # build시점의 시간 확보
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # 서울 UTC 적용

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

- 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 .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_GITHUB_ACTIONS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_GITHUB_ACTIONS_SECRET_ACCESS_KEY }}
application_name: pictalk-dev
environment_name: Pictalk-dev-env
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_deployment: false
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;
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
78 changes: 41 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'com'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'org.springframework.security:spring-security-crypto'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'org.springframework.security:spring-security-crypto'
// implementation('org.springframework.security:spring-security-oauth2-client')
implementation 'org.springframework.security:spring-security-test'
implementation 'org.springframework.security:spring-security-test'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// Environment
// Environment
// developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
implementation 'io.github.cdimascio:dotenv-java:2.2.0'
implementation 'io.github.cdimascio:dotenv-java:2.2.0'

// Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'com.h2database:h2:2.1.214'
// Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'com.h2database:h2:2.1.214'

// Lombok
annotationProcessor 'org.projectlombok:lombok'
// Lombok
annotationProcessor 'org.projectlombok:lombok'

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}

jar {
enabled = false
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jwt:
refresh:
expiration: 86400000
header: Refresh
secret: ${JWT_SECURITY_KEY}
secret: ${JWT_SECURITY_KEY}

0 comments on commit 1a7a17a

Please sign in to comment.