diff --git a/.github/workflows/develop_build_deploy.yml b/.github/workflows/develop_build_deploy.yml index fbba204c6..12ca5b109 100644 --- a/.github/workflows/develop_build_deploy.yml +++ b/.github/workflows/develop_build_deploy.yml @@ -61,20 +61,35 @@ jobs: push: true tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ steps.github-sha-short.outputs.sha }} + # 서버로 docker-compose 파일 전송 + - name: Copy docker-compose.yml to NCP Server + uses: appleboy/scp-action@v0.1.4 + with: + host: ${{ secrets.NCP_HOST }} + username: tenminute + key: ${{ secrets.NCP_PRIVATE_KEY }} + port: ${{ secrets.NCP_PORT }} + source: docker-compose.yaml + target: /home/tenminute/ + deploy: runs-on: ubuntu-latest environment: DEV needs: build steps: - - name: Login to NCP Server + - name: Deploy to NCP Server uses: appleboy/ssh-action@master + env: + NCP_CONTAINER_REGISTRY: ${{ secrets.NCP_CONTAINER_REGISTRY }} + NCP_IMAGE_TAG: ${{ needs.build.outputs.sha }} with: host: ${{ secrets.NCP_HOST }} username: tenminute key: ${{ secrets.NCP_PRIVATE_KEY }} port: ${{ secrets.NCP_PORT }} + envs: NCP_CONTAINER_REGISTRY,NCP_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수 script: | echo "${{ secrets.NCP_SECRET_KEY }}" | docker login -u "${{ secrets.NCP_ACCESS_KEY }}" --password-stdin "${{ secrets.NCP_CONTAINER_REGISTRY }}" docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ needs.build.outputs.sha }} - docker stop server-spring && docker rm server-spring - docker run -d --name server-spring -p 8080:8080 -d ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ needs.build.outputs.sha }} + docker compose -f /home/tenminute/docker-compose.yaml up -d + docker image prune -a -f diff --git a/.github/workflows/develop_deploy.yml b/.github/workflows/develop_deploy.yml index cec05e438..8d1932e9b 100644 --- a/.github/workflows/develop_deploy.yml +++ b/.github/workflows/develop_deploy.yml @@ -11,19 +11,21 @@ jobs: deploy: runs-on: ubuntu-latest environment: DEV + needs: build steps: - - name: checkout - uses: actions/checkout@master - - - name: Login to NCP Server + - name: Deploy to NCP Server uses: appleboy/ssh-action@master + env: + NCP_CONTAINER_REGISTRY: ${{ secrets.NCP_CONTAINER_REGISTRY }} + NCP_IMAGE_TAG: ${{ needs.build.outputs.sha }} with: host: ${{ secrets.NCP_HOST }} username: tenminute key: ${{ secrets.NCP_PRIVATE_KEY }} port: ${{ secrets.NCP_PORT }} + envs: NCP_CONTAINER_REGISTRY,NCP_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수 script: | echo "${{ secrets.NCP_SECRET_KEY }}" | docker login -u "${{ secrets.NCP_ACCESS_KEY }}" --password-stdin "${{ secrets.NCP_CONTAINER_REGISTRY }}" - docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ github.event.inputs.commit_hash }} - docker stop server-spring && docker rm server-spring - docker run -d --name server-spring -p 8080:8080 -d ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ github.event.inputs.commit_hash }} + docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ needs.build.outputs.sha }} + docker compose -f /home/tenminute/docker-compose.yaml up -d + docker image prune -a -f diff --git a/Dockerfile b/Dockerfile index 0492f4f83..b54d10e7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:17 +FROM eclipse-temurin:17 ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..1695a3e31 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,8 @@ +version: "3.8" + +services: + backend: + image: ${NCP_CONTAINER_REGISTRY}/server-spring:${NCP_IMAGE_TAG} + container_name: server-spring + restart: always + network_mode: host