-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setting: AWS S3와 CodeDeploy 설정 후 github action 작성 완료 #48
- Loading branch information
1 parent
cf71535
commit 4827dc3
Showing
8 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Develop Branch CI | ||
|
||
on: | ||
push: | ||
branches: [ "setting/#48" ] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# JDK 설정 | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# 환경 변수 파일 생성 | ||
- name: Set environment values | ||
run: | | ||
cd ./src/main/resources # resources 폴더로 이동 | ||
touch ./env.properties # env.properties 파일 생성 | ||
echo "${{ secrets.ENV }}" > ./env.properties # github actions secret에서 가져온 값을 application.yml 파일에 씁니다 | ||
shell: bash | ||
|
||
# Gradle에 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
# Gradle test | ||
- name: Test with Gradle | ||
run: ./gradlew test | ||
|
||
# Gradle build | ||
- name: Build Gradle | ||
run: ./gradlew build | ||
|
||
# 압축 파일 만들기 | ||
- name: Make zip file | ||
run: | | ||
mkdir develop-deploy | ||
cp ./src/main/resources/env.properties ./deploy/.env | ||
cp ./docker-compose.blue.yml ./deploy/ | ||
cp ./docker-compose.green.yml ./deploy/ | ||
cp ./appspec.yml ./deploy/ | ||
cp ./Dockerfile ./deploy/ | ||
cp ./scripts/*.sh ./deploy/ | ||
cp ./build/libs/*.jar ./deploy/ | ||
zip -r -qq -j ./munecting.zip ./deploy | ||
# AWS 접속 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
# S3에 저장 | ||
- name: Upload to S3 | ||
run: aws s3 cp --region ap-northeast-2 ./munecting.zip s3://develop-code-deploy-munecting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
HELP.md | ||
env.properties | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:21 | ||
WORKDIR /munecting | ||
COPY munecting-0.0.1-SNAPSHOT.jar app.jar | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: / | ||
destination: /home/ubuntu/app | ||
overwrite: yes | ||
|
||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
mode: 777 | ||
|
||
hooks: | ||
ApplicationStart: | ||
- location: develop-deploy.sh | ||
timeout: 60 | ||
runas: ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#blue | ||
version: '3' | ||
services: | ||
mohazi-api: | ||
build: . | ||
ports: | ||
- "8081:8080" | ||
container_name: spring-blue | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#green | ||
version: '3' | ||
services: | ||
mohazi-api: | ||
build: . | ||
ports: | ||
- "8082:8080" | ||
container_name: spring-green | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
cd /home/ubuntu/app | ||
|
||
DOCKER_APP_NAME=spring | ||
|
||
# 실행중인 blue가 있는지 | ||
EXIST_BLUE=$(docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml ps | grep running) | ||
|
||
# green이 실행중이면 blue up | ||
if [ -z "$EXIST_BLUE" ]; then | ||
echo "blue up" | ||
docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml up -d --build | ||
|
||
sleep 30 | ||
|
||
docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml down | ||
docker image prune -af # 사용하지 않는 이미지 삭제 | ||
|
||
# blue가 실행중이면 green up | ||
else | ||
echo "green up" | ||
docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml up -d --build | ||
|
||
sleep 30 | ||
|
||
docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml down | ||
docker image prune -af | ||
fi |