Skip to content

Commit

Permalink
feat: add ci script
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Nov 20, 2023
1 parent ba66e94 commit bd4e244
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
name: 이미지 빌드 & 푸쉬
on:
workflow_call:
inputs:
image-tag:
required: true
type: string
spring-profile:
required: true
type: string
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true

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

jobs:
build:
Expand Down Expand Up @@ -28,4 +44,4 @@ jobs:
id: build-image
run: |
chmod +x ./gradlew &&
./gradlew bootJar
./gradlew jib
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 이미지 빌드 & 푸쉬
on:
workflow_call:
inputs:
image-tag:
required: true
type: string
spring-profile:
required: true
type: string
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true

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

jobs:
build:
runs-on: [ ubuntu-latest ]
name: 이미지 빌드하기

permissions:
id-token: write
contents: read

steps:
- name: GitHub 에서 레포 받아오기
uses: actions/checkout@v3

- name: JDK17 준비하기
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

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

- name: 이미지 빌드하고 푸쉬하기
id: build-image
run: |
chmod +x ./gradlew &&
./gradlew jib
28 changes: 27 additions & 1 deletion .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
name: 프로덕션 워크플로우
on:
push:
branches: [ 'main' ]
branches: [ 'main', 'feature/OING-7' ]
paths:
- 'src/**' # 어드민 API 코드가 변경된 경우
- '.github/workflows/**' # 워크플로우와 관련된 파일이 변경된 경우
- 'build.gradle' # Parent Gradle 모듈 설정이 변경된 경우
- 'settings.gradle' # Parent Gradle 설정이 변경된 경우

env:
SPRING_PROFILE: prod

concurrency:
group: production

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 }}
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
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 }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
2 changes: 1 addition & 1 deletion config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks.named('test') {

jib {
def imageTag = System.getenv("IMAGE_TAG")
def serverPort = System.getenv("SERVER_PORT")
def serverPort = "8080"
def activeProfile = System.getenv("ACTIVE_PROFILE")
def dockerUsername = System.getenv("DOCKER_USERNAME")
def dockerPassword = System.getenv("DOCKER_PASSWORD")
Expand Down

0 comments on commit bd4e244

Please sign in to comment.