Skip to content
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

[Feat] Elastic Beanstalk을 통한 CI/CD를 위한 설정 파일 추가 #32

Merged
merged 34 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a05e2b
feat: Elastic Beanstalk을 통한 CI/CD를 위한 설정 파일 추가
wldns2577 Oct 4, 2023
d4dfdfc
feat: deploy 시 java distribution 지정
wldns2577 Oct 4, 2023
436a9dd
feat: CI/CD 트리거 추가
wldns2577 Oct 4, 2023
d173e7f
fix: CI/CD 트리거 수정
wldns2577 Oct 4, 2023
0873867
feat: deploy gradlew 설치 코드 추가 및 주석 수정
wldns2577 Oct 4, 2023
9faf161
fix: deploy gradle 설치 코드 수정
wldns2577 Oct 4, 2023
1d089b1
fix: deploy gradle 설치 권한 추가
wldns2577 Oct 4, 2023
6668f1d
fix: deploy 코드 실행 순서 수정
wldns2577 Oct 4, 2023
fd883ca
fix: deploy 불필요한 명령 제거
wldns2577 Oct 4, 2023
ca0c699
feat: deploy gradlew 설정 명령 권한 추가
wldns2577 Oct 4, 2023
0978f07
feat: deploy gradlew 설정 명령 옵션 추가
wldns2577 Oct 4, 2023
ae65d80
feat: deploy gradle 설치 버전 명시
wldns2577 Oct 4, 2023
3fbe467
fix: deploy gradle 설치 명령 수정
wldns2577 Oct 4, 2023
3aa6d8f
fix: deploy gradle 설치 버전 수정
wldns2577 Oct 4, 2023
0514f15
fix: deploy gradle 설치 방식 수정
wldns2577 Oct 4, 2023
d38e5ed
fix: deploy gradle 설치 버전 재수정
wldns2577 Oct 4, 2023
aa6c977
test: deploy 테스트 코드 작성
wldns2577 Oct 4, 2023
f960415
build: targetCompatibility 추가
wldns2577 Oct 4, 2023
4cc66b0
fix : deploy gradle wrapper 버전 명시 제거
wldns2577 Oct 4, 2023
8af5549
fix: deploy gradlew 코드 수정 및 삭제
wldns2577 Oct 4, 2023
a37cf50
fix: deploy gradlew 코드 수정 및 삭제
wldns2577 Oct 4, 2023
2acb969
fix: deploy gradlew 코드 추가
wldns2577 Oct 4, 2023
6d84257
fix: deploy gradle 설치 방식 수정
wldns2577 Oct 4, 2023
79154f3
fix: deploy 오탈자 수정
wldns2577 Oct 4, 2023
b5d0b40
feat: deploy gradle-build-action wrapper 명시
wldns2577 Oct 4, 2023
0be596b
feat: deploy gradlew 수정
wldns2577 Oct 4, 2023
6f5b531
fix: 오탈자 수정
wldns2577 Oct 4, 2023
6a88621
build: gradle wrapper 설정 추가
wldns2577 Oct 4, 2023
34c6b38
build: settings plugin 추가
wldns2577 Oct 4, 2023
c37b7a9
build: gradle-wrapper.jar 추가
Ji-Un-Gil Oct 4, 2023
dd1ba5f
test: deploy gradle 설치 코드 삭제
wldns2577 Oct 4, 2023
9842b1f
Merge branch 'feature/#30' of https://github.com/Car-Give/Backend int…
wldns2577 Oct 4, 2023
ca34371
feat: gradle caching, test result 기능 추가
wldns2577 Oct 4, 2023
576d242
feat: deploy 권한 추가
wldns2577 Oct 4, 2023
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
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
killall java
java -Dfile.encoding=UTF-8 -jar $JAR_PATH
138 changes: 138 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: carGive Dev CI/CD

permissions:
checks: write
pull-requests: write

on:
pull_request:
workflow_dispatch: # (2) 수동 실행

jobs:
test:
runs-on: ubuntu-latest # (3) OS환경
if: startsWith(github.head_ref, 'feature/')

steps:
- name: Checkout
uses: actions/checkout@v2 # (4) 코드 check out : 스프링부트 프로젝트의 소스코드를 내려받는다

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

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

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

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

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

- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash # (10) 확보한 시간 보여주기

- name: Code Test
run: ./gradlew test
shell: bash # (11) 테스트 코드 실행

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }} # 테스트가 실패하여도 Report를 보기 위해 `always`로 설정
with:
files: build/test-results/**/*.xml

- name: Cleanup Gradle Cache
if: ${{ always() }}
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
build:
runs-on: ubuntu-latest # (3) OS환경
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'

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-hotspot

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

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

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

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

- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash # (10) 확보한 시간 보여주기

- name: Generate deployment package
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions 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_ACCESS_KEY}}
aws_secret_key: ${{secrets.AWS_SECRET_KEY}}
application_name: carGive
environment_name: carGive-env
version_label: github-action-${{steps.current-time.outputs.formattedTime}}
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_environment_recovery: 60

- name: Cleanup Gradle Cache
if: ${{ always() }}
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
58 changes: 58 additions & 0 deletions .platform/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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;
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
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
targetCompatibility = '17'
}

wrapper {
gradleVersion = '8.3'
}

configurations {
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 2 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'carGive'
rootProject.name = 'carGive'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.cargive.global.infra;

import com.example.cargive.global.base.BaseResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/health")
public class ElasticBeanstalkHealthCheck {
@GetMapping
public ResponseEntity<BaseResponse> getHealthCheck() {
return BaseResponse.toResponseEntityContainsResult("It Works!");
}
}
Loading