diff --git a/.github/workflows/docker-cd.yml b/.github/workflows/docker-cd.yml new file mode 100644 index 0000000..7ff4908 --- /dev/null +++ b/.github/workflows/docker-cd.yml @@ -0,0 +1,36 @@ +name: Docker CD + +on: + push: + branches: + - 'master' + +jobs: + # 서버 이미지를 생성합니다. + Build-Upload-Image: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v2 + with: + # Git revision count를 구하기 위해 지난 모든 커밋 내역을 가져옵니다. + fetch-depth: '0' + + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # 프로젝트의 버전을 이미지 이름에 사용하여 하나 빌드하고, + - name: Build bootBuildImage with version + run: ./gradlew bootBuildImage -PdockerImageName=ghcr.io/inu-appcenter/inuit-server -PdockerUrl=https://ghcr.io -PdockerUsername=${{ secrets.DOCKER_USER }} -PdockerPassword=${{ secrets.DOCKER_TOKEN }} + + # "latest"를 이미지 이름에 사용하여 하나 빌드합니다. + - name: Build bootBuildImage with latest + run: ./gradlew bootBuildImage -PdockerImageName=ghcr.io/inu-appcenter/inuit-server -PdockerUrl=https://ghcr.io -PdockerUsername=${{ secrets.DOCKER_USER }} -PdockerPassword=${{ secrets.DOCKER_TOKEN }} -PdockerTag=latest \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 329696f..0000000 --- a/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -plugins { - id 'org.springframework.boot' version '2.5.0' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' - id 'java' -} - -group = 'pj' -version = '0.0.1-SNAPSHOT' -sourceCompatibility = '11' - -configurations { - compileOnly { - extendsFrom annotationProcessor - } -} - -repositories { - mavenCentral() -} - -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' - implementation 'mysql:mysql-connector-java' - runtimeOnly 'mysql:mysql-connector-java' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-jdbc' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-mail' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.2' - implementation 'io.springfox:springfox-boot-starter:3.0.0' - compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' - annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' -} - -test { - useJUnitPlatform() -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..23a85f2 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,89 @@ +import java.io.ByteArrayOutputStream + +plugins { + id("org.springframework.boot") version "2.5.0" + id("io.spring.dependency-management") version "1.0.11.RELEASE" + id("java") +} + +val major = 0 +val minor = 1 +val patch = getRevisionCount() + +group = "pj" +version = "$major.$minor.$patch" +java.sourceCompatibility = JavaVersion.VERSION_11 + +configurations { + compileOnly { + extendsFrom(configurations.annotationProcessor.get()) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation ("org.springframework.boot:spring-boot-starter-data-jdbc") + implementation ("mysql:mysql-connector-java") + implementation ("org.springframework.boot:spring-boot-starter-data-jpa") + implementation ("org.springframework.boot:spring-boot-starter-jdbc") + implementation ("org.springframework.boot:spring-boot-starter-validation") + implementation ("org.springframework.boot:spring-boot-starter-web") + implementation ("org.springframework.boot:spring-boot-starter-mail") + implementation ("org.springframework.boot:spring-boot-starter-security") + implementation ("io.jsonwebtoken:jjwt:0.2") + implementation ("io.springfox:springfox-boot-starter:3.0.0") + compileOnly ("org.projectlombok:lombok") + runtimeOnly ("com.h2database:h2") + runtimeOnly ("mysql:mysql-connector-java") + annotationProcessor( "org.projectlombok:lombok") + testImplementation ("org.springframework.boot:spring-boot-starter-test") +} + +tasks.withType { + useJUnitPlatform() +} + +/**************************************************************** + * Docker 이미지 빌드를 위한 설정입니다. + ****************************************************************/ + +val dockerUrl: String? by project +val dockerImageName: String? by project +val dockerUsername: String? by project +val dockerPassword: String? by project +val dockerTag: String? by project + +tasks.bootBuildImage { + imageName = "${dockerImageName ?: project.name}:${dockerTag ?: project.version}" + + print("[bootBuildImage] 이미지 이름: $imageName") + + if (dockerUrl != null) { + isPublish = true + docker { + publishRegistry { + url = dockerUrl + username = dockerUsername + password = dockerPassword + } + } + } +} + +/** + * Git 리비전 카운트를 가져옵니다. + * 이 카운트를 버전으로 사용합니다. + */ +fun getRevisionCount(): Int { + val byteOut = ByteArrayOutputStream() + project.exec { + commandLine = "git rev-list --count HEAD".split(" ") + standardOutput = byteOut + } + val output = String(byteOut.toByteArray()) + + return Integer.parseInt(output.trim()) +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 3789fcd..0000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'circles' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..e09e203 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "circles"