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

Chore : OCI Migration #45

Merged
merged 11 commits into from
Oct 13, 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
44 changes: 0 additions & 44 deletions .github/actions/ci-workflow.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- main
pull_request:
types: [ opened, synchronize, reopened ]

jobs:
build:
name: Build and analyze
Expand Down Expand Up @@ -33,7 +34,6 @@ jobs:

- name: touch application.yml
run: |
mkdir ./src/main/resources
touch ./src/main/resources/application.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" > ./src/main/resources/application.yml
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

### Credentials ###
.env
src/main/resources/application.yaml

### STS ###
.apt_generated
.classpath
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Start with a base image containing Java runtime
FROM openjdk:17-jdk-alpine
# Use a multi-architecture base image that supports ARM64
FROM openjdk:17

# Set the working directory in the container
WORKDIR /app
Expand All @@ -11,4 +11,4 @@ COPY build/libs/platform-core-*.jar app.jar
EXPOSE 8080

# Command to run the executable jar file
ENTRYPOINT ["java", "-jar", "app.jar"]
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "app.jar"]
129 changes: 65 additions & 64 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import io.swagger.v3.oas.models.servers.Server
import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI
import org.springframework.boot.gradle.tasks.bundling.BootJar

buildscript {
ext {
restdocsApiSpecVersion = '0.19.2'
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id "org.sonarqube" version "4.4.1.3373"
id 'org.sonarqube' version '4.4.1.3373'
id 'com.epages.restdocs-api-spec' version '0.19.2'
id 'org.hidetake.swagger.generator' version '2.19.2'
id 'jacoco'
Expand All @@ -27,8 +19,8 @@ java {
}
}

jar {
enabled = false
repositories {
mavenCentral()
}

configurations {
Expand All @@ -37,110 +29,119 @@ configurations {
}
}

repositories {
mavenCentral()
}

dependencies {
// Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security:2.3.3.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.0")

// AWS
implementation platform('io.awspring.cloud:spring-cloud-aws-dependencies:3.0.0')
implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3'

// Database
runtimeOnly 'com.h2database:h2:2.2.224'
implementation 'mysql:mysql-connector-java:8.0.32'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.1'

// Lombok
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

runtimeOnly 'com.h2database:h2:2.2.224'
// implementation 'mysql:mysql-connector-java:8.0.32'
implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.1")


// test dependencies
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'com.epages:restdocs-api-spec:0.19.2'
testImplementation 'com.epages:restdocs-api-spec-mockmvc:0.19.2'
testImplementation "com.epages:restdocs-api-spec:0.19.2"
testImplementation "com.epages:restdocs-api-spec-mockmvc:0.19.2"
testImplementation 'org.springframework.security:spring-security-test:6.3.1'

// Swagger UI
swaggerUI 'org.webjars:swagger-ui:5.0.0'

// Dev Tools
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}

openapi3 {
servers = [
{ url = 'http://localhost:8080' },
{ url = 'https://stage.gdsc-konkuk.dev' },
{ url = 'https://gdsc-konkuk.dev' },
] as List<? extends Closure<Server>>
title = 'Post Service API'
description = 'Post Service API description'
version = '1.0.0'
format = 'yaml'
jar {
enabled = false
}

swaggerSources {
sample {
setInputFile(file("${project.buildDir}/api-spec/openapi3.yaml"))
bootJar {
dependsOn 'copySwaggerUI'
doFirst {
if (project.hasProperty('excludeSecrets') && project.property('excludeSecrets') == 'true') {
exclude 'application.yaml'
println 'Excluding application.yaml from the build'
}
}
}

tasks.named('test') {
resolveMainClassName {
dependsOn 'copySwaggerUI'
}

test {
useJUnitPlatform()
finalizedBy 'jacocoTestReport'
}

jacoco {
toolVersion = "0.8.7"
toolVersion = '0.8.7'
}

jacocoTestReport {
dependsOn 'copySwaggerUI'

reports {
html.required = true
xml.required = true
}
}

tasks.withType(GenerateSwaggerUI).configureEach {
dependsOn 'openapi3'
sonar {
properties {
property 'sonar.projectKey', 'gdsc-konkuk_platform-core'
property 'sonar.organization', 'gdsc-konkuk'
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.coverage.jacoco.xmlReportPaths', layout.buildDirectory.file("reports/jacoco/test/jacocoTestReport.xml")
}
}

tasks.register('copySwaggerUI', Copy) {
dependsOn 'generateSwaggerUISample'

def generateSwaggerUISampleTask = tasks.named('generateSwaggerUISample', GenerateSwaggerUI).get()

from("${generateSwaggerUISampleTask.outputDir}")
into("${project.buildDir}/resources/main/static/docs")
openapi3 {
servers = [
{ url = 'https://gdsc-konkuk.dev' },
{ url = 'https://api.gdsc-konkuk.dev' },
{ url = 'https://stage.gdsc-konkuk.dev' },
{ url = 'http://localhost:8080' },
]
title = 'Post Service API'
description = 'Post Service API description'
version = '1.0.0'
format = 'yaml'
}

tasks.resolveMainClassName {
dependsOn 'copySwaggerUI'
postman {
baseUrl = 'http://localhost:8080'
}

tasks.withType(BootJar).configureEach {
dependsOn 'copySwaggerUI'
swaggerSources {
sample {
inputFile = file(layout.buildDirectory.file("api-spec/openapi3.yaml"))
}
}

tasks.named('jar').configure {
dependsOn 'copySwaggerUI'
tasks.withType(GenerateSwaggerUI).configureEach {
dependsOn 'openapi3'
}

// sonarqube plugins
sonar {
properties {
property "sonar.projectKey", "gdsc-konkuk_platform-core"
property "sonar.organization", "gdsc-konkuk"
property "sonar.host.url", "https://sonarcloud.io"
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/test/jacocoTestReport.xml'
}
tasks.register('copySwaggerUI', Copy) {
dependsOn 'generateSwaggerUISample'
from(tasks.named('generateSwaggerUISample', GenerateSwaggerUI).map { it.outputDir })
into(layout.buildDirectory.dir("resources/main/static/docs"))
}
9 changes: 3 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash

# 프로젝트 클린 및 빌드
./gradlew clean bootJar
./gradlew clean bootJar -PexcludeSecrets=true

# Docker 이미지 빌드
docker build -t ekgns33/gdsc-spring:latest .

# Docker 이미지 푸시
docker push ekgns33/gdsc-spring:latest
# Docker 이미지 빌드 & 푸시
docker buildx build --platform linux/amd64,linux/arm64 -t ekgns33/gdsc-spring:latest . --push

# 완료 메시지
echo "Docker image pushed to ekgns33/gdsc-spring:latest successfully."
Loading