amarillo-core/Jenkinsfile
Csaba 3b6b8dddf8
Some checks failed
Amarillo/amarillo-gitea/amarillo-core/pipeline/head There was a failure building this commit
Build amarillo-base and derived images
2024-06-14 11:24:47 +02:00

136 lines
5.3 KiB
Groovy

pipeline {
agent { label 'builtin' }
environment {
GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER')
TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi"
PLUGINS_REPO_URL = "git.gerhardt.io/api/packages/amarillo/pypi/simple"
DOCKER_REGISTRY_URL = 'https://git.gerhardt.io'
DERIVED_DOCKERFILE = 'standard.Dockerfile'
OWNER = 'amarillo'
BASE_IMAGE_NAME = 'amarillo-base'
IMAGE_NAME = 'amarillo'
AMARILLO_DISTRIBUTION = '0.1'
TAG = "${AMARILLO_DISTRIBUTION}.${BUILD_NUMBER}${env.BRANCH_NAME == 'main' ? '' : '-dev'}"
DEPLOY_WEBHOOK_URL = "${env.BRANCH_NAME == 'main' ? 'http://amarillo.mfdz.de:8888/mitanand' : 'http://amarillo.mfdz.de:8888/dev'}"
DEPLOY_SECRET = credentials('AMARILLO-JENKINS-DEPLOY-SECRET')
}
stages {
stage('Create virtual environment') {
steps {
echo 'Creating virtual environment'
sh '''python3 -m venv .venv
. .venv/bin/activate'''
}
}
stage('Installing requirements') {
steps {
echo 'Installing packages'
sh 'python3 -m pip install -r requirements.txt'
sh 'python3 -m pip install --upgrade build'
sh 'python3 -m pip install --upgrade twine'
}
}
stage('Build package') {
steps {
echo 'Building package'
sh 'python3 -m build'
}
}
stage('Publish package') {
steps {
sh 'python3 -m twine upload --skip-existing --verbose --repository-url $TWINE_REPO_URL --username $GITEA_CREDS_USR --password $GITEA_CREDS_PSW ./dist/*'
}
}
stage('Build base docker image') {
when {
anyOf { branch 'main'; branch 'dev' }
}
steps {
echo 'Building image'
script {
docker.build("${OWNER}/${BASE_IMAGE_NAME}:${TAG}")
// "--no-cache --build-arg='PACKAGE_REGISTRY_URL=${PLUGINS_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .")
}
}
}
stage('Push base image to container registry') {
when {
anyOf { branch 'main'; branch 'dev' }
}
steps {
echo 'Pushing image to registry'
script {
docker.withRegistry(DOCKER_REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){
def image = docker.image("${OWNER}/${BASE_IMAGE_NAME}:${TAG}")
image.push()
image.push('latest')
}
}
}
}
stage('Build derived docker image') {
when {
anyOf { branch 'main'; branch 'dev' }
}
steps {
echo 'Building image'
script {
docker.withRegistry(DOCKER_REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){
docker.build("${OWNER}/${IMAGE_NAME}:${TAG}",
//--no-cache to make sure plugins are updated
"-f ${DERIVED_DOCKERFILE} --no-cache --build-arg='PACKAGE_REGISTRY_URL=${PLUGINS_REPO_URL}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .")
// "--no-cache --build-arg='PACKAGE_REGISTRY_URL=${PLUGINS_REPO_URL}' --build-arg='PLUGINS=${PLUGINS}' --secret id=AMARILLO_REGISTRY_CREDENTIALS,env=GITEA_CREDS .")
}
}
}
}
stage('Push derived image to container registry') {
when {
anyOf { branch 'main'; branch 'dev' }
}
steps {
echo 'Pushing image to registry'
script {
docker.withRegistry(DOCKER_REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){
def image = docker.image("${OWNER}/${IMAGE_NAME}:${TAG}")
image.push()
image.push('latest')
}
}
}
}
stage('Notify CD script') {
when {
anyOf { branch 'main'; branch 'dev' }
}
steps {
echo 'Triggering deploy webhook'
script {
def response = httpRequest contentType: 'APPLICATION_JSON',
httpMode: 'POST', requestBody: '{}', authentication: 'AMARILLO-JENKINS-DEPLOY-SECRET',
url: "${DEPLOY_WEBHOOK_URL}"
}
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
echo 'This will run only if failed'
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}