Skip to content

Commit

Permalink
[OING-16] chore: 프로젝트 CD 파이프라인 추가 (#4)
Browse files Browse the repository at this point in the history
* docs: create github pr template

* feat: add jib to build.gradle

* feat: add ci script

* chore: 환경변수 출력 코드 추가

* fix: input 경로 변경

* fix: fix nullable issue

* fix: move tags to to closure

* chore: add production manifest

* chore: add invoke rule

* chore: pass docker credentials to build

* chore: add docker credentials  2

* feat: ci 테스트

* feat: add deploy script

* chore: add image-name variable

* chore: fix typo

* chore: change stage name

* chore: passphrase to password

* chore: fix image name

* chore: remove test branch

* chore: add development stage

* chore: remove test stage

* debug: remove debug code

* �[OING-7] chore: CI 파이프라인 추가 (#3)

* docs: create github pr template

* feat: add jib to build.gradle

* feat: add ci script

* chore: 환경변수 출력 코드 추가

* fix: input 경로 변경

* fix: fix nullable issue

* fix: move tags to to closure

* chore: add production manifest

* chore: add invoke rule

* chore: pass docker credentials to build

* chore: add docker credentials  2

* feat: add jib to build.gradle

* feat: add ci script

* fix: fix nullable issue

* fix: move tags to to closure

* feat: ci 테스트

* feat: add deploy script

* chore: add image-name variable

* chore: fix typo

* chore: change stage name

* chore: passphrase to password

* chore: fix image name

* chore: remove test branch

* chore: add development stage

* chore: remove test stage

* debug: remove debug code
  • Loading branch information
CChuYong authored Nov 21, 2023
1 parent c0f8658 commit 718bd4e
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 32 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ name: 이미지 빌드 & 푸쉬
on:
workflow_call:
inputs:
image-name:
required: true
type: string
image-tag:
required: true
type: string
required: true
type: string
spring-profile:
required: true
type: string
required: true
type: string
secrets:
DOCKER_USERNAME:
required: true
Expand All @@ -17,6 +20,7 @@ on:
env:
IMAGE_TAG: ${{ inputs.image-tag || 'latest' }}
ACTIVE_PROFILE: ${{ inputs.spring-profile || 'local' }}
IMAGE_NAME: ${{ inputs.image-name }}

jobs:
build:
Expand Down Expand Up @@ -46,6 +50,6 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "IMAGE_TAG=$IMAGE_TAG, ACTIVE_PROFILE=$ACTIVE_PROFILE" &&
echo "IMAGE_TAG=$IMAGE_TAG, ACTIVE_PROFILE=$ACTIVE_PROFILE, IMAGE_NAME=$IMAGE_NAME" &&
chmod +x ./gradlew &&
./gradlew jib
57 changes: 33 additions & 24 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
name: 이미지 빌드 & 푸쉬
name: 서비스 배포
on:
workflow_call:
secrets:
REMOTE_SSH_HOST:
required: true
REMOTE_SSH_USERNAME:
required: true
REMOTE_SSH_KEY:
required: true
REMOTE_SSH_PASSPHRASE:
required: true
REMOTE_SSH_PORT:
required: true
inputs:
environment:
required: true
type: string
image-tag:
required: true
type: string
spring-profile:
required: true
type: string
secrets:
DOCKER_USERNAME:
image-name:
required: true
DOCKER_PASSWORD:
type: string
service-name:
required: true
type: string

env:
IMAGE_TAG: ${{ github.event.inputs.image-tag || 'latest' }}
ACTIVE_PROFILE: ${{ github.event.inputs.spring-profile || 'local' }}
IMAGE_TAG: ${{ inputs.image-tag || 'latest' }}
ACTIVE_PROFILE: ${{ inputs.spring-profile || 'local' }}

jobs:
build:
deploy:
runs-on: [ ubuntu-latest ]
name: 이미지 빌드하기
name: 서비스 배포하기
environment: ${{ inputs.environment }}

permissions:
id-token: write
Expand All @@ -31,20 +47,13 @@ jobs:
- name: GitHub 에서 레포 받아오기
uses: actions/checkout@v3

- name: JDK17 준비하기
uses: actions/setup-java@v3
- name: 배포 스크립트 실행
uses: appleboy/ssh-action@master
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle 애드온 준비하기
uses: gradle/gradle-build-action@v2

- name: 이미지 빌드하고 푸쉬하기
id: build-image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
chmod +x ./gradlew &&
./gradlew jib
host: ${{ secrets.REMOTE_SSH_HOST }}
username: ${{ secrets.REMOTE_SSH_USERNAME }}
key: ${{ secrets.REMOTE_SSH_KEY }}
password: ${{ secrets.REMOTE_SSH_PASSPHRASE }}
port: ${{ secrets.REMOTE_SSH_PORT }}
script: |
docker service update --image ${{ inputs.image-name }}:${{ inputs.image-tag }} ${{ inputs.service-name }}
79 changes: 79 additions & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: 데브 워크플로우
on:
push:
branches: [ 'dev' ]
paths:
- 'config/**' # Config 모듈 변경
- 'member/**' # Member 모듈 변뚶
- '.github/workflows/**' # 워크플로우와 관련된 파일이 변경된 경우
- 'build.gradle' # Parent Gradle 모듈 설정이 변경된 경우
- 'settings.gradle' # Parent Gradle 설정이 변경된 경우

env:
SPRING_PROFILE: dev
ENVIRONMENT: development
IMAGE_NAME: no5ing/spring-was-dev
SERVICE_NAME: be-dev-was

concurrency:
group: development

jobs:
prepare-variables:
name: 환경변수 준비하기
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.setup-env.outputs.image-tag }}
spring-profile: ${{ steps.setup-env.outputs.spring-profile }}
environment: ${{ steps.setup-env.outputs.environment }}
image-name: ${{ steps.setup-env.outputs.image-name }}
service-name: ${{ steps.setup-env.outputs.service-name }}
steps:
- name: GitHub 에서 레포 받아오기
uses: actions/checkout@v3

- name: 환경변수 출력하기
id: setup-env
run: |
echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "spring-profile=$SPRING_PROFILE" >> $GITHUB_OUTPUT
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "service-name=$SERVICE_NAME" >> $GITHUB_OUTPUT
call-build-workflow:
if: github.event_name == 'push'
needs: [ prepare-variables ]
name: 이미지 빌드
uses: ./.github/workflows/build.yaml
permissions:
id-token: write
contents: read
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
image-name: ${{ needs.prepare-variables.outputs.image-name }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

call-deploy-workflow:
if: github.event_name == 'push'
needs: [ prepare-variables, call-build-workflow ]
name: 서비스 배포
uses: ./.github/workflows/deploy.yaml
permissions:
id-token: write
contents: read
secrets:
REMOTE_SSH_HOST: ${{ secrets.REMOTE_SSH_HOST }}
REMOTE_SSH_USERNAME: ${{ secrets.REMOTE_SSH_USERNAME }}
REMOTE_SSH_KEY: ${{ secrets.REMOTE_SSH_KEY }}
REMOTE_SSH_PASSPHRASE: ${{ secrets.REMOTE_SSH_PASSPHRASE }}
REMOTE_SSH_PORT: ${{ secrets.REMOTE_SSH_PORT }}
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
environment: ${{ needs.prepare-variables.outputs.environment }}
image-name: ${{ needs.prepare-variables.outputs.image-name }}
service-name: ${{ needs.prepare-variables.outputs.service-name }}
35 changes: 33 additions & 2 deletions .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: 프로덕션 워크플로우
on:
push:
branches: [ 'main', 'feature/OING-7' ]
branches: [ 'main' ]
paths:
- 'config/**' # Config 모듈 변경
- 'member/**' # Member 모듈 변경
- 'member/**' # Member 모듈 변뚶
- '.github/workflows/**' # 워크플로우와 관련된 파일이 변경된 경우
- 'build.gradle' # Parent Gradle 모듈 설정이 변경된 경우
- 'settings.gradle' # Parent Gradle 설정이 변경된 경우

env:
SPRING_PROFILE: prod
ENVIRONMENT: production
IMAGE_NAME: no5ing/spring-was
SERVICE_NAME: be-prod-was

concurrency:
group: production
Expand All @@ -22,6 +25,9 @@ jobs:
outputs:
image-tag: ${{ steps.setup-env.outputs.image-tag }}
spring-profile: ${{ steps.setup-env.outputs.spring-profile }}
environment: ${{ steps.setup-env.outputs.environment }}
image-name: ${{ steps.setup-env.outputs.image-name }}
service-name: ${{ steps.setup-env.outputs.service-name }}
steps:
- name: GitHub 에서 레포 받아오기
uses: actions/checkout@v3
Expand All @@ -31,6 +37,9 @@ jobs:
run: |
echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "spring-profile=$SPRING_PROFILE" >> $GITHUB_OUTPUT
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "service-name=$SERVICE_NAME" >> $GITHUB_OUTPUT
call-build-workflow:
if: github.event_name == 'push'
Expand All @@ -43,6 +52,28 @@ jobs:
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
image-name: ${{ needs.prepare-variables.outputs.image-name }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

call-deploy-workflow:
if: github.event_name == 'push'
needs: [ prepare-variables, call-build-workflow ]
name: 서비스 배포
uses: ./.github/workflows/deploy.yaml
permissions:
id-token: write
contents: read
secrets:
REMOTE_SSH_HOST: ${{ secrets.REMOTE_SSH_HOST }}
REMOTE_SSH_USERNAME: ${{ secrets.REMOTE_SSH_USERNAME }}
REMOTE_SSH_KEY: ${{ secrets.REMOTE_SSH_KEY }}
REMOTE_SSH_PASSPHRASE: ${{ secrets.REMOTE_SSH_PASSPHRASE }}
REMOTE_SSH_PORT: ${{ secrets.REMOTE_SSH_PORT }}
with:
image-tag: ${{ needs.prepare-variables.outputs.image-tag }}
spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }}
environment: ${{ needs.prepare-variables.outputs.environment }}
image-name: ${{ needs.prepare-variables.outputs.image-name }}
service-name: ${{ needs.prepare-variables.outputs.service-name }}
3 changes: 2 additions & 1 deletion config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ jib {
def activeProfile = System.getenv("ACTIVE_PROFILE")
def dockerUsername = System.getenv("DOCKER_USERNAME")
def dockerPassword = System.getenv("DOCKER_PASSWORD")
def imageName = System.getenv("IMAGE_NAME")
from {
image = 'amazoncorretto:17-alpine3.17-jdk'
}
to {
image = 'no5ing/spring-was:latest'
image = imageName + ':latest'
tags = ['latest', imageTag]
auth {
username = dockerUsername ? dockerUsername : ""
Expand Down

0 comments on commit 718bd4e

Please sign in to comment.