Skip to content

Commit

Permalink
Deployment configs
Browse files Browse the repository at this point in the history
### What's done:
* Common gradle task for spring configuration
* Wrapped deployment commands in gradle tasks
  • Loading branch information
petertrr committed Feb 16, 2021
1 parent 1fb2d95 commit 11f85f4
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 30 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import org.cqfn.save.buildutils.configureDetekt
import org.cqfn.save.buildutils.configureDiktat
import org.cqfn.save.buildutils.createDetektTask
import org.cqfn.save.buildutils.createDiktatTask
import org.cqfn.save.buildutils.createStackDeployTask
import org.cqfn.save.buildutils.installGitHooks

plugins {
Expand All @@ -18,6 +19,7 @@ allprojects {
configureDetekt()
}

createStackDeployTask()
createDiktatTask()
createDetektTask()
installGitHooks()
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repositories {
}

dependencies {
implementation("org.springframework.boot:spring-boot-gradle-plugin:2.4.2")
implementation("org.cqfn.diktat:diktat-gradle-plugin:0.4.0")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cqfn.save.buildutils

import org.gradle.api.Project
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage

fun Project.createStackDeployTask() {
tasks.register<Exec>("startLocalDockerRegistry") {
description = "Start local docker registry for spring boot images"
commandLine("docker", "service", "create", "--name", "registry", "--publish", "published=6000,target=5000", "registry:2")
}

tasks.register<Exec>("deployDockerStack") {
dependsOn(subprojects.flatMap { it.tasks.withType<BootBuildImage>() })
doFirst {
copy {
description = "Copy configuration files from repo to actual locations"
from("save-deploy")
into("${System.getProperty("user.home")}/configs")
}
}
description = "Deploy docker stack to docker swarm"
commandLine("docker", "stack", "deploy", "--compose-file", "docker-compose.yaml", "save")
doLast {
exec {
description = "Stop local docker registry"
commandLine("docker", "service", "rm", "registry")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.cqfn.save.buildutils

import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.named
import org.springframework.boot.gradle.plugin.SpringBootPlugin
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage

fun Project.configureSpringBoot() {
apply<SpringBootPlugin>()

dependencies {
add("implementation", "org.springframework.boot:spring-boot-starter-webflux:${Versions.springBoot}")
add("implementation", "org.springframework.boot:spring-boot-starter-actuator:${Versions.springBoot}")
add("implementation", "io.micrometer:micrometer-registry-prometheus:${Versions.micrometer}") // expose prometheus metrics in actuator
add("implementation", "org.springframework.security:spring-security-core:${Versions.springSecurity}")
add("testImplementation", "org.springframework.boot:spring-boot-starter-test:${Versions.springBoot}")
}

tasks.named<BootBuildImage>("bootBuildImage") {
dependsOn("startLocalDockerRegistry")
docker {
publishRegistry {
host = "http://localhost:6000"
}
}
isPublish = true
}
}
11 changes: 1 addition & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
# https://docs.docker.com/engine/swarm/stack-deploy/
# $ ./gradlew build # create executable jars
# $ docker-compose build # build docker images
# $ docker service create --name registry --publish published=6000,target=5000 registry:2 # create a throwaway local registry
# $ docker-compose push # push images to local registry
# $ cp save-deploy/* ~/configs
# $ docker stack deploy --compose-file docker-compose.yaml save
# $ ./gradlew deployDockerStack
version: '3.9'

services:
orchestrator:
# todo: set version from gradle, otherwise will be `latest`
image: 127.0.0.1:6000/save-orchestrator
build: save-orchestrator # location of Dockerfile
ports:
- "5100:5100"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
labels:
- prometheus-job
backend:
# todo: set version from gradle
image: 127.0.0.1:6000/save-backend
build: save-backend
ports:
- "5000:5000"
labels:
Expand Down
4 changes: 0 additions & 4 deletions save-backend/Dockerfile

This file was deleted.

9 changes: 3 additions & 6 deletions save-backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import org.cqfn.save.buildutils.configureJacoco
import org.cqfn.save.buildutils.configureSpringBoot
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.springframework.boot") version Versions.springBoot
}

configureSpringBoot()

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Versions.jdk
Expand All @@ -18,15 +20,10 @@ tasks.withType<Test> {

dependencies {
implementation(project(":save-common"))
implementation("org.springframework.boot:spring-boot-starter-webflux:${Versions.springBoot}")
implementation("org.springframework.boot:spring-boot-starter-actuator:${Versions.springBoot}")
implementation("io.micrometer:micrometer-registry-prometheus:${Versions.micrometer}") // expose prometheus metrics in actuator
implementation("org.springframework.security:spring-security-core:${Versions.springSecurity}")
implementation("org.liquibase:liquibase-core:${Versions.liquibase}")
implementation("org.hibernate:hibernate-core:${Versions.hibernate}")
implementation("org.slf4j:slf4j-api:${Versions.slf4j}")
implementation("ch.qos.logback:logback-core:${Versions.logback}")
testImplementation("org.springframework.boot:spring-boot-starter-test:${Versions.springBoot}")
}

configureJacoco()
4 changes: 0 additions & 4 deletions save-orchestrator/Dockerfile

This file was deleted.

9 changes: 3 additions & 6 deletions save-orchestrator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import org.cqfn.save.buildutils.configureJacoco
import org.cqfn.save.buildutils.configureSpringBoot
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.springframework.boot") version Versions.springBoot
}

configureSpringBoot()

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Versions.jdk
Expand All @@ -18,18 +20,13 @@ tasks.withType<Test> {

dependencies {
implementation(project(":save-common"))
implementation("org.springframework.boot:spring-boot-starter-webflux:${Versions.springBoot}")
implementation("org.springframework.boot:spring-boot-starter-actuator:${Versions.springBoot}")
implementation("io.micrometer:micrometer-registry-prometheus:${Versions.micrometer}") // expose prometheus metrics in actuator
implementation("org.springframework.security:spring-security-core:${Versions.springSecurity}")
implementation("org.liquibase:liquibase-core:${Versions.liquibase}")
implementation("org.hibernate:hibernate-core:${Versions.hibernate}")
implementation("org.slf4j:slf4j-api:${Versions.slf4j}")
implementation("ch.qos.logback:logback-core:${Versions.logback}")
implementation("com.github.docker-java:docker-java-core:${Versions.dockerJavaApi}")
implementation("com.github.docker-java:docker-java-transport-httpclient5:${Versions.dockerJavaApi}")
implementation("org.apache.commons:commons-compress:1.20")
testImplementation("org.springframework.boot:spring-boot-starter-test:${Versions.springBoot}")
}

configureJacoco()

0 comments on commit 11f85f4

Please sign in to comment.