Skip to content

Commit

Permalink
chore: docker compose 적용 (#31)
Browse files Browse the repository at this point in the history
* chore: 워크플로 테스트 트리거 추가

* chore: 서버로 컴포즈 파일을 전송하는 스텝 추가

* chore: 빌드 시 자바 이미지 eclipse-temurin으로 변경

* chore: 컴포즈 파일 작성

* chore: 컴포즈 파일에 사용할 환경변수 설정

* chore: 시크릿을 사용하도록 변경

* fix: 권한 문제 수정

* chore: 도커 컴포즈를 실행하도록 변경

* fix: scp action의 버전을 고정하도록 변경

* fix: 오타 수정

* fix: 유저네임 변경

* fix: 쉘에서 환경변수 전달하도록 수정

* fix: 사용할 환경변수 지정

* chore: 도커 미사용 리소스 삭제 명령어 추가

* fix: 이미지만 삭제하도록 수정

* fix: 환경변수 수정

* chore: 호스트 모드 사용 시 포트 바인딩 옵션 제거

* chore: 컴포즈가 전역 컨텍스트의 환경변수를 직접 참조하도록 수정 테스트

* fix: 주석 수정

* Revert "fix: 주석 수정"

This reverts commit 0e8f426.

* Revert "chore: 컴포즈가 전역 컨텍스트의 환경변수를 직접 참조하도록 수정 테스트"

This reverts commit b910404.

* docs: 주석 추가

* chore: 주석 처리한 명령어 제거

* chore: 워크플로 테스트 트리거 롤백

* chore: 배포 전용 워크플로에 변경사항 적용
  • Loading branch information
uwoobeat authored and kdomo committed Dec 1, 2023
1 parent c222367 commit 6b5e7fc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/develop_build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
16 changes: 9 additions & 7 deletions .github/workflows/develop_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6b5e7fc

Please sign in to comment.