2022-09-01 03:23:10 +00:00
|
|
|
pipeline {
|
|
|
|
agent none
|
|
|
|
|
|
|
|
environment {
|
|
|
|
HOME = "${env.WORKSPACE}"
|
2022-09-04 03:28:54 +00:00
|
|
|
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')
|
2022-09-01 03:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
stage('Check') {
|
|
|
|
agent {
|
|
|
|
docker {
|
2022-09-04 03:28:54 +00:00
|
|
|
image env.PYTHON_IMAGE
|
|
|
|
args '--rm'
|
2022-09-01 03:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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'
|
2022-09-01 03:23:10 +00:00
|
|
|
sh 'python -m pipenv check --clear'
|
|
|
|
sh 'python -m pipenv run bandit *.py'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Build') {
|
|
|
|
agent {
|
|
|
|
label 'main'
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
script {
|
2022-09-04 03:28:54 +00:00
|
|
|
IMAGE_BUILD = docker.build("${IMAGE_NAME}")
|
2022-09-01 03:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Publish') {
|
|
|
|
agent {
|
|
|
|
label 'main'
|
|
|
|
}
|
2022-09-02 04:38:29 +00:00
|
|
|
when {
|
|
|
|
branch 'main'
|
|
|
|
}
|
2022-09-01 03:23:10 +00:00
|
|
|
steps {
|
|
|
|
script {
|
2022-09-04 04:40:46 +00:00
|
|
|
// withCredentials is annoyingly required to mask token occurrences.
|
2022-09-04 03:28:54 +00:00
|
|
|
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-01 03:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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'
|
|
|
|
)]) {
|
2022-09-04 05:23:05 +00:00
|
|
|
sh """
|
2022-09-04 05:18:47 +00:00
|
|
|
curl -H 'Authorization: Bearer $API_TOKEN_PASS' -H 'Content-Type: application/json' \
|
|
|
|
-X POST 'https://api.digitalocean.com/v2/apps/$APP_ID/deployments' \
|
|
|
|
-d '{ \"force_build\" : true }'
|
2022-09-04 05:23:05 +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
|
|
|
}
|
|
|
|
}
|
2022-09-01 03:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
node('main') {
|
|
|
|
cleanWs()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-04 03:28:54 +00:00
|
|
|
}
|