Skip to content

Commit

Permalink
👷 [cicd] github action moodify
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi3226 committed Jul 12, 2024
1 parent 031ff27 commit c625647
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
pull_request:
types: [ closed ]
push:
workflow_dispatch: # 수동 실행 가능
workflow_dispatch:

jobs:
build-and-push-image:
setup:
runs-on: ubuntu-latest

steps:
Expand All @@ -19,7 +20,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# 환경 변수 설정 (0)
- name: Set Yaml
uses: microsoft/variable-substitution@v1
with:
Expand All @@ -31,44 +31,71 @@ jobs:
spring.jwt.secret: ${{ secrets.JWT_SECRET }}
spring.mail.password: ${{ secrets.GMAIL_PWD }}

# Spring Boot 어플리케이션 Build (1)
build:
runs-on: ubuntu-latest
needs: setup

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Spring Boot Build
run: ./gradlew clean build -x test --warning-mode=all --stacktrace

# Docker 이미지 Build (2)
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: build/libs/*.jar

docker:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifact

- name: docker image build
run: docker build -t rimi3226/gamegoo .

# DockerHub Login (3)
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PW }}

# Docker Hub push (4)
- name: docker Hub push
run: docker push rimi3226/gamegoo

# GET GitHub IP (5)
deploy:
runs-on: ubuntu-latest
needs: docker

steps:
- name: Checkout
uses: actions/checkout@v3

- name: get GitHub IP
id: ip
run: echo "ipv4=$(curl -s https://api.ipify.org)" >> $GITHUB_ENV

# Configure AWS Credentials (6) - 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 (7)
- 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 명령어 실행 (8)
- name: AWS EC2 Connection
uses: appleboy/ssh-action@master
with:
Expand All @@ -82,7 +109,6 @@ jobs:
sudo docker rm gamegoo_api
sudo docker run -it -d -p 8080:8080 --name gamegoo_api rimi3226/gamegoo
# REMOVE Github IP FROM security group (9)
- 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

0 comments on commit c625647

Please sign in to comment.