[Fix/315] ๋ณด์ ๊ด๋ จ ๋น๋ฐ๋ฒํธ, ๋ค๋ฅธํ์ ํ๋กํ ์กฐํ ์์ #308
Workflow file for this run
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
name: Java CICD with Gradle & Docker | |
on: | |
pull_request: | |
types: [ closed ] | |
workflow_dispatch: # ์๋ ์คํ ๊ฐ๋ฅ | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# JDK 17 ์ค์น (1) | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# repository checkout (2) | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# ํ๊ฒฝ ๋ณ์ ์ค์ (3) | |
- name: Set Yaml | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: ./src/main/resources/application.yml | |
env: | |
spring.datasource.url: ${{ secrets.DB_URL }} | |
spring.datasource.username: ${{ secrets.DB_USERNAME }} | |
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | |
spring.jwt.secret: ${{ secrets.JWT_SECRET }} | |
spring.mail.password: ${{ secrets.GMAIL_PWD }} | |
spring.riot.api.key: ${{ secrets.RIOT_API }} | |
socket.server.url: https://socket.gamegoo.co.kr | |
# Spring Boot ์ดํ๋ฆฌ์ผ์ด์ Build (4) | |
- name: Spring Boot Build | |
run: ./gradlew clean build -x test --warning-mode=all --stacktrace | |
# Docker ์ด๋ฏธ์ง Build (5) | |
- name: docker image build | |
run: docker build -t rimi3226/gamegoo:${{ github.sha }} . | |
# DockerHub Login (6) | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PW }} | |
# Docker Hub push (7) | |
- name: docker Hub push | |
run: docker push rimi3226/gamegoo:${{ github.sha }} | |
# GET GitHub IP (8) | |
- name: get GitHub IP | |
id: ip | |
run: echo "ipv4=$(curl -s https://api.ipify.org)" >> $GITHUB_ENV | |
# Configure AWS Credentials (9) - AWS ์ ๊ทผ ๊ถํ ์ทจ๋(IAM) | |
- 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 | |
# Add github ip to AWS (10) | |
- name: Add GitHub IP to AWS | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32 | |
# AWS EC2 Server Connect & Docker ๋ช ๋ น์ด ์คํ (11) | |
- name: AWS EC2 Connection | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PEM_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
timeout: 50s | |
script: | | |
sudo timedatectl set-timezone Asia/Seoul | |
sudo docker pull rimi3226/gamegoo:${{ github.sha }} | |
sudo docker stop gamegoo_api | |
sudo docker rm gamegoo_api | |
sudo docker rm $(docker ps -a -q -f status=exited) | |
sudo docker image prune -a | |
sudo docker run -it -d -p 8080:8080 --name gamegoo_api \ | |
-e JAVA_OPTS="-Duser.timezone=Asia/Seoul" \ | |
rimi3226/gamegoo:${{ github.sha }} | |
# REMOVE Github IP FROM security group (12) | |
- name: Remove IP FROM security group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32 |