[release] μμ μ¬ν λ°μμ μν΄ λ°°ν¬ν©λλ€. #35
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 |