Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4890968
ci/cd: test1
toychip Nov 16, 2024
4c16f86
ci/cd: test2
toychip Nov 16, 2024
b6a5030
ci/cd: test3
toychip Nov 16, 2024
971111b
ci/cd: test4
toychip Nov 16, 2024
3959aeb
ci/cd: test5
toychip Nov 16, 2024
c6dc0ca
ci/cd: test6
toychip Nov 16, 2024
f1012af
ci/cd: test7
toychip Nov 16, 2024
f5b8589
ci/cd: test8
toychip Nov 16, 2024
66c41bf
ci/cd: test9
toychip Nov 16, 2024
4a9db53
ci/cd: test10
toychip Nov 16, 2024
795fe3b
ci/cd: test11
toychip Nov 16, 2024
09fc196
ci/cd: test12
toychip Nov 16, 2024
ceea851
ci/cd: test13
toychip Nov 16, 2024
0eb9d59
ci/cd: test14
toychip Nov 16, 2024
77e76aa
ci/cd: test15
toychip Nov 16, 2024
e114224
ci/cd: test16
toychip Nov 16, 2024
932924b
ci/cd: test17
toychip Nov 16, 2024
01eb902
ci/cd: test18
toychip Nov 16, 2024
6ba2bbd
ci/cd: test19
toychip Nov 16, 2024
10d491a
ci/cd: test20
toychip Nov 16, 2024
5c4a765
ci/cd: test21
toychip Nov 16, 2024
21deab1
ci/cd: test22
toychip Nov 16, 2024
e0d5c5d
ci/cd: test23
toychip Nov 16, 2024
47c3289
ci/cd: test24
toychip Nov 16, 2024
927bdb0
ci/cd: test25
toychip Nov 16, 2024
631e603
ci/cd: test26
toychip Nov 16, 2024
02863be
ci/cd: test27
toychip Nov 16, 2024
15288f3
ci/cd: test28
toychip Nov 16, 2024
a0b00a1
ci/cd: test29
toychip Nov 16, 2024
febe4b1
ci/cd: test30
toychip Nov 16, 2024
b2c8d52
ci/cd: test31
toychip Nov 16, 2024
f18fb5e
ci/cd: test32
toychip Nov 16, 2024
7c4d17c
ci/cd: test33
toychip Nov 16, 2024
64f5316
ci/cd: test34
toychip Nov 16, 2024
b755ca0
ci/cd: test35
toychip Nov 16, 2024
2bfce24
ci/cd: test36
toychip Nov 16, 2024
cb0fb97
ci/cd: test37
toychip Nov 16, 2024
a074ce2
ci/cd: test38
toychip Nov 16, 2024
292be91
ci/cd: test39
toychip Nov 16, 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
117 changes: 117 additions & 0 deletions .github/workflows/deploy-ec2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: CI/CD Workflow for Multi-Module Project

on:
push:
branches:
- setting/change-cicd-action

jobs:
ci:
runs-on: ubuntu-latest

env:
AWS_REGION: "ap-northeast-2"

steps:
- name: Checkout Code
uses: actions/checkout@v2

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

- name: Build and Test Each Module
run: |
./gradlew :ttoklip-api:clean :ttoklip-api:build :ttoklip-api:test
./gradlew :ttoklip-batch:clean :ttoklip-batch:build :ttoklip-batch:test
./gradlew :ttoklip-notification:clean :ttoklip-notification:build :ttoklip-notification:test

- name: Verify Build Artifacts
run: |
echo "Verifying build artifacts..."
ls -la ttoklip-api/build/libs/
ls -la ttoklip-batch/build/libs/
ls -la ttoklip-notification/build/libs/

- name: Save Build Artifacts
run: |
mkdir -p deploy
cp ttoklip-api/build/libs/ttoklip-api-SNAPSHOT.jar deploy/
cp ttoklip-batch/build/libs/ttoklip-batch-SNAPSHOT.jar deploy/
cp ttoklip-notification/build/libs/ttoklip-notification-SNAPSHOT.jar deploy/

cp ttoklip-api/Dockerfile-prod deploy/Dockerfile-api-prod
cp ttoklip-batch/Dockerfile-prod deploy/Dockerfile-batch-prod
cp ttoklip-notification/Dockerfile-prod deploy/Dockerfile-notification-prod
cp -r nginx deploy/
cp docker-compose.prod.yml deploy/
zip -r deploy-package.zip deploy

- name: Configure AWS Credentials
run: |
aws configure set aws_access_key_id ${{ secrets.SSM_PUBLIC }}
aws configure set aws_secret_access_key ${{ secrets.SSM_PRIVATE }}
aws configure set region $AWS_REGION

- name: Upload to S3
run: |
aws s3 cp deploy-package.zip s3://ttoklip-deploy/zips/deploy-package.zip --region ap-northeast-2

cd:
needs: ci
runs-on: ubuntu-latest

env:
AWS_REGION: "ap-northeast-2"

steps:
- name: Configure AWS Credentials
run: |
aws configure set aws_access_key_id ${{ secrets.SSM_PUBLIC }}
aws configure set aws_secret_access_key ${{ secrets.SSM_PRIVATE }}
aws configure set region $AWS_REGION

- name: Upload Deploy Script to S3
run: |
cat << 'EOF' > deploy_script.sh
#!/bin/bash

mkdir -p /home/ec2-user/ttoklip/application
sudo chown -R ec2-user:ec2-user /home/ec2-user/ttoklip
sudo chmod -R 755 /home/ec2-user/ttoklip

if [ -d "/home/ec2-user/ttoklip/application/deploy" ]; then
rm -rf /home/ec2-user/ttoklip/application/deploy
fi

aws s3 cp s3://ttoklip-deploy/zips/deploy-package.zip /home/ec2-user/ttoklip/application/deploy-package.zip --region ap-northeast-2

unzip -o /home/ec2-user/ttoklip/application/deploy-package.zip -d /home/ec2-user/ttoklip/application/

docker-compose -f /home/ec2-user/ttoklip/application/deploy/docker-compose.prod.yml --env-file /home/ec2-user/ttoklip/application/.env up -d --build
EOF

zip deploy_script.zip deploy_script.sh

aws s3 cp deploy_script.zip s3://ttoklip-deploy/zips/deploy-script.zip --region ap-northeast-2

- name: Deploy to EC2 via SSM
run: |
aws ssm send-command \
--instance-ids "${{ secrets.EC2_INSTANCE_ID }}" \
--document-name "AWS-RunShellScript" \
--comment "Running deployment script" \
--parameters commands=$'\
aws s3 cp s3://ttoklip-deploy/zips/deploy-script.zip /home/ec2-user/ttoklip/application/ --region ap-northeast-2\n\
cd /home/ec2-user/ttoklip/application/\n\
unzip -o deploy-script.zip\n\
chmod +x deploy_script.sh\n\
./deploy_script.sh' \
--output-s3-bucket-name "ttoklip-deploy" \
--output-s3-key-prefix "ssm-output" \
--region $AWS_REGION



Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Deploy to Amazon ECS - Develop
name: Deploy to Amazon ECS

on:
push:
branches: [ "main" ]
push:
branches-ignore:
- "**" # 모든 브랜치를 무시

env:
AWS_REGION: ap-northeast-2
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {

subprojects {
group = 'com'
version = '0.0.1-SNAPSHOT'
version = 'SNAPSHOT'
sourceCompatibility = '17'

apply plugin: 'java'
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version: '3.8'
services:
api:
build:
context: ./ttoklip-api
dockerfile: Dockerfile-prod
context: .
dockerfile: Dockerfile-api-prod
args:
JASYPT_ENCRYPTOR_PASSWORD: ${JASYPT_ENCRYPTOR_PASSWORD}
container_name: api
Expand All @@ -28,8 +28,8 @@ services:

batch:
build:
context: ./ttoklip-batch
dockerfile: Dockerfile-prod
context: .
dockerfile: Dockerfile-batch-prod
args:
JASYPT_ENCRYPTOR_PASSWORD: ${JASYPT_ENCRYPTOR_PASSWORD}
container_name: batch
Expand All @@ -53,8 +53,8 @@ services:

notification:
build:
context: ./ttoklip-notification
dockerfile: Dockerfile-prod
context: .
dockerfile: Dockerfile-notification-prod
args:
JASYPT_ENCRYPTOR_PASSWORD: ${JASYPT_ENCRYPTOR_PASSWORD}
container_name: notification
Expand Down
9 changes: 8 additions & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ http {
sendfile on;
keepalive_timeout 65;

# 로그 설정
error_log /var/log/nginx/error.log debug;

# API 컨테이너에 대한 upstream 설정
upstream api_upstream {
server api:8080; # API 컨테이너 이름과 포트
Expand All @@ -19,7 +22,11 @@ http {
server {
listen 80;

# 일반 API 요청을 처리
location /health {
proxy_pass http://api_upstream/health;
proxy_set_header Host $host;
}

location / {
proxy_pass http://api_upstream;
proxy_set_header Host $host;
Expand Down
2 changes: 1 addition & 1 deletion ttoklip-api/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:17

ARG JAR_FILE=build/libs/ttoklip-api-0.0.1-SNAPSHOT.jar
ARG JAR_FILE=ttoklip-api-SNAPSHOT.jar
ARG JASYPT_ENCRYPTOR_PASSWORD

ENV SPRING_PROFILES_ACTIVE=prod
Expand Down
2 changes: 1 addition & 1 deletion ttoklip-batch/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:17

ARG JAR_FILE=build/libs/ttoklip-batch-0.0.1-SNAPSHOT.jar
ARG JAR_FILE=ttoklip-batch-SNAPSHOT.jar
ARG JASYPT_ENCRYPTOR_PASSWORD

ENV SPRING_PROFILES_ACTIVE=prod
Expand Down
2 changes: 1 addition & 1 deletion ttoklip-notification/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:17

ARG JAR_FILE=build/libs/ttoklip-notification-0.0.1-SNAPSHOT.jar
ARG JAR_FILE=ttoklip-notification-SNAPSHOT.jar
ARG JASYPT_ENCRYPTOR_PASSWORD

ENV SPRING_PROFILES_ACTIVE=prod
Expand Down
Loading