Merge pull request #24 from GDSC-Daejin/fix/fixAiApi #1
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: Dev Profile Deploy to GCP Instance | |
on: | |
push: | |
branches: ["develop"] | |
permissions: | |
contents: read | |
env: | |
DOCKER_REPO_NAME: ${{ secrets.DOCKER_REPO_NAME }} | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
SHA: ${{ github.sha }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 기본 체크아웃 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Gradlew 실행 허용 | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
#JDK 세팅 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
# 환경변수 설정 | |
- name: Set up environment variables | |
run: | | |
cd ./src/main/resources | |
touch ./application-dev.properties | |
echo "${{secrets.DEV_SPRING_PROPERTIES}}" > ./application-dev.properties | |
shell: bash | |
# Gradle build (Test 제외) | |
- name: Build with Gradle | |
run: ./gradlew clean build -Pprofile=dev --exclude-task test | |
# Docker 이미지 빌드 | |
- name: Docker Build | |
run: | | |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
docker build --tag $DOCKER_USERNAME/$DOCKER_REPO_NAME:reddy-image-$SHA . | |
docker push $DOCKER_USERNAME/$DOCKER_REPO_NAME:reddy-image-$SHA | |
# GCP 인스턴스에 Docker 이미지 배포 | |
- name: Deploy to GCP | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.GCE_HOST }} | |
username: ${{ secrets.GCE_USERNAME }} | |
key: ${{ secrets.GCE_PRIVATE_KEY }} | |
envs: DOCKER_USERNAME, DOCKER_REPO_NAME, SHA | |
script: | | |
sudo docker ps -aq --filter "name=reddy-dev" | xargs sudo docker stop | xargs sudo docker rm | |
sudo docker image prune -a -f | |
sudo docker pull $DOCKER_USERNAME/$DOCKER_REPO_NAME:reddy-image-$SHA | |
sudo docker run -d -p 8080:8080 --name reddy-dev $DOCKER_USERNAME/$DOCKER_REPO_NAME:reddy-image-$SHA |