everybody-mov/Jenkinsfile

96 lines
3.0 KiB
Plaintext
Raw Normal View History

pipeline {
agent none
environment {
HOME = "${env.WORKSPACE}"
PYTHON_IMAGE = 'python:3.10-slim-bullseye'
CREDENTIALS_ID = 'digital-ocean-ailuridae-registry'
REGISTRY = 'https://registry.digitalocean.com'
IMAGE_NAME = 'registry.digitalocean.com/ailuridae-registry/ailuridae.io/everybodymov'
IMAGE_BUILD = ''
2022-09-04 04:48:33 +00:00
APP_ID = credentials('digital-ocean-app-id')
}
stages {
stage('Check') {
agent {
docker {
image env.PYTHON_IMAGE
args '--rm'
}
}
steps {
2022-09-04 04:40:46 +00:00
sh 'python -m pip install --no-cache-dir --upgrade --user pip'
sh 'python -m pip install --no-cache-dir --user pipenv'
sh 'python -m pipenv install --dev --deploy'
sh 'python -m pipenv check --clear'
sh 'python -m pipenv run bandit *.py'
}
}
stage('Build') {
agent {
label 'main'
}
steps {
script {
IMAGE_BUILD = docker.build("${IMAGE_NAME}")
}
}
}
stage('Publish') {
agent {
label 'main'
}
2022-09-02 04:38:29 +00:00
when {
branch 'main'
}
steps {
script {
2022-09-04 04:40:46 +00:00
// withCredentials is annoyingly required to mask token occurrences.
withCredentials([usernamePassword(
credentialsId: env.CREDENTIALS_ID,
usernameVariable: 'API_TOKEN_USER',
passwordVariable: 'API_TOKEN_PASS'
)]) {
docker.withRegistry(env.REGISTRY, env.CREDENTIALS_ID) {
IMAGE_BUILD.push("${BUILD_NUMBER}")
IMAGE_BUILD.push('latest')
}
}
}
}
}
2022-09-04 04:49:29 +00:00
stage('Deploy') {
2022-09-04 04:51:48 +00:00
agent {
label 'main'
}
// when {
// branch 'main'
// }
steps {
script {
withCredentials([usernamePassword(
credentialsId: env.CREDENTIALS_ID,
usernameVariable: 'API_TOKEN_USER',
passwordVariable: 'API_TOKEN_PASS'
)]) {
sh '''
2022-09-04 04:54:45 +00:00
curl -H "Authorization: Bearer $API_TOKEN_PASS" -H "Content-Type: application/json" \
2022-09-04 04:58:11 +00:00
-X POST "https://api.digitalocean.com/v2/apps/$APP_ID/deployments" \
2022-09-04 05:00:25 +00:00
-d "{ \"force_build\" : true }" --fail-with-body
2022-09-04 04:51:48 +00:00
'''
2022-09-04 04:48:33 +00:00
}
2022-09-04 04:51:48 +00:00
}
2022-09-04 04:40:46 +00:00
}
}
}
post {
always {
node('main') {
cleanWs()
}
}
}
}