2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-01-30 20:49:58 +00:00
|
|
|
|
|
|
|
def PROTECTED_BRANCH
|
|
|
|
def FROM_GIT
|
|
|
|
def RUN_TESTS
|
2024-02-04 23:10:05 +00:00
|
|
|
def RUN_BUILD
|
2024-01-30 20:49:58 +00:00
|
|
|
|
2024-02-07 12:24:50 +00:00
|
|
|
def BRANCH_ENV = [
|
|
|
|
test: 'test',
|
|
|
|
master: 'production'
|
|
|
|
]
|
|
|
|
|
2024-02-06 09:20:04 +00:00
|
|
|
node {
|
|
|
|
stage('Setup') {
|
2024-02-07 12:24:50 +00:00
|
|
|
env.BACK_REPLICAS = 1
|
|
|
|
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
|
2024-02-06 10:27:14 +00:00
|
|
|
|
2024-02-06 10:40:13 +00:00
|
|
|
PROTECTED_BRANCH = [
|
|
|
|
'dev',
|
|
|
|
'test',
|
|
|
|
'master'
|
|
|
|
].contains(env.BRANCH_NAME)
|
|
|
|
|
|
|
|
FROM_GIT = env.JOB_NAME.startsWith('gitea/')
|
|
|
|
RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT
|
|
|
|
RUN_BUILD = PROTECTED_BRANCH && FROM_GIT
|
2024-05-27 08:07:44 +00:00
|
|
|
|
2024-02-06 11:16:49 +00:00
|
|
|
// https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
|
2024-02-06 11:21:06 +00:00
|
|
|
echo "NODE_NAME: ${env.NODE_NAME}"
|
|
|
|
echo "WORKSPACE: ${env.WORKSPACE}"
|
2024-02-06 11:16:49 +00:00
|
|
|
|
2024-02-07 12:56:21 +00:00
|
|
|
configFileProvider([
|
|
|
|
configFile(fileId: 'salix.properties',
|
|
|
|
variable: 'PROPS_FILE')
|
|
|
|
]) {
|
|
|
|
def props = readProperties file: PROPS_FILE
|
|
|
|
props.each {key, value -> env."${key}" = value }
|
|
|
|
props.each {key, value -> echo "${key}: ${value}" }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PROTECTED_BRANCH) {
|
2024-02-06 10:27:14 +00:00
|
|
|
configFileProvider([
|
2024-02-07 12:56:21 +00:00
|
|
|
configFile(fileId: "salix.branch.${env.BRANCH_NAME}",
|
|
|
|
variable: 'BRANCH_PROPS_FILE')
|
2024-02-06 10:27:14 +00:00
|
|
|
]) {
|
2024-02-07 12:56:21 +00:00
|
|
|
def props = readProperties file: BRANCH_PROPS_FILE
|
2024-02-06 11:17:45 +00:00
|
|
|
props.each {key, value -> env."${key}" = value }
|
2024-02-06 11:16:49 +00:00
|
|
|
props.each {key, value -> echo "${key}: ${value}" }
|
2024-02-06 10:27:14 +00:00
|
|
|
}
|
2024-02-06 09:20:04 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-01 21:13:36 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
pipeline {
|
2019-01-11 13:15:34 +00:00
|
|
|
agent any
|
2019-01-17 11:06:40 +00:00
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
}
|
2024-02-01 13:07:42 +00:00
|
|
|
tools {
|
|
|
|
nodejs 'node-v20'
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
environment {
|
2019-12-23 13:33:54 +00:00
|
|
|
PROJECT_NAME = 'salix'
|
2019-01-08 14:54:02 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
stages {
|
2019-02-11 23:22:59 +00:00
|
|
|
stage('Install') {
|
|
|
|
environment {
|
2024-02-06 09:20:04 +00:00
|
|
|
NODE_ENV = ''
|
2019-02-11 23:22:59 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
parallel {
|
2024-02-06 09:20:04 +00:00
|
|
|
stage('Back') {
|
2024-01-30 19:04:32 +00:00
|
|
|
steps {
|
2024-02-06 09:20:04 +00:00
|
|
|
sh 'pnpm install --prefer-offline'
|
2024-04-19 05:27:54 +00:00
|
|
|
sh 'node node_modules/puppeteer/install.mjs'
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-06 09:20:04 +00:00
|
|
|
stage('Print') {
|
2024-01-30 20:57:04 +00:00
|
|
|
when {
|
2024-02-06 09:20:04 +00:00
|
|
|
expression { FROM_GIT }
|
2024-01-30 20:57:04 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
steps {
|
2024-02-06 09:20:04 +00:00
|
|
|
sh 'pnpm install --prefer-offline --prefix=print'
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-06 09:20:04 +00:00
|
|
|
stage('Front') {
|
2024-01-30 20:57:04 +00:00
|
|
|
when {
|
2024-02-06 09:20:04 +00:00
|
|
|
expression { FROM_GIT }
|
2024-01-30 20:57:04 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
steps {
|
2024-02-06 09:20:04 +00:00
|
|
|
sh 'pnpm install --prefer-offline --prefix=front'
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
stage('Stack') {
|
2022-05-12 14:18:08 +00:00
|
|
|
parallel {
|
2024-02-04 22:58:26 +00:00
|
|
|
stage('Back') {
|
2024-02-04 20:17:47 +00:00
|
|
|
stages {
|
|
|
|
stage('Test') {
|
|
|
|
when {
|
|
|
|
expression { RUN_TESTS }
|
|
|
|
}
|
|
|
|
environment {
|
2024-02-06 09:20:04 +00:00
|
|
|
NODE_ENV = ''
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
|
|
|
steps {
|
2024-06-04 20:59:33 +00:00
|
|
|
sh 'node back/tests.js --junit'
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
|
|
|
post {
|
|
|
|
always {
|
2024-02-06 20:51:15 +00:00
|
|
|
junit(
|
|
|
|
testResults: 'junitresults.xml',
|
|
|
|
allowEmptyResults: true
|
|
|
|
)
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stage('Build') {
|
|
|
|
when {
|
|
|
|
expression { RUN_BUILD }
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-05 10:38:16 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:41:00 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-05 10:38:16 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
sh 'docker-compose build back'
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2022-05-12 14:18:08 +00:00
|
|
|
}
|
2022-05-13 10:25:35 +00:00
|
|
|
}
|
2024-02-04 22:58:26 +00:00
|
|
|
stage('Front') {
|
2024-02-04 20:17:47 +00:00
|
|
|
when {
|
|
|
|
expression { FROM_GIT }
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stages {
|
|
|
|
stage('Test') {
|
|
|
|
when {
|
|
|
|
expression { RUN_TESTS }
|
|
|
|
}
|
|
|
|
environment {
|
2024-02-06 09:20:04 +00:00
|
|
|
NODE_ENV = ''
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10'
|
|
|
|
}
|
2024-02-06 20:51:15 +00:00
|
|
|
post {
|
|
|
|
always {
|
|
|
|
junit(
|
|
|
|
testResults: 'junit.xml',
|
|
|
|
allowEmptyResults: true
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stage('Build') {
|
|
|
|
when {
|
|
|
|
expression { RUN_BUILD }
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-05 10:38:16 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:41:00 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-05 10:38:16 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
sh 'gulp build'
|
|
|
|
sh 'docker-compose build front'
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2022-11-14 09:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-27 07:26:02 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
stage('Push') {
|
2024-01-30 17:52:31 +00:00
|
|
|
when {
|
2024-02-04 20:00:03 +00:00
|
|
|
expression { RUN_BUILD }
|
2024-01-30 17:52:31 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
environment {
|
2021-04-29 22:39:44 +00:00
|
|
|
CREDENTIALS = credentials('docker-registry')
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
steps {
|
2024-02-02 13:27:36 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:41:00 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-02 13:27:36 +00:00
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
sh 'docker login --username $CREDENTIALS_USR --password $CREDENTIALS_PSW $REGISTRY'
|
|
|
|
sh 'docker-compose push'
|
2019-01-02 00:16:28 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Deploy') {
|
2024-01-30 19:58:15 +00:00
|
|
|
when {
|
2024-02-01 20:49:42 +00:00
|
|
|
expression { PROTECTED_BRANCH }
|
2024-01-30 19:58:15 +00:00
|
|
|
}
|
2024-01-30 18:51:30 +00:00
|
|
|
parallel {
|
|
|
|
stage('Database') {
|
|
|
|
steps {
|
|
|
|
configFileProvider([
|
|
|
|
configFile(fileId: "config.${env.NODE_ENV}.ini",
|
|
|
|
variable: 'MYSQL_CONFIG')
|
|
|
|
]) {
|
|
|
|
sh 'mkdir -p db/remotes'
|
|
|
|
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
|
|
|
|
}
|
2024-01-30 20:37:20 +00:00
|
|
|
|
|
|
|
sh 'npx myt push $NODE_ENV --force --commit'
|
2024-01-30 18:51:30 +00:00
|
|
|
}
|
2019-03-20 11:21:32 +00:00
|
|
|
}
|
2024-05-27 07:39:51 +00:00
|
|
|
stage('Kubernetes') {
|
2024-01-30 19:04:32 +00:00
|
|
|
when {
|
2024-02-01 20:49:42 +00:00
|
|
|
expression { FROM_GIT }
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
|
|
|
steps {
|
2024-02-02 13:27:36 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:41:00 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-02 13:27:36 +00:00
|
|
|
}
|
2024-05-27 07:31:42 +00:00
|
|
|
withKubeConfig([
|
|
|
|
serverUrl: "$KUBERNETES_API",
|
|
|
|
credentialsId: 'kubernetes',
|
|
|
|
namespace: 'salix'
|
|
|
|
]) {
|
2024-05-27 07:37:17 +00:00
|
|
|
sh 'kubectl set image deployment/salix-back-$BRANCH_NAME salix-back-$BRANCH_NAME=$REGISTRY/salix-back:$VERSION'
|
|
|
|
sh 'kubectl set image deployment/salix-front-$BRANCH_NAME salix-front-$BRANCH_NAME=$REGISTRY/salix-front:$VERSION'
|
2024-05-27 07:31:42 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 11:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-24 12:41:38 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
post {
|
2024-01-30 17:52:31 +00:00
|
|
|
success {
|
|
|
|
script {
|
2024-01-30 20:49:58 +00:00
|
|
|
if (env.BRANCH_NAME == 'master' && FROM_GIT) {
|
2024-02-02 13:27:36 +00:00
|
|
|
env.GIT_COMMIT_MSG = sh(
|
|
|
|
script: 'git log -1 --pretty=%B ${GIT_COMMIT}',
|
|
|
|
returnStdout: true
|
|
|
|
).trim()
|
|
|
|
|
2024-01-30 17:52:31 +00:00
|
|
|
String message = env.GIT_COMMIT_MSG
|
|
|
|
int index = message.indexOf('\n')
|
|
|
|
if (index != -1)
|
|
|
|
message = message.substring(0, index)
|
|
|
|
|
2024-02-22 08:36:48 +00:00
|
|
|
setEnv()
|
2024-01-30 17:52:31 +00:00
|
|
|
rocketSend(
|
|
|
|
channel: 'vn-database',
|
|
|
|
message: "*DB version uploaded:* ${message}"
|
|
|
|
+"\n$COMMITTER_EMAIL ($BRANCH_NAME)"
|
2024-02-23 17:57:32 +00:00
|
|
|
+"\n$RUN_DISPLAY_URL",
|
2024-01-30 17:52:31 +00:00
|
|
|
rawMessage: true
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 19:58:15 +00:00
|
|
|
unsuccessful {
|
2024-02-02 13:27:36 +00:00
|
|
|
setEnv()
|
2024-01-30 19:58:15 +00:00
|
|
|
sendEmail()
|
|
|
|
}
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|