-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lsn5963/testbaepo
[FEAT] 배포
- Loading branch information
Showing
5 changed files
with
140 additions
and
1 deletion.
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,73 @@ | ||
name: Deploy to Amazon EC2 | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
S3_BUCKET_NAME: growme-github-actions-s3-bucket | ||
CODE_DEPLOY_APPLICATION_NAME: growme-codedeploy-app | ||
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: growme-codedeploy-app-group | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Build with Gradle | ||
uses: gradle/gradle-build-action@v3 | ||
with: | ||
arguments: clean build -x test | ||
|
||
- name: Generate application.yml | ||
run: | | ||
mkdir -p ./src/main/resources | ||
cd ./src/main/resources | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > ./application.yml | ||
cat ./application.yml # 디버깅용, 생성된 파일 내용 확인 | ||
# - name: Clean and Build with Gradle | ||
# run: ./gradlew clean build --refresh-dependencies | ||
|
||
- 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: ${{ env.AWS_REGION }} | ||
|
||
- name: Upload to AWS S3 | ||
run: | | ||
aws deploy push \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--ignore-hidden-files \ | ||
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | ||
--source . | ||
- name: Deploy to AWS EC2 from S3 | ||
run: | | ||
aws deploy create-deployment \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--deployment-config-name CodeDeployDefault.AllAtOnce \ | ||
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | ||
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip | ||
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,23 @@ | ||
version: 0.0 | ||
os: linux | ||
|
||
files: | ||
- source: / | ||
destination: /home/ubuntu/app | ||
overwrite: yes | ||
|
||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
hooks: | ||
AfterInstall: | ||
- location: scripts/stop.sh | ||
timeout: 60 | ||
runas: ubuntu | ||
ApplicationStart: | ||
- location: scripts/start.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,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
PROJECT_ROOT="/home/ubuntu/app" | ||
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" | ||
|
||
APP_LOG="$PROJECT_ROOT/application.log" | ||
ERROR_LOG="$PROJECT_ROOT/error.log" | ||
DEPLOY_LOG="$PROJECT_ROOT/deploy.log" | ||
|
||
TIME_NOW=$(date +%c) | ||
|
||
# build 파일 복사 | ||
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG | ||
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE | ||
|
||
# jar 파일 실행 | ||
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG | ||
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG & | ||
|
||
CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
PROJECT_ROOT="/home/ubuntu/app" | ||
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" | ||
|
||
DEPLOY_LOG="$PROJECT_ROOT/deploy.log" | ||
|
||
TIME_NOW=$(date +%c) | ||
|
||
# 현재 구동 중인 애플리케이션 pid 확인 | ||
CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
|
||
# 프로세스가 켜져 있으면 종료 | ||
if [ -z $CURRENT_PID ]; then | ||
echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG | ||
else | ||
echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG | ||
kill -15 $CURRENT_PID | ||
fi |