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

Feature: 배포 세팅 #5

Merged
merged 27 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
979cefd
feat: action workflow 작성 #3
wjdtkdgns Nov 19, 2023
41ca1fe
fix: workflow needs 오타 수정 #3
wjdtkdgns Nov 19, 2023
9b186fe
fix: workflow 수정 #3
wjdtkdgns Nov 19, 2023
2589d45
fix: 오타 수정 #3
wjdtkdgns Nov 19, 2023
c2cf4ed
feat: secret test 추가 #3
wjdtkdgns Nov 20, 2023
a2c4e6d
feat: action test 추가 #3
wjdtkdgns Nov 20, 2023
5f6cffc
fix: docker login 방식 변경 #3
wjdtkdgns Nov 20, 2023
51479f2
fix: workflow script 수정 #3
wjdtkdgns Nov 20, 2023
dd23cb6
feat: dockerfile 생성 및 jdk 변경 #3
wjdtkdgns Nov 20, 2023
3a32ebf
fix: docker 명령어 수정 #3
wjdtkdgns Nov 20, 2023
892785a
chore: 주석 삭제 #3
wjdtkdgns Nov 20, 2023
899fe3b
fix: docker 명령어 수정 #3
wjdtkdgns Nov 20, 2023
864ed56
feat: nginx 추가 #3
wjdtkdgns Nov 20, 2023
3afe9b0
fix: 오타 수정 #3
wjdtkdgns Nov 20, 2023
247fb62
feat: nginx pull 명령어 추가 #3
wjdtkdgns Nov 20, 2023
261c54e
fix: workflow job 통합 #3
wjdtkdgns Nov 20, 2023
3354580
fix: docker pull 명령어 수정 #3
wjdtkdgns Nov 20, 2023
5254891
fix: docker-compose로 변경 #3
wjdtkdgns Nov 20, 2023
7e5b007
fix: action 브랜치 수정 #3
wjdtkdgns Nov 20, 2023
1b3b5ab
fix: deploy branch prod로 변경 #3
wjdtkdgns Nov 21, 2023
beb564b
fix: gradle cache key 변경 #3
wjdtkdgns Nov 21, 2023
a6325f6
fix: gradle cache key, path 변경 #3
wjdtkdgns Nov 21, 2023
d8e96ac
fix: gradle cache key 변경 #3
wjdtkdgns Nov 21, 2023
7cbe07d
fix: no daemon 추가 #3
wjdtkdgns Nov 21, 2023
b3db43c
fix: gradle cache 주석처리 #3
wjdtkdgns Nov 21, 2023
e5e6d53
feat: remove mysql data #3
wjdtkdgns Nov 21, 2023
fc572a1
feat: run script 수정 #3
wjdtkdgns Nov 21, 2023
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
14 changes: 14 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ jobs:
kotlin-version: ${{ matrix.kotlin-version }}
distribution: 'adopt'

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

# 빌드, ktlint check도 진행됨
- name: Gradle Clean & Build
run: ./gradlew clean build
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Deploy

on:
push:
branches: ['develop']

env:
ACTIVE_PROFILE: "prod"
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_IMAGE_NAME: ${{ secrets.DOCKERHUB_IMAGE_NAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 staging, dev 환경 구축없이 prod 단일 운영으로 초기 논의를 했던 것 같은데요!
요기 branch 설정이 바뀌어야 될 것 같아요.

아니면, dev 환경을 별도로 분리해서 배포하는 방식으로 진행해야 될 것 같아요.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

초기진행

  • prod 단일 배포

추후(서비스가 커진다는 행복회로)

  • prod, staging 배포

추후(미쵸따!)

  • prod, staging, dev 배포


permissions:
contents: read

jobs:
build_and_push:
runs-on: ubuntu-latest
strategy:
matrix:
kotlin-version: [ "1.8.22" ]
java-version: [ "17" ]

steps:
- name: Check Out The Repository
uses: actions/checkout@v3

- name: Set up Kotlin
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
kotlin-version: ${{ matrix.kotlin-version }}
distribution: 'corretto'

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


- name: Build with Gradle
run: ./gradlew build --no-daemon

- name: Make image tag
run: echo "IMAGE_TAG=$ACTIVE_PROFILE-${GITHUB_SHA::7}" >> $GITHUB_ENV # activeProfile-커밋 hash 값

- name: Docker build and push
run: |
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
docker build -t $DOCKERHUB_USERNAME/$DOCKERHUB_IMAGE_NAME:${{env.IMAGE_TAG}} .
docker push $DOCKERHUB_USERNAME/$DOCKERHUB_IMAGE_NAME:${{env.IMAGE_TAG}}

- name: Get Public IP
id: publicip
run: |
response=$(curl -s canhazip.com)
echo "ip='$response'" >> $GITHUB_OUTPUT

- 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: ${{ secrets.AWS_REGION }}

- name: Add GitHub IP to AWS
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32

- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
script: |
cd susu

sudo touch .env
echo "${{ secrets.ENV_VARS }}" | sudo tee .env > /dev/null
echo "IMAGE_TAG=${{ env.IMAGE_TAG }}" >> .env

sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker rmi $(sudo docker images -q)
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${{env.IMAGE_TAG}}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/susu-nginx:0.0.1
sudo docker-compose -f ~/susu/docker-compose.yml --env-file ~/susu/.env up --build -d

sudo docker system prune --all -f

- name: Remove IP FROM security group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.publicip.outputs.ip }}/32
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ out/
### VS Code ###
.vscode/

mysqldata/
mysqldata/

.env

docker-compose.prod.yml
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM amazoncorretto:17

ARG JAR_FILE=./build/libs/*.jar
COPY ${JAR_FILE} app.jar

ARG PROFILE=dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ARG PROFILE=dev
ARG PROFILE=prod

ENV PROFILE=${PROFILE}

ENTRYPOINT ["java","-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
6 changes: 3 additions & 3 deletions src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ spring:

# DEV-DATABASE-COMMON
datasource: &dev-datasource
url: jdbc:mysql://localhost:3306/susu?useUnicode=true&charset=utf8mb4&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
username: susu
password: susu
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${DB_NAME:susu}?useUnicode=true&charset=utf8mb4&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
username: ${MYSQL_USERNAME:susu}
password: ${MYSQL_PASSWORD:susu}
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application-prod.yml에 해당 셋업 진행해야 될 것 같아요!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prod는 default값 빼고 세팅할게요!
디비 연결 안되면 에러 터트리는게 맞을 것 같다고 생각해서요

hikari:
minimum-idle: 2
maximum-pool-size: 2
Expand Down
Loading