Skip to content

Commit

Permalink
feat: EFUB week11 ์„ธ์…˜
Browse files Browse the repository at this point in the history
  • Loading branch information
seohyun-lee committed Sep 10, 2024
1 parent ce1fcb4 commit 05d52e0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
74 changes: 41 additions & 33 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@ name: Deploy to Amazon EC2

on:
push:
branches: [ "develop" ]

env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: efub-week10-github-actions-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: efub-week10-codedeploy-app
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: efub-week10-codedeploy-deployment-group

permissions:
contents: read
branches: [ "week11" ]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
Expand All @@ -26,40 +16,58 @@ jobs:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
distribution: 'zulu'

- name: make application.yml
run: |
mkdir ./src/main/resources
cd ./src/main/resources
mkdir ./blog/src/main/resources
cd ./blog/src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: |
cd ./blog
chmod +x ./gradlew
./gradlew build -x test
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
- name: Login to DockerHub
uses: docker/login-action@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- 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
# Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ ๋ฐ ํ‘ธ์‹œ
- name: Docker build & push
uses: docker/build-push-action@v6
with:
context: ./blog
file: ./blog/Dockerfile
push: true
tags: ${{ secrets.DOCKER_REPO }}:latest

# ์„œ๋ฒ„์— ๋ฐฐํฌ
- name: Deploy to Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}:lastest
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
11 changes: 11 additions & 0 deletions blog/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ์‚ฌ์šฉํ•  base ์ด๋ฏธ์ง€ ์„ ํƒ
FROM openjdk:17

# build/libs/ ์— ์žˆ๋Š” jar ํŒŒ์ผ์„ JAR_FILE ๋ณ€์ˆ˜์— ์ €์žฅ
ARG JAR_FILE=build/libs/*.jar

# JAR_FILE์„ app.jar๋กœ ๋ณต์‚ฌ
COPY ${JAR_FILE} app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "-Duser.timezone=Asia/Seoul", "app.jar"]

0 comments on commit 05d52e0

Please sign in to comment.