diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml new file mode 100644 index 0000000..b58d6d6 --- /dev/null +++ b/.github/workflows/deploy-prod.yaml @@ -0,0 +1,62 @@ +name: deploy on prod server + +on: + push: + branches: [test/main-cd] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - name: 체크아웃 + uses: actions/checkout@v4 + with: + submodules: true + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + + - name: 서브모듈 업데이트 + run: | + git submodule update --remote + + - name: JDK 11 설치 + uses: actions/setup-java@v4 + with: + distribution: 'corretto' + java-version: '11' + cache: 'gradle' + + - name: Gradle에 실행 권한 부여 + run: chmod +x gradlew + + - name: 빌드 + run: ./gradlew build -x test + + - name: DockerHub 로그인 + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker 이미지 빌드 & DockerHub에 Push + uses: docker/build-push-action@v6 + with: + context: ./docker + file: Dockerfile-prod + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:prod + + - name: EC2 서버에 배포 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PROD_SERVER_HOST }} + username: ${{ secrets.PROD_SERVER_USERNAME }} + key: ${{ secrets.PROD_SERVER_PEM_KEY }} + envs: GITHUB_SHA + script: | + sudo docker stop $(sudo docker ps -a -q) + sudo docker rm $(sudo docker ps -a -q) + sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod + sudo docker run -d -p 8080:8080 --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod + sudo docker image prune -f diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy-stg.yaml similarity index 95% rename from .github/workflows/deploy.yaml rename to .github/workflows/deploy-stg.yaml index c921b63..1d28cd2 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy-stg.yaml @@ -1,4 +1,4 @@ -name: deploy +name: deploy on stage server on: push: @@ -42,7 +42,8 @@ jobs: - name: Docker 이미지 빌드 & DockerHub에 Push uses: docker/build-push-action@v6 with: - context: . + context: ./docker + file: Dockerfile-stg push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:latest diff --git a/docker/Dockerfile-prod b/docker/Dockerfile-prod new file mode 100644 index 0000000..e70f220 --- /dev/null +++ b/docker/Dockerfile-prod @@ -0,0 +1,4 @@ +FROM amazoncorretto:11-alpine-jdk +EXPOSE 8080 +COPY ./build/libs/Qtudy-server-0.0.1-SNAPSHOT.jar /app.jar +CMD ["java", "-jar", "app.jar", "--spring.profiles.active=deploy"] diff --git a/Dockerfile b/docker/Dockerfile-stg similarity index 100% rename from Dockerfile rename to docker/Dockerfile-stg