-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ATR-611] chore: 스테이징 서버 ci/cd 설정 (#295)
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Deploy to Staging | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
Deploy: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
deployments: write | ||
|
||
steps: | ||
- name: Github Repository 파일 불러오기 | ||
uses: actions/checkout@v4 | ||
|
||
- name: JDK v21 설치 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 21 | ||
|
||
- name: application-dev.yml 파일 만들기 | ||
run: echo '${{ secrets.APPLICATION_DEV_PROPERTIES }}' > ./src/main/resources/application.yml | ||
|
||
- name: application-test.yml 파일 만들기 | ||
run: echo '${{ secrets.APPLICATION_TEST_PROPERTIES }}' > ./src/main/resources/application-test.yml | ||
|
||
- name: credentials.json 파일 만들기 | ||
run: echo '${{ secrets.CREDENTIAL_JSON }}' > ./src/main/resources/credentials.json | ||
|
||
- name: log4j2.xml 파일 만들기 | ||
run: echo '${{ secrets.LOG4J2_XML }}' > ./src/main/resources/log4j2.xml | ||
|
||
- name: 테스트 및 빌드하기 | ||
run: ./gradlew clean build | ||
|
||
- name: Docker hub 로그인 | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{secrets.DOCKERHUB_USERNAME}} | ||
password: ${{secrets.DOCKERHUB_TOKEN}} | ||
|
||
- name: build and release to DockerHub | ||
env: | ||
NAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
REPO: attraction-api-server | ||
run: | | ||
docker build -t $REPO . | ||
docker tag $REPO:latest $NAME/$REPO:latest | ||
docker push $NAME/$REPO:latest | ||
- name: 배포 작업 생성 | ||
uses: chrnorm/deployment-action@v2 | ||
id: deployment | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
environment-url: https://attraction.run | ||
environment: dev | ||
ref: ${{ github.ref }} | ||
|
||
- name: SSH로 EC2에 접속하기 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.DEV_EC2_HOST }} | ||
username: ${{ secrets.DEV_EC2_USERNAME }} | ||
key: ${{ secrets.DEV_EC2_PRIVATE_KEY }} | ||
script_stop: true | ||
script: | | ||
docker stop attraction-api-server || true | ||
docker rm attraction-api-server || true | ||
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/attraction-api-server:latest | ||
# Redis 컨테이너 실행 | ||
docker stop redis-server || true | ||
docker rm redis-server || true | ||
docker run -d --name redis-server -p 6379:6379 redis:latest | ||
# Spring Boot 애플리케이션 컨테이너 실행 | ||
docker run -d --name attraction-api-server --link redis-server:redis -e TZ=Asia/Seoul -p 8080:8080 -v /home/ec2-user/workspace/logs:/logs ${{ steps.ecr-login.outputs.registry }}/attraction-api-server:latest | ||
# filebeat 실행 | ||
docker stop filebeat || true | ||
docker rm filebeat || true | ||
docker run -d --name filebeat -v "$HOME/workspace/logs:/usr/share/filebeat/logs" -v "$HOME/workspace/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml" docker.elastic.co/beats/filebeat:8.14.1 | ||
- name: 슬랙 알림 | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} | ||
if: always() |