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

feat: Write github workflows for CI & CD #6

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CD
on:
push:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: temurin

- name: Get CurrentTime
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"

- run: chmod +x gradlew && ./gradlew build

- name: 도컀 이미지 λΉŒλ“œ & ν‘Έμ‹œ by jib
run: |
./gradlew :pic-api:jib -Prelease
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ € 맨날 Dockerfile둜 λΉŒλ“œν–ˆμ—ˆλŠ”λ° λ°°μ›Œκ°‘λ‹ˆλ‹€

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_BEANSTALK_ACCESS_KEY }}
aws_secret_key: ${{ secrets.AWS_BEANSTALK_SECRET_KEY }}
application_name: pic-backend-eb-app
environment_name: pic-backend-eb-env
version_label: pic-deploy-${{steps.current-time.outputs.formattedTime}}
region: ap-northeast-2
deployment_package: ./deploy/Dockerrun.aws.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λΉˆμŠ€ν†‘λ„ λ°°μ›Œκ°λ‘₯

31 changes: 31 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pull request workflow (build check)

on:
pull_request:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: temurin

- name: Get CurrentTime
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"

- name: build test
run: chmod +x gradlew && ./gradlew build
16 changes: 7 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id("org.springframework.boot") version "3.3.0"
id("io.spring.dependency-management") version "1.1.5"
kotlin("jvm") version "1.9.24"
kotlin("plugin.spring") version "1.9.24"
kotlin("plugin.jpa") version "1.9.24"
kotlin("plugin.spring") version "1.9.24" apply false
kotlin("plugin.jpa") version "1.9.24" apply false
id("org.springframework.boot") version "3.3.0" apply false
id("io.spring.dependency-management") version "1.1.5" apply false
id("com.google.cloud.tools.jib") version "3.4.3" apply false
}

java.sourceCompatibility = JavaVersion.VERSION_21
Expand All @@ -21,10 +22,7 @@ subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
apply(plugin = "org.springframework.boot")
apply(plugin = "kotlin")
apply(plugin = "java-library")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "application")

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
Expand All @@ -44,11 +42,11 @@ subprojects {
}
}

tasks.bootJar {
tasks.getByName("bootJar") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 이런 λ©”μ„œλ“œλ‘œλŠ” 처음 λ΄μš” κ³ μƒν•˜μ…¨μŠ΅λ‹ˆλ‹€

enabled = false
}

tasks.jar {
tasks.getByName("jar") {
enabled = true
}
}
12 changes: 12 additions & 0 deletions deploy/Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "gappangzip/pic-api:latest",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
]
}
47 changes: 47 additions & 0 deletions pic-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.google.cloud.tools.jib.gradle.JibExtension

tasks.bootJar {
enabled = true
}
Expand All @@ -6,6 +8,8 @@ tasks.jar {
enabled = false
}

apply(plugin = "com.google.cloud.tools.jib")

val jjwtVersion: String by project.extra

dependencies {
Expand All @@ -29,3 +33,46 @@ dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

configure<JibExtension> {
val registryUsername = System.getenv("DOCKERHUB_USERNAME")
val (activeProfile, containerImageName) = getProfileAndImageName(registryUsername)

from {
image = "eclipse-temurin:21-jre"
}

to {
image = containerImageName
tags = setOf("$version", "latest")
auth {
username = registryUsername
password = System.getenv("DOCKERHUB_PASSWORD")
}
}

container {
// TODO: μ„œλ²„ μŠ€νŽ™μ— 따라 Xmx/Xms, Initial/Min/MaxRAMFraction μ„€μ •
jvmFlags = listOf(
"-server",
"-XX:+UseContainerSupport",
"-XX:+UseStringDeduplication",
"-Dserver.port=8080",
"-Dfile.encoding=UTF-8",
"-Djava.awt.headless=true",
"-Dspring.profiles.active=${activeProfile}"
)
ports = listOf("8080")
environment = mapOf(
"TZ" to "Asia/Seoul"
)
}
}

fun getProfileAndImageName(registryUsername: String?): Array<String> {
val containerImageName = "${registryUsername}/${project.name}"
if (project.hasProperty("release")) {
return arrayOf("release", containerImageName)
}
return arrayOf("dev", "$containerImageName-dev")
}
10 changes: 6 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rootProject.name = "gappangzip-backend"
include("pic-api")
include("pic-common")
include("pic-external")
include("pic-domain")
include(
"pic-api",
"pic-domain",
"pic-common",
"pic-external"
)
Loading