-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 19 commits
979cefd
41ca1fe
9b186fe
2589d45
c2cf4ed
a2c4e6d
5f6cffc
51479f2
dd23cb6
3a32ebf
892785a
899fe3b
864ed56
3afe9b0
247fb62
261c54e
3354580
5254891
7e5b007
1b3b5ab
beb564b
a6325f6
d8e96ac
7cbe07d
b3db43c
e5e6d53
fc572a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 }} | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,8 @@ out/ | |
### VS Code ### | ||
.vscode/ | ||
|
||
mysqldata/ | ||
mysqldata/ | ||
|
||
.env | ||
|
||
docker-compose.prod.yml |
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ENV PROFILE=${PROFILE} | ||||||
|
||||||
ENTRYPOINT ["java","-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. application-prod.yml에 해당 셋업 진행해야 될 것 같아요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prod는 default값 빼고 세팅할게요! |
||
hikari: | ||
minimum-idle: 2 | ||
maximum-pool-size: 2 | ||
|
There was a problem hiding this comment.
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 환경을 별도로 분리해서 배포하는 방식으로 진행해야 될 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
초기진행
추후(서비스가 커진다는 행복회로)
추후(미쵸따!)