8713-testToMaster #3523

Merged
alexm merged 383 commits from 8713-testToMaster into master 2025-03-04 06:52:15 +00:00
3 changed files with 82 additions and 92 deletions
Showing only changes of commit 2e36d9b116 - Show all commits

159
Jenkinsfile vendored
View File

@ -8,6 +8,7 @@ def RUN_BUILD
def BRANCH_ENV = [
test: 'test',
master: 'production',
main: 'production',
beta: 'production'
]
@ -20,12 +21,14 @@ node {
'dev',
'test',
'master',
'main',
'beta'
].contains(env.BRANCH_NAME)
FROM_GIT = env.JOB_NAME.startsWith('gitea/')
RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT
RUN_BUILD = PROTECTED_BRANCH && FROM_GIT
IS_LATEST = ['master', 'main'].contains(env.BRANCH_NAME)
// https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
echo "NODE_NAME: ${env.NODE_NAME}"
@ -73,6 +76,7 @@ pipeline {
def packageJson = readJSON file: 'package.json'
def version = "${packageJson.version}-build${env.BUILD_ID}"
writeFile(file: 'VERSION.txt', text: version)
echo "VERSION.txt: ${version}"
}
}
}
@ -105,93 +109,73 @@ pipeline {
}
}
}
stage('Stack') {
parallel {
stage('Back') {
stages {
stage('Test') {
when {
expression { RUN_TESTS }
}
environment {
NODE_ENV = ''
}
steps {
sh 'node back/tests.js --junit'
}
post {
always {
junit(
testResults: 'junitresults.xml',
allowEmptyResults: true
)
}
}
}
stage('Build') {
when {
expression { RUN_BUILD }
}
environment {
VERSION = readFile 'VERSION.txt'
}
steps {
sh 'docker-compose build back'
}
}
}
}
stage('Front') {
when {
expression { FROM_GIT }
}
stages {
stage('Test') {
when {
expression { RUN_TESTS }
}
environment {
NODE_ENV = ''
}
steps {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10'
}
post {
always {
junit(
testResults: 'junit.xml',
allowEmptyResults: true
)
}
}
}
stage('Build') {
when {
expression { RUN_BUILD }
}
environment {
VERSION = readFile 'VERSION.txt'
}
steps {
sh 'gulp build'
sh 'docker-compose build front'
}
}
}
}
}
}
stage('Push') {
stage('Build') {
when {
expression { RUN_BUILD }
}
environment {
CREDENTIALS = credentials('docker-registry')
VERSION = readFile 'VERSION.txt'
CREDENTIALS = credentials('docker-registry')
}
steps {
sh 'docker login --username $CREDENTIALS_USR --password $CREDENTIALS_PSW $REGISTRY'
sh 'docker-compose push'
parallel {
stage('Back') {
steps {
dockerBuildPush 'salix-back', '.', 'back/Dockerfile'
}
}
stage('Front') {
steps {
sh 'gulp build'
dockerBuildPush 'salix-front', 'front'
}
}
stage('DB') {
steps {
sh 'npx myt run -t'
sh 'docker exec vn-database sh -c "cp -r /var/lib/mysql /data"'
sh 'docker commit vn-database vn_db'
sh 'docker stop vn-database'
sh 'docker rm vn-database'
dockerBuildPush 'salix-db', 'db'
}
}
}
}
stage('Test') {
when {
expression { RUN_TESTS }
}
environment {
NODE_ENV = ''
}
parallel {
stage('Back') {
steps {
sh 'node back/tests.js --junit'
}
post {
always {
junit(
testResults: 'junitresults.xml',
allowEmptyResults: true
)
}
}
}
stage('Front') {
steps {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10'
}
post {
always {
junit(
testResults: 'junit.xml',
allowEmptyResults: true
)
}
}
}
}
}
stage('Deploy') {
@ -264,3 +248,16 @@ pipeline {
}
}
}
def dockerBuildPush(imageName, context, dockerfile = null) {
if (dockerfile == null)
dockerfile = "${context}/Dockerfile"
docker.withRegistry("https://${env.REGISTRY}", 'docker-registry') {
def baseImage = "${imageName}:${env.VERSION}"
def image = docker.build(baseImage, "-f ${dockerfile} ${context}")
image.push()
image.push(env.BRANCH_NAME)
if (IS_LATEST) image.push('latest')
}
}

4
db/Dockerfile Normal file
View File

@ -0,0 +1,4 @@
FROM mariadb:10.11.6
ENV TZ Europe/Madrid
COPY --from=vn_db /data /var/lib/mysql
CMD ["mysqld"]

View File

@ -1,11 +0,0 @@
version: '3.7'
services:
front:
image: registry.verdnatura.es/salix-front:${VERSION:?}
build:
context: front
back:
image: registry.verdnatura.es/salix-back:${VERSION:?}
build:
context: .
dockerfile: back/Dockerfile