feature: updated scripts, Jenkinsfile. added install.sh

This commit is contained in:
amorozov 2025-03-08 02:08:53 +03:00
parent cbbb454a35
commit 9d60348b8b
5 changed files with 41 additions and 29 deletions

View File

@ -41,22 +41,6 @@ pipeline {
}
}
// Дополнительная сборка для релизов
stage('Build: Release Binaries And Deploy Image') {
when {
anyOf {
tag "release-*"
tag "binaries-*"
}
}
steps {
script {
env.CI_DOCKER_FILES_PRESET="release"
}
runGroovy 'release_docker_gitea_publish'
}
}
// Пушим собранный образ в Docker Registry
stage('Publish: Release docker image') {
when {
@ -71,7 +55,7 @@ pipeline {
}
// Создаем в Gitea релиз с бинарями
stage('Publish: Create gitea release') {
stage('Publish: Build binaries and create gitea release') {
when {
anyOf {
tag "release-*"

27
install.sh Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Адрес репозитория
REPO_URL="https://git.tswf.io/ci/universal-ci-cd-scripts.git"
# Путь к папке внутри репозитория, которую нужно скопировать
SOURCE_DIR="src/main/groovy"
# Целевая директория для копирования файлов
TARGET_DIR=".ci"
# Клонируем репозиторий в временный каталог
TEMP_DIR=$(mktemp -d)
git clone "$REPO_URL" "$TEMP_DIR"
# Проверяем, существует ли целевая папка, и если нет, создаем её
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
# Копируем содержимое папки из временного каталога в целевую папку
cp -r "${TEMP_DIR}/${SOURCE_DIR}/"* "$TARGET_DIR"
# Удаляем временный каталог
rm -rf "$TEMP_DIR"
echo "$SOURCE_DIR copied to $TARGET_DIR"

View File

@ -86,15 +86,16 @@ for (def dockerfileName : deployDockerfiles) {
throw new IllegalStateException("Build tag was not resolved (empty or null '${dockerReleaseTagToSetup}')")
}
def dockerComposeRollbackFileName = "${dockerComposeFileName}.backup.${System.currentTimeMillis()}.yml"
def dockerComposeRollbackDir = "./${dockerComposeFileName}-rollback-backups"
def dockerComposeRollbackFilePath = "${dockerComposeRollbackDir}/${dockerComposeFileName}.backup.${System.currentTimeMillis()}.yml"
try {
sh """ ssh -tt ${sshDeployProfile} "\\
cd '${dockerComposeDirectory}' && \\
cp ${dockerComposeFileName} ${dockerComposeRollbackFileName} && \\
sed -i 's|image: ${dockerImageToUpdateTagBaseName}:.*|image: ${dockerReleaseImageToSetup}|g' '${dockerComposeFileName}'\\ &&
${dockerComposeBaseCommand} -f '${dockerComposeFileName}' up -d \\
"
mkdir -p ${dockerComposeRollbackDir} && \\
cp ${dockerComposeFileName} ${dockerComposeRollbackFilePath} && \\
sed -i 's|image:.*${dockerImageToUpdateTagBaseName}:.*|image: ${dockerReleaseImageToSetup}|g' '${dockerComposeFileName}' && \\
${dockerComposeBaseCommand} -f '${dockerComposeFileName}' up -d"
"""
} catch (Throwable e) {
ScriptLog.printf("Exception occurred while updating docker-compose tag on deploy, rolling back")
@ -103,8 +104,8 @@ for (def dockerfileName : deployDockerfiles) {
sh """ ssh -tt ${sshDeployProfile} "\\
cd '${dockerComposeDirectory}' && \\
rm ${dockerComposeFileName} && \\
cp ${dockerComposeRollbackFileName} ${dockerComposeFileName} \\
"
cp ${dockerComposeRollbackFilePath} ${dockerComposeFileName} \\
${dockerComposeBaseCommand} -f '${dockerComposeFileName}' up -d"
"""
ScriptLog.printf("Application restored from backup")

View File

@ -1,8 +1,5 @@
package script
import util.CIProperties
import util.DockerImageNames
/**
* Скрипт для публикации докер образа при сборке.
@ -13,7 +10,8 @@ import util.DockerImageNames
@Grab(group='io.tswf.groovy.better-groovy', module='better-groovy-scripting-shell', version='2.0.2-SNAPSHOT', changing = true),
@Grab(group='io.tswf.groovy.better-groovy', module='better-groovy-scripting-gitea', version='2.0.2-SNAPSHOT', changing = true)
])
@groovy.transform.CompileStatic
_
import util.DockerLogin
import util.DockerBuildCommandFactory
import util.DockerTags
@ -21,6 +19,8 @@ import util.Dockerfiles
import util.GitTags
import util.GlobalProperties
import util.ScriptLog
import util.CIProperties
import util.DockerImageNames
println """
#############################################################################

View File

@ -9,7 +9,7 @@ class DockerBuildCommandFactory {
def propertyNames = [
"docker.build.${dockerfileName.toLowerCase()}.additional-args",
"docker.build.additional-args"
]
].map { it.toString() }
return propertyNames.stream()
.map { CIProperties.findProperty(it).orNull() }