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

deploy: 프로젝트 배포 테스트 #84

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c5a9a89
feat: CI workflow
Hamiwood Dec 19, 2024
3d1ad12
feat: CD workflow
Hamiwood Dec 19, 2024
72e19b3
feat: 배포 설정 파일 추가
Hamiwood Dec 19, 2024
dc50ad9
feat: 배포 스크립트 추가
Hamiwood Dec 19, 2024
3a2e55c
feat: Ci 실패 테스트(컴파일 에러)
Hamiwood Dec 19, 2024
d264de9
test: push일 때도 ci 되도록
Hamiwood Dec 19, 2024
4b8171d
fix: ci 오타수정
Hamiwood Dec 19, 2024
fd425ce
fix: gradle 권한 부여
Hamiwood Dec 19, 2024
72fc78b
fix: gradle 권한 부여 수정
Hamiwood Dec 19, 2024
ec03bc5
fix: gradle 권한 부여 수정
Hamiwood Dec 19, 2024
7cde4c5
fix: gradle 권한 부여 수정
Hamiwood Dec 19, 2024
8d59b13
test: Ci 성공 테스트
Hamiwood Dec 19, 2024
277a42e
test: Ci 실패 테스트(재)
Hamiwood Dec 19, 2024
34bbef7
fix: build-and-deploy가 보이지 않는 문제
Hamiwood Dec 19, 2024
cc3f815
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
9a20fb5
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
10d7170
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
ce11797
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
4124016
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
54bf842
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
0dd0b0d
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
19125ea
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
5d7fb74
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
95db1dd
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
5526f2d
fix: build-and-deploy가 보이지 않는 문제 수정 > 아티팩트 추가(종속성)
Hamiwood Dec 19, 2024
4f47c35
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 19, 2024
52dec47
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 20, 2024
7babf8d
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 20, 2024
2dc171e
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 20, 2024
af6d8c1
fix: build-and-deploy가 보이지 않는 문제 수정
Hamiwood Dec 20, 2024
107e0bf
fix: CI/CD yml 합치기(임시)
Hamiwood Dec 20, 2024
9d829d4
fix: prod.yml 파일 추가 코드
Hamiwood Dec 20, 2024
7caa484
fix: prod.yml 파일 루트 변경
Hamiwood Dec 20, 2024
b3178b0
fix: prod.yml 공파일 직접 넣고 테스트
Hamiwood Dec 20, 2024
e004353
fix: prod.yml 공파일 루트 변경
Hamiwood Dec 20, 2024
3c33878
fix: prod.yml 파일 내용변경
Hamiwood Dec 20, 2024
d796615
fix: bucket 이름 변경
Hamiwood Dec 20, 2024
b842488
fix: CI/CD 분리 git token 부여
Hamiwood Dec 20, 2024
68d1452
fix: 파일명 수정
Hamiwood Dec 20, 2024
9257b4b
fix: 파일명 수정
Hamiwood Dec 20, 2024
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
92 changes: 92 additions & 0 deletions .github/workflows/ItcastBuildAndDeploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: ItcastBuildAndDeploy

on:
workflow_run:
workflows: ["ItcastBuildAndTest"]
types:
- completed

jobs:
deploy:
# if: >
# github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.KJH_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Set Yaml
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/application-prod.yml
env:
spring.datasource.url: ${{secrets.KJH_MYSQL_URL}}
spring.datasource.username: ${{ secrets.KJH_DB_USERNAME }}
spring.datasource.password: ${{ secrets.KJH_DB_PASSWORD }}
spring.data.redis.host: ${{ secrets.KJH_REDIS_HOST }}
spring.data.redis.port: ${{ secrets.KJH_REDIS_PORT }}

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose

- name: Set up Docker Compose
run: |
docker-compose up -d
docker-compose ps

- name: Wait for services to be ready
run: |
until docker-compose exec -T mysql mysqladmin ping -h"127.0.0.1" --silent; do
echo "Waiting for MySQL to be ready"
sleep 5
done
sleep 10

- name: Build with Gradle (prod profile)
run: ./gradlew clean build -Dspring.profiles.active=prod -Duser.language=ko -Duser.country=KR

- name: Tear down Docker Compose
if: always()
run: docker-compose down

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Make Zip file
run: zip -r $GITHUB_SHA.zip build/libs/*.jar appspec.yml scripts/deploy.sh
shell: bash

- name: AWS credential setting
uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ${{secrets.AWS_KJH_REGION}}
aws-access-key-id: ${{secrets.AWS_KJH_ACCESS_KEY}}
aws-secret-access-key: ${{secrets.AWS_KJH_SECRET_ACCESS_KEY}}

- name: Upload to S3
run: aws s3 cp ./$GITHUB_SHA.zip s3://${{ secrets.AWS_KJH_S3_BUCKET }}/$GITHUB_SHA.zip

- name: EC2 Deploy
run: aws deploy create-deployment
--application-name ${{secrets.AWS_KJH_CODE_DEPLOY_APPLICATION}}
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{secrets.AWS_KJH_CODE_DEPLOY_GROUP}}
--s3-location bucket=${{secrets.AWS_KJH_S3_BUCKET}},key=$GITHUB_SHA.zip,bundleType=zip
54 changes: 54 additions & 0 deletions .github/workflows/ItcastBuildAndTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: ItcastBuildAndTest

on:
push:
branches:
- main
- issue/**

pull_request:
branches:
- main
- issue/**

jobs:
build:
runs-on: ubuntu-latest

steps:

- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose

- name: Set up Docker Compose
run: |
docker-compose up -d
docker-compose ps

- name: Wait for services to be ready
run: |
until docker-compose exec -T mysql mysqladmin ping -h"127.0.0.1" --silent; do
echo "Waiting for MySQL to be ready"
sleep 5
done
sleep 10

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test -Duser.language=ko -Duser.country=KR

- name: Tear down Docker Compose
if: always()
run: docker-compose down
8 changes: 8 additions & 0 deletions admin/src/main/java/itcast/test/CiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package itcast.test;

public class CiTest {
public static void main(String[] args) {
System.out.println("Hello World");
int error;
}
}
9 changes: 9 additions & 0 deletions application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
datasource:
url: ""
username: ""
password: ""
data:
redis:
host: ""
port: ""
17 changes: 17 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/itcast
overwrite: yes

permissions:
- object: /
owner: ubuntu
group: ubuntu

hooks:
ApplicationStart:
- location: scripts/deploy.sh
timeout: 60
22 changes: 22 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

DEPLOY_PATH=/home/ubuntu/itcast
echo ">>> 배포 경로: $DEPLOY_PATH" >> /home/ubuntu/deploy.log

mkdir -p $DEPLOY_PATH
echo ">>> 디렉토리 생성 완료" >> /home/ubuntu/deploy.log

BUILD_JAR=$(ls /home/ubuntu/itcast/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_JAR)
echo ">>> build 파일명: $JAR_NAME" >> /home/ubuntu/deploy.log

echo ">>> build 파일 복사" >> /home/ubuntu/deploy.log
cp $BUILD_JAR $DEPLOY_PATH 2>> /home/ubuntu/deploy_err.log

echo ">>> 현재 실행중인 애플리케이션 pid 확인 후 일괄 종료" >> /home/ubuntu/deploy.log
sudo ps -ef | grep java | awk '{print $2}' | xargs kill -15 2>> /home/ubuntu/deploy_err.log

DEPLOY_JAR=$DEPLOY_PATH/$JAR_NAME
echo ">>> DEPLOY_JAR 배포" >> /home/ubuntu/deploy.log
echo ">>> $DEPLOY_JAR의 $JAR_NAME를 실행합니다" >> /home/ubuntu/deploy.log
nohup java -jar -Dspring.profiles.active=prod $DEPLOY_JAR >> /home/ubuntu/deploy.log 2>> /home/ubuntu/deploy_err.log &
Loading