[release] ์ต์ต์ข ๋ฐฐํฌ #43
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
# Workflow ์ด๋ฆ | |
name: CD workflow | |
# Event Trigger ํ๊ฒฝ | |
on: | |
pull_request: | |
branches: [ "main" ] # push๊ฐ main ๋ธ๋์น์ ์์ฑ๋๋ฉด ํธ๋ฆฌ๊ฑฐ | |
permissions: # ์ํฌํ๋ก์ฐ ๊ถํ | |
id-token: write | |
contents: read # ์ฝ๊ธฐ | |
jobs: | |
build: | |
# ์คํํ๊ฒฝ ์ค์ | |
runs-on: ubuntu-24.04 | |
# Action์ ์ฌ์ฉํ์ฌ Step์ ๊ตฌ์ฑ | |
steps: | |
# GitHub repository ์ฝ๋ ์ฒดํฌ์์ | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
# JDK 21 ์ค์น | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
# resources ํด๋ ์์ฑ | |
- name: Create resources folder if not exist | |
run: | | |
if [ ! -d "./src/main/resources" ]; then | |
mkdir -p ./src/main/resources | |
fi | |
# application.yml ํ์ผ ์์ฑ | |
- name: make application.yml | |
run: | | |
touch ./src/main/resources/application.yml | |
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml | |
shell: bash | |
# cloud ํด๋ ์์ฑ | |
- name: Create cloud folder if not exist | |
run: | | |
if [ ! -d "./src/main/resources/cloud" ]; then | |
mkdir -p ./src/main/resources/cloud | |
fi | |
# application-cloud.yml ํ์ผ ์์ฑ | |
- name: make application-cloud.yml | |
run: | | |
touch ./src/main/resources/cloud/application-cloud.yml | |
echo "${{ secrets.APPLICATION_CLOUD_YML }}" > ./src/main/resources/cloud/application-cloud.yml | |
shell: bash | |
# openapi ํด๋ ์์ฑ | |
- name: Create cloud folder if not exist | |
run: | | |
if [ ! -d "./src/main/resources/openapi" ]; then | |
mkdir -p ./src/main/resources/openapi | |
fi | |
# application-spotify.yml ํ์ผ ์์ฑ | |
- name: make application-spotify.yml | |
run: | | |
touch ./src/main/resources/openapi/application-spotify.yml | |
echo "${{ secrets.APPLICATION_SPOTIFY_YML }}" > ./src/main/resources/openapi/application-spotify.yml | |
shell: bash | |
# ๋น๋ ์๋ ํฅ์์ ์ํ Gradle ์บ์ฑ | |
- name: Gradle Caching | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
gradle-${{ runner.os }}- | |
# ๋น๋๋ฅผ ์ํ ๊ถํ ๋ถ์ฌ | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew # Gradle wrapper์ ์คํ ๊ถํ ๋ถ์ฌ | |
# Gradle์ ์ฌ์ฉํ์ฌ ๋น๋ ์คํ | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build -x test | |
# Docker ๋ก๊ทธ์ธ | |
- name: login docker hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker ๋น๋ ๋ฐ ํธ์ | |
- name: install docker buildx | |
uses: docker/[email protected] | |
- name: docker image build & push | |
run: | | |
docker build --platform linux/amd64 -t confetiserver/deploy . | |
docker push confetiserver/deploy | |
deploy: | |
needs: build | |
# ์คํํ๊ฒฝ ์ค์ | |
runs-on: ubuntu-24.04 | |
environment: production | |
# Action์ ์ฌ์ฉํ์ฌ Step์ ๊ตฌ์ฑ | |
steps: | |
# Github Action ํ๊ฒฝ์ Public IP ๊ฐ์ ธ์ค๊ธฐ | |
- name: Get Github action IP | |
id: ip | |
uses: haythem/[email protected] | |
# AWS ์ธ์ฆ | |
- name: configure aws credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_NAME }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
# AWS ECR ๋ก๊ทธ์ธ | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: true | |
# ๋ณด์ ๊ท์น์ ssh IP ์ถ๊ฐ | |
- name: Add Github Actions IP to Security group | |
run: | | |
aws ec2 authorize-security-group-ingress --group-name ${{ secrets.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
# ์๊ฒฉ ์๋ฒ์ ๋ฐฐํฌ | |
- name: docker container deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
port: ${{ secrets.PORT }} | |
script: | | |
cd ~ | |
docker login -u "${{ secrets.DOCKER_USERNAME }}" -p "${{ secrets.DOCKER_PASSWORD }}" | |
./deploy.sh | |
# ๋ณด์ ๊ท์น์ ssh IP ์ญ์ | |
- name: Remove Github Actions IP from security group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-name ${{ secrets.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 |