Skip to content

Instantly share code, notes, and snippets.

@fragaLY
Last active June 29, 2021 13:06
Show Gist options
  • Save fragaLY/9bfad71352d9315c65ea5d4e07e275f5 to your computer and use it in GitHub Desktop.
Save fragaLY/9bfad71352d9315c65ea5d4e07e275f5 to your computer and use it in GitHub Desktop.
Setting up Jib using build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
plugins {
application
id("org.springframework.boot") version "2.5.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.20"
kotlin("plugin.spring") version "1.5.20"
id("com.google.cloud.tools.jib") version "3.1.1"
}
springBoot {
buildInfo()
}
group = "by.vk"
version = "0.0.1"
java.sourceCompatibility = JavaVersion.VERSION_11
application {
mainClass.set("com.api.gateway.demo.DemoApplicationKt")
applicationName = "kafka-producer"
}
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2020.0.3"
configurations.all {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
implementation("org.springframework.cloud:spring-cloud-config-client")
implementation("org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j")
implementation("io.github.resilience4j:resilience4j-spring-boot2:1.7.0")
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation("ch.qos.logback.contrib:logback-json-classic:0.1.5")
implementation("ch.qos.logback.contrib:logback-jackson:0.1.5")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
object DockerProps {
const val BASE_IMAGE = "gcr.io/distroless/java:11"
const val APP_PORT = "8082"
const val DEBUG_PORT = "5082"
const val JMX_PORT = "38082"
}
object JVMProps {
const val XMX = "256m"
const val XMS = "64m"
const val MAX_METASPACE_SIZE = "64m"
const val MAX_DIRECT_MEMORY_SIZE = "128m"
const val HEAPDUMP_PATH = "/opt/tmp/heapdump.bin"
}
jib {
from {
image = DockerProps.BASE_IMAGE
}
container {
jvmFlags = parseSpaceSeparatedArgs("-noverify -XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=50.0 -XX:+OptimizeStringConcat -XX:+UseStringDeduplication -XX:+ExitOnOutOfMemoryError -XX:+AlwaysActAsServerClassMachine -Xlog:gc -Xmx${JVMProps.XMX} -Xms${JVMProps.XMS} -XX:MaxMetaspaceSize=${JVMProps.MAX_METASPACE_SIZE} -XX:MaxDirectMemorySize=${JVMProps.MAX_DIRECT_MEMORY_SIZE} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${JVMProps.HEAPDUMP_PATH} -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${DockerProps.JMX_PORT} -Dcom.sun.management.jmxremote.rmi.port=${DockerProps.JMX_PORT} -Dspring.profiles.active=prod")
ports = listOf(DockerProps.APP_PORT, DockerProps.DEBUG_PORT, DockerProps.JMX_PORT)
labels.set(mapOf("maintainer" to "Vadzim Kavalkou <[email protected]>",
"app-name" to application.applicationName,
"service-version" to version.toString()))
creationTime = "USE_CURRENT_TIMESTAMP"
}
}
name: ci/cd
on:
push:
branches:
- master
- develop
- 'feature/**'
jobs:
producer:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: kafka-producer
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: ${{ secrets.JAVA_VERSION }}
distribution: 'adopt'
architecture: x64
- name: Scan current project
id: scan
uses: anchore/scan-action@v2
with:
path: "./kafka-producer"
fail-build: true
acs-report-enable: true
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: GRADLE PREPARATION
run: chmod +x gradlew
- name: PRODUCER COMPILATION
run: ./gradlew compileKotlin -x compileJava --parallel
- name: PRODUCER TESTS
run: ./gradlew test -x compileTestJava --parallel
- name: PRODUCER BUILD
run: ./gradlew build -x test -x compileJava --parallel
- name: PRODUCER DOCKER DELIVERY
if: github.ref == 'refs/heads/master'
run: ./gradlew jib -Djib.to.image=${{ secrets.DOCKER_HUB_REGISTRY }}/${{ secrets.DOCKER_HUB_USER }}/producer:latest -Djib.to.auth.username=${{ secrets.DOCKER_HUB_USER }} -Djib.to.auth.password=${{ secrets.DOCKER_HUB_PASSWORD }}
consumer:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: kafka-consumer
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: ${{ secrets.JAVA_VERSION }}
distribution: 'adopt'
architecture: x64
- name: Scan current project
id: scan
uses: anchore/scan-action@v2
with:
path: "./kafka-consumer"
fail-build: true
acs-report-enable: true
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: GRADLE PREPARATION
run: chmod +x gradlew
- name: CONSUMER COMPILATION
run: ./gradlew compileKotlin -x compileJava --parallel
- name: CONSUMER TESTS
run: ./gradlew test -x compileTestJava --parallel
- name: CONSUMER BUILD
run: ./gradlew build -x test -x compileJava --parallel
- name: CONSUMER DOCKER DELIVERY
if: github.ref == 'refs/heads/master'
run: ./gradlew jib -Djib.to.image=${{ secrets.DOCKER_HUB_REGISTRY }}/${{ secrets.DOCKER_HUB_USER }}/consumer:latest -Djib.to.auth.username=${{ secrets.DOCKER_HUB_USER }} -Djib.to.auth.password=${{ secrets.DOCKER_HUB_PASSWORD }}
gateway:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: gateway
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: ${{ secrets.JAVA_VERSION }}
distribution: 'adopt'
architecture: x64
- name: Scan current project
id: scan
uses: anchore/scan-action@v2
with:
path: "./gateway"
fail-build: true
acs-report-enable: true
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: GRADLE PREPARATION
run: chmod +x gradlew
- name: GATEWAY COMPILATION
run: ./gradlew compileKotlin -x compileJava --parallel
- name: GATEWAY TESTS
run: ./gradlew test -x compileTestJava --parallel
- name: GATEWAY BUILD
run: ./gradlew build -x test -x compileJava --parallel
- name: GATEWAY DOCKER DELIVERY
if: github.ref == 'refs/heads/master'
run: ./gradlew jib -Djib.to.image=${{ secrets.DOCKER_HUB_REGISTRY }}/${{ secrets.DOCKER_HUB_USER }}/gateway:latest -Djib.to.auth.username=${{ secrets.DOCKER_HUB_USER }} -Djib.to.auth.password=${{ secrets.DOCKER_HUB_PASSWORD }}
config-server:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: config-server
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: ${{ secrets.JAVA_VERSION }}
distribution: 'adopt'
architecture: x64
- name: Scan current project
id: scan
uses: anchore/scan-action@v2
with:
path: "./config-server"
fail-build: true
acs-report-enable: true
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- run: echo $GIT_CONFIG_URL
- name: GRADLE PREPARATION
run: chmod +x gradlew
- name: CONFIG SERVER COMPILATION
env:
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }}
GIT_CONFIG_URL: ${{ secrets.GIT_CONFIG_URL }}
run: ./gradlew compileKotlin -x compileJava --parallel
- name: CONFIG SERVER BUILD
env:
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }}
GIT_CONFIG_URL: ${{ secrets.GIT_CONFIG_URL }}
run: ./gradlew build -x test -x compileJava --parallel
- name: CONFIG SERVER DOCKER DELIVERY
if: github.ref == 'refs/heads/master'
env:
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }}
GIT_CONFIG_URL: ${{ secrets.GIT_CONFIG_URL }}
run: ./gradlew jib -Djib.to.image=${{ secrets.DOCKER_HUB_REGISTRY }}/${{ secrets.DOCKER_HUB_USER }}/config-server:latest -Djib.to.auth.username=${{ secrets.DOCKER_HUB_USER }} -Djib.to.auth.password=${{ secrets.DOCKER_HUB_PASSWORD }}
frontend:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: notification-app
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '15'
check-latest: true
- name: NPM installation
run: npm install --only=prod --silent
- name: NPM building
run: npm run build
- name: Set up QEMU
if: github.ref == 'refs/heads/master'
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
if: github.ref == 'refs/heads/master'
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Docker
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
with:
context: ./notification-app/.
push: true
tags: fragaly/web:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment