๐ท[CD]:GitHub Actions, Docker ๋ฐฐํฌ ๊ด๋ จ #40
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 CI with Gradle & Docker | |
on: | |
push: | |
branches: [ "develop", "feat/*", "cd/*", "fix/*", "hotfix/*", "refactor/*", "chore/*", "docs/*", "style/*", "test/*" ] | |
pull_request: | |
types : [ closed ] | |
workflow_dispatch: # ์๋ ์คํ ๊ฐ๋ฅ | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
# develop ๊ธฐ๋ฐ ๋ธ๋์น๊ฐ PR์ด merge ๋์ ๊ฒฝ์ฐ์๋ง ์งํ | |
# ๊ฐ๋ฐ ์ดํ์ if ๋ฌธ ๋ถ์ด๊ธฐ.. if๋ฌธ ์์ผ๋ฉด Status skipped ๋จ | |
# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Spring Boot ์ดํ๋ฆฌ์ผ์ด์ Build (1) | |
- name: Spring Boot Build | |
run: ./gradlew clean build -x test --warning-mode=all --stacktrace | |
# Docker ์ด๋ฏธ์ง Build (2) | |
- 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) | |
- name: get GitHub IP | |
id: ip | |
uses: haythem/[email protected] | |
# 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 ${{ steps.ip.outputs.ipv4 }}/32 | |
# AWS EC2 Server Connect & Docker ๋ช ๋ น์ด ์คํ (8) | |
- name: AWS EC2 Connection | |
uses: appleboy/ssh-action@master | |
with: | |
host : ec2-3-39-194-35.ap-northeast-2.compute.amazonaws.com | |
username : root | |
password : pwd | |
port : 22 | |
# host: ${{ secrets.EC2_HOST }} | |
# username: ${{ secrets.EC2_USERNAME }} | |
# password: ${{ secrets.EC2_PASSWORD }} | |
# port: ${{ secrets.EC2_SSH_PORT }} | |
timeout: 60s | |
script: | |
cd | |
# sudo docker stop gamegoo | |
# sudo docker rm gamegoo | |
# sudo docker run -it -d -p 8080:8080 --name rimi3226 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 ${{ steps.ip.outputs.ipv4 }}/32 |