Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Nov 21, 2023
22 changes: 21 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: ${{ inputs.image-tag || 'latest' }}
ACTIVE_PROFILE: ${{ inputs.spring-profile || 'local' }}

jobs:
build:
Expand All @@ -26,6 +42,10 @@ jobs:

- name: 이미지 빌드하고 푸쉬하기
id: build-image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "IMAGE_TAG=$IMAGE_TAG, ACTIVE_PROFILE=$ACTIVE_PROFILE" &&
chmod +x ./gradlew &&
./gradlew bootJar
./gradlew jib
50 changes: 50 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
chmod +x ./gradlew &&
./gradlew jib
31 changes: 29 additions & 2 deletions .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
name: 프로덕션 워크플로우
on:
push:
branches: [ 'main' ]
branches: [ 'main', 'feature/OING-7' ]
CChuYong marked this conversation as resolved.
Show resolved Hide resolved
paths:
- 'src/**' # 어드민 API 코드가 변경된 경우
- 'config/**' # Config 모듈 변경
- 'member/**' # Member 모듈 변경
- '.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 }}
32 changes: 32 additions & 0 deletions config/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'com.google.cloud.tools.jib' version '3.4.0'
}

repositories {
Expand All @@ -26,3 +27,34 @@ tasks.named('jar') {
tasks.named('test') {
useJUnitPlatform()
}

jib {
def imageTag = System.getenv("IMAGE_TAG")
def serverPort = "8080"
def activeProfile = System.getenv("ACTIVE_PROFILE")
def dockerUsername = System.getenv("DOCKER_USERNAME")
def dockerPassword = System.getenv("DOCKER_PASSWORD")
from {
image = 'amazoncorretto:17-alpine3.17-jdk'
}
to {
image = 'no5ing/spring-was:latest'
tags = ['latest', imageTag]
auth {
username = dockerUsername ? dockerUsername : ""
password = dockerPassword ? dockerPassword : ""
}
}
container {
jvmFlags = [
'-Dspring.profiles.active=' + activeProfile,
'-Dserver.port=' + serverPort,
'-Xms2G', '-Xmx2G',
'-XX:+UseG1GC',
'-XX:+UseContainerSupport',
'-XX:+DisableExplicitGC',
'-server'
]
ports = [serverPort]
}
}
Empty file.