-
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.
chore: nginx 도입에 따른 CI/CD 워크플로우 수정 (#396)
* chore: nginx 컨테이너 세팅 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 빌드 및 배포 잡 통합 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 도커허브 로그인으로 변경 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 메타데이터 액션을 사용하도록 변경 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 배포 스크립트 관련 설정 수정 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: docker-compose 전송 설정 변경 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 이미지 태그 직접 추출하는 스텝 제거 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 상용 워크플로 컴포즈 파일 전송 설정 변경 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * fix: 오타 수정 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * fix: 도커허브 유저네임 오타 수정 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: nginx 리로드 커맨드 추가 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 수동 배포 워크플로 수정 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: default.conf 전송 스텝 추가 Co-Authored-By: 도모 <[email protected]> Co-Authored-By: yb__char <[email protected]> * chore: 테스트 트리거 활성화 * chore: 절대경로로 수정 * chore: ssh-action 버전 변경 * chore: 파일 전송 스텝 임시 비활성화 * chore: ssh debug 활성화 * chore: docker-compose backend image 환경변수 변경 * style: rsync 주석 해제 * chore: rsync version downgrade * chore: docker-compose.yaml에 DOCKERHUB_IMAGE_NAME 환경변수 추가 * chore: rsync version update test * chore: production에도 변경 된 내용 적용 * chore: 트리거 제거 --------- Co-authored-by: 도모 <[email protected]> Co-authored-by: yb__char <[email protected]> Co-authored-by: kdomo <[email protected]>
- Loading branch information
1 parent
fd3649a
commit c98de04
Showing
6 changed files
with
163 additions
and
111 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 |
---|---|---|
|
@@ -4,17 +4,19 @@ on: | |
push: | ||
branches: [ "develop" ] | ||
|
||
env: | ||
DOCKERHUB_USERNAME: tenminutes | ||
DOCKERHUB_IMAGE_NAME: 10mm-server | ||
|
||
jobs: | ||
build: | ||
build-deploy: | ||
runs-on: ubuntu-latest | ||
environment: DEV | ||
strategy: | ||
matrix: | ||
java-version: [ 17 ] | ||
distribution: [ 'temurin' ] | ||
outputs: | ||
# IMAGE_TAG 환경 변수를 다른 Job에서 사용하기 위해 설정 | ||
image-tag: ${{ steps.image-tag.outputs.value }} | ||
|
||
steps: | ||
# 기본 체크아웃 | ||
- name: Checkout | ||
|
@@ -27,11 +29,6 @@ jobs: | |
java-version: ${{ matrix.java-version }} | ||
distribution: ${{ matrix.distribution }} | ||
|
||
# 이미지 태그 설정 | ||
- name: Set up image-tag by GITHUB_SHA | ||
id: image-tag | ||
run: echo "value=$(echo ${GITHUB_SHA::7})" >> $GITHUB_OUTPUT | ||
|
||
# test 돌릴때 레디스 필요 | ||
- name: Start containers | ||
run: docker-compose -f ./docker-compose-test.yaml up -d | ||
|
@@ -50,33 +47,52 @@ jobs: | |
--scan | ||
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | ||
|
||
# NCP Container Registry 로그인 | ||
- name: Login to NCP Container Registry | ||
# Dockerhub 로그인 | ||
- name: Login to Dockerhub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} | ||
username: ${{ secrets.NCP_ACCESS_KEY }} | ||
password: ${{ secrets.NCP_SECRET_KEY }} | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | ||
|
||
# Docker 메타데이터 추출 | ||
- name: Extract Docker metadata | ||
id: metadata | ||
uses: docker/[email protected] | ||
env: | ||
DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} | ||
with: | ||
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }} | ||
tags: | | ||
type=sha,prefix= | ||
# Docker 이미지 빌드 및 푸시 | ||
# Docker 이미지 빌드 및 도커허브로 푸시 | ||
- name: Docker Build and Push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ steps.image-tag.outputs.value }} | ||
tags: ${{ steps.metadata.outputs.tags }} | ||
|
||
# 서버로 docker-compose 파일 전송 | ||
- name: copy source via ssh key | ||
uses: burnett01/rsync-deployments@4.1 | ||
- name: Copy docker-compose file to EC2 | ||
uses: burnett01/rsync-deployments@7.0.1 | ||
with: | ||
switches: -avzr --delete | ||
remote_host: ${{ secrets.NCP_HOST }} | ||
remote_user: ${{ secrets.NCP_USERNAME }} | ||
remote_port: ${{ secrets.NCP_PORT }} | ||
remote_key: ${{ secrets.NCP_PRIVATE_KEY }} | ||
remote_host: ${{ secrets.EC2_HOST }} | ||
remote_user: ${{ secrets.EC2_USERNAME }} | ||
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
path: docker-compose.yaml | ||
remote_path: /home/tenminute/ | ||
remote_path: /home/ec2-user/ | ||
|
||
- name: Copy default.conf to EC2 | ||
uses: burnett01/[email protected] | ||
with: | ||
switches: -avzr --delete | ||
remote_host: ${{ secrets.EC2_HOST }} | ||
remote_user: ${{ secrets.EC2_USERNAME }} | ||
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
path: ./nginx | ||
remote_path: /home/ec2-user/ | ||
|
||
# 슬랙으로 빌드 스캔 결과 전송 | ||
- name: Send to slack | ||
|
@@ -89,26 +105,20 @@ jobs: | |
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: DEV | ||
needs: build | ||
steps: | ||
- name: Deploy to NCP Server | ||
uses: appleboy/ssh-action@master | ||
# EC2로 배포 | ||
- name: Deploy to EC2 Server | ||
uses: appleboy/[email protected] | ||
env: | ||
NCP_CONTAINER_REGISTRY: ${{ secrets.NCP_CONTAINER_REGISTRY }} | ||
NCP_IMAGE_TAG: ${{ needs.build.outputs.image-tag }} | ||
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }} | ||
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }} | ||
with: | ||
host: ${{ secrets.NCP_HOST }} | ||
username: ${{ secrets.NCP_USERNAME }} | ||
key: ${{ secrets.NCP_PRIVATE_KEY }} | ||
port: ${{ secrets.NCP_PORT }} | ||
envs: NCP_CONTAINER_REGISTRY,NCP_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수 | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME # docker-compose.yml 에서 사용할 환경 변수 | ||
debug: true | ||
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:${{ env.NCP_IMAGE_TAG }} | ||
SWAGGER_VERSION=${{ env.NCP_IMAGE_TAG }} | ||
sed -i "s/SWAGGER_VERSION=.*/SWAGGER_VERSION=$SWAGGER_VERSION/" .env | ||
docker compose -f /home/tenminute/docker-compose.yaml up -d | ||
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin | ||
docker compose up -d | ||
docker exec -d nginx nginx -s reload | ||
docker image prune -a -f |
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
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 |
---|---|---|
|
@@ -5,17 +5,19 @@ on: | |
tags: | ||
- v*.*.* | ||
|
||
env: | ||
DOCKERHUB_USERNAME: tenminutes | ||
DOCKERHUB_IMAGE_NAME: 10mm-server | ||
|
||
jobs: | ||
build: | ||
build-deploy: | ||
runs-on: ubuntu-latest | ||
environment: PROD | ||
strategy: | ||
matrix: | ||
java-version: [ 17 ] | ||
distribution: [ 'temurin' ] | ||
outputs: | ||
# IMAGE_TAG 환경 변수를 다른 Job에서 사용하기 위해 설정 | ||
image-tag: ${{ steps.image-tag.outputs.value }} | ||
|
||
steps: | ||
# 기본 체크아웃 | ||
- name: Checkout | ||
|
@@ -28,11 +30,6 @@ jobs: | |
java-version: ${{ matrix.java-version }} | ||
distribution: ${{ matrix.distribution }} | ||
|
||
# 이미지 태그 설정 | ||
- name: Set up image-tag by Releases Tag | ||
id: image-tag | ||
run: echo "value=$(cut -d'v' -f2 <<< ${GITHUB_REF#refs/*/})" >> $GITHUB_OUTPUT | ||
|
||
# test 돌릴때 레디스 필요 | ||
- name: Start containers | ||
run: docker-compose -f ./docker-compose-test.yaml up -d | ||
|
@@ -51,33 +48,62 @@ jobs: | |
--scan | ||
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | ||
|
||
# NCP Container Registry 로그인 | ||
- name: Login to NCP Container Registry | ||
# Dockerhub 로그인 | ||
- name: Login to Dockerhub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} | ||
username: ${{ secrets.NCP_ACCESS_KEY }} | ||
password: ${{ secrets.NCP_SECRET_KEY }} | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | ||
|
||
# Docker 메타데이터 추출 | ||
- name: Extract Docker metadata | ||
id: metadata | ||
uses: docker/[email protected] | ||
env: | ||
DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} | ||
with: | ||
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }} | ||
tags: | | ||
type=semver,pattern={{version}} | ||
flavor: | | ||
latest=false | ||
# 멀티 아키텍처 지원을 위한 QEMU 설정 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
# Docker 이미지 빌드 및 푸시 | ||
# 도커 확장 빌드를 위한 Buildx 설정 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
# Docker 이미지 빌드 및 도커허브로 푸시 | ||
- name: Docker Build and Push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server-spring:${{ steps.image-tag.outputs.value }} | ||
tags: ${{ steps.metadata.outputs.tags }} | ||
|
||
# 서버로 docker-compose 파일 전송 | ||
- name: copy source via ssh key | ||
uses: burnett01/rsync-deployments@4.1 | ||
- name: Copy docker-compose file to EC2 | ||
uses: burnett01/rsync-deployments@7.0.1 | ||
with: | ||
switches: -avzr --delete | ||
remote_host: ${{ secrets.NCP_HOST }} | ||
remote_user: ${{ secrets.NCP_USERNAME }} | ||
remote_port: ${{ secrets.NCP_PORT }} | ||
remote_key: ${{ secrets.NCP_PRIVATE_KEY }} | ||
remote_host: ${{ secrets.EC2_HOST }} | ||
remote_user: ${{ secrets.EC2_USERNAME }} | ||
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
path: docker-compose.yaml | ||
remote_path: /home/tenminute/ | ||
remote_path: / | ||
|
||
- name: Copy default.conf to EC2 | ||
uses: burnett01/[email protected] | ||
with: | ||
switches: -avzr --delete | ||
remote_host: ${{ secrets.EC2_HOST }} | ||
remote_user: ${{ secrets.EC2_USERNAME }} | ||
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
path: ./nginx | ||
remote_path: / | ||
|
||
# 슬랙으로 빌드 스캔 결과 전송 | ||
- name: Send to slack | ||
|
@@ -90,26 +116,18 @@ jobs: | |
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: PROD | ||
needs: build | ||
steps: | ||
- name: Deploy to NCP Server | ||
# EC2로 배포 | ||
- name: Deploy to EC2 Server | ||
uses: appleboy/ssh-action@master | ||
env: | ||
NCP_CONTAINER_REGISTRY: ${{ secrets.NCP_CONTAINER_REGISTRY }} | ||
NCP_IMAGE_TAG: ${{ needs.build.outputs.image-tag }} | ||
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }} | ||
with: | ||
host: ${{ secrets.NCP_HOST }} | ||
username: ${{ secrets.NCP_USERNAME }} | ||
key: ${{ secrets.NCP_PRIVATE_KEY }} | ||
port: ${{ secrets.NCP_PORT }} | ||
envs: NCP_CONTAINER_REGISTRY,NCP_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수 | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME # 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:${{ env.NCP_IMAGE_TAG }} | ||
SWAGGER_VERSION=${{ env.NCP_IMAGE_TAG }} | ||
sed -i "s/SWAGGER_VERSION=.*/SWAGGER_VERSION=$SWAGGER_VERSION/" .env | ||
docker compose -f /home/tenminute/docker-compose.yaml up -d | ||
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin | ||
docker compose up -d | ||
docker exec -d nginx nginx -s reload | ||
docker image prune -a -f |
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
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
Oops, something went wrong.