Merge pull request #65 from Gamegoo-repo/feat/41 #134
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 ] | |
push: | |
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 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 . | |
# 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 | |
# 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 docker stop gamegoo_api | |
sudo docker rm gamegoo_api | |
sudo docker run -it -d -p 8080:8080 --name gamegoo_api rimi3226/gamegoo | |
# 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 |