Chore: github-actions.yml 코드 수정 #159
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: bookwoori CI/CD v3 | |
on: | |
push: | |
branches: ["deploy"] | |
jobs: | |
build-and-deploy: | |
name: Build and Deploy Services | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
service: [core, auth, gateway, chat, notification] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: 17 | |
# Eureka 관련 설정 삭제 | |
- name: Remove Eureka Dependencies | |
run: | | |
find . -name 'build.gradle' | while read -r file; do | |
sed -i '/spring-cloud-starter-netflix-eureka-client/d' "$file" | |
sed -i '/spring-cloud-starter-netflix-eureka-server/d' "$file" | |
done | |
find . -name 'application*.yml' | while read -r file; do | |
sed -i '/eureka:/,+3d' "$file" | |
done | |
- name: Make application-prod.yml | |
run: | | |
mkdir -p ./${{ matrix.service }}/src/main/resources | |
touch ./${{ matrix.service }}/src/main/resources/application.yml | |
echo "${{ secrets[format('APPLICATION_{0}', matrix.service)] }}" > ./${{ matrix.service }}/src/main/resources/application.yml | |
- name: create-json | |
id: create-json | |
uses: jsdaniell/[email protected] | |
with: | |
name: "firebase-adminsdk.json" | |
json: ${{ secrets.FIREBASE_ADMINSDK }} | |
dir: "./notification/src/main/resources" | |
- name: Build Service with Gradle | |
run: | | |
cd ./${{ matrix.service }} | |
chmod +x ./gradlew | |
./gradlew clean build -x test --no-daemon | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker Build and Push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./${{ matrix.service }} | |
file: ./${{ matrix.service }}/Dockerfile | |
platforms: linux/arm64/v8 | |
push: true | |
tags: ${{ secrets[format('DOCKER_REPO_{0}', matrix.service)] }}:v2 | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
script: | | |
echo "${{ secrets.DOCKER_COMPOSE }}" | sudo tee ./docker-compose.yml | |
sudo docker ps -a --filter "name=app" --format "{{.ID}}" | xargs -r sudo docker stop | |
sudo docker ps -a --filter "name=app" --format "{{.ID}}" | xargs -r sudo docker rm -f | |
sudo docker stop auth-app | |
sudo docker pull ${{ secrets[format('DOCKER_REPO_{0}', matrix.service)] }}:v2 | |
sudo docker-compose up -d |