Skip to content
Snippets Groups Projects
Commit 85b28881 authored by Tomáš Holub's avatar Tomáš Holub
Browse files

#1 - Nahrání quarkus projektu

změna umístění proto souborů, task pro upload proto, ci cd pro image a proto zip
parent b578196a
1 merge request!3#1 - Nahrání quarkus projektu
Pipeline #141541 canceled with stage
......@@ -34,6 +34,3 @@ nb-configuration.xml
# Local environment
.env
# proto
*.proto
variables:
SPRING_PROFILES_ACTIVE: gitlab
CONNECTOR_PACKAGE_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/proto/$CI_COMMIT_TAG/proto-connector.zip"
cache:
untracked: true
key: "$CI_COMMIT_MESSAGE"
stages:
- image
- publish_image
- publish_proto_connector
# ===========================================================================
# Stage: image
# ===========================================================================
sequence-image:
stage: image
script:
- ./gradlew buildNativeImage
# ===========================================================================
# Stage: publish
# ===========================================================================
sequence-publish:
stage: publish_image
only:
- 385-production-server-deployment
- master
- /^verze_\d+\.\d+\.\d+$/
before_script:
- export $(xargs < .env)
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
script:
- docker push $DOCKER_NAMESPACE/sequence:$TAG
# ===========================================================================
# Stage: publish
# ===========================================================================
connector-publish:
rules:
- if: $CI_COMMIT_TAG
stage: publish_proto_connector
before_script:
- apk add --update zip curl
script:
- zip -j proto-connector.zip src/main/proto/*
- 'curl
--header "JOB-TOKEN: $CI_JOB_TOKEN"
--upload-file proto-connector.zip
"${CONNECTOR_PACKAGE_URL}"'
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'java'
id 'groovy'
id 'io.quarkus'
id("de.undercouch.download") version "5.4.0"
}
repositories {
......@@ -31,6 +33,16 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
}
test {
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
......@@ -44,31 +56,69 @@ compileTestJava {
options.encoding = 'UTF-8'
}
// read-only token
def protoRepositoryToken = 'XXXXXX'
def protoRepositoryTag = '1.0.5'
def protoRepositoryUrl = "https://gitlab.com/api/v4/projects/45963671/packages/generic/proto/" + protoRepositoryTag + "/proto.zip"
def protoZipFileDest = new File(buildDir, "myprotos/proto.zip")
def protoDir = "src/main/proto"
def getVersion = { projectName ->
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
try {
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
errorOutput = stderr
ignoreExitValue = true
workingDir "./$projectName"
}
def exitValue = execResult.exitValue
if (exitValue != 0) {
throw new Exception("Command exited with value: $exitValue")
}
} catch (Exception e) {
println "Command failed with error: ${stderr.toString().trim()}"
return 'no-tag'
}
def describe = stdout.toString().trim()
return describe.substring(describe.indexOf('_') + 1, describe.length())
}
ext {
gitVersion = getVersion()
dockerImageNamespace = 'dnaanalyser'
dockerRepository = 'sequence'
dockerImageTag = gitVersion.contains('-')
? 'latest'
: gitVersion
}
def allowedProtoFiles = ['hello.proto']
tasks.register("exportEnv") {
doLast {
File env = new File('.env')
env.write """DOCKER_NAMESPACE=$dockerImageNamespace
TAG=$dockerImageTag
"""
}
}
task deleteProtoDir(type: Delete) {
delete protoDir
processResources {
include '**'
filter ReplaceTokens, tokens: [
'gitVersion': gitVersion,
'assemblyDate': Long.toString(System.currentTimeMillis())
]
}
task pullProtoFiles(type: Download) {
dependsOn deleteProtoDir
task buildNativeImage(type: Exec) {
description = 'Builds a native image of the Quarkus application'
group = 'Build'
src protoRepositoryUrl
dest protoZipFileDest
header 'PRIVATE-TOKEN', protoRepositoryToken
// Define the command to execute.
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine "${project.rootDir}\\gradlew.bat", "clean", "build", "-Dquarkus.package.type=native", "-Dquarkus.native.container-build=true", "-Dquarkus.container-image.build=true"
} else {
commandLine "${project.rootDir}/gradlew", "clean", "build", "-Dquarkus.package.type=native", "-Dquarkus.native.container-build=true", "-Dquarkus.container-image.build=true"
}
doLast {
copy {
from zipTree(protoZipFileDest)
into protoDir
include allowedProtoFiles
}
doFirst {
environment "QUARKUS_CONTAINER_IMAGE_GROUP", "${dockerImageNamespace}"
environment "QUARKUS_CONTAINER_IMAGE_NAME", "${dockerRepository}"
environment "QUARKUS_CONTAINER_IMAGE_TAG", "${dockerImageTag}"
}
}
\ No newline at end of file
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment