[Jenkins] Deploy a cleaned up archive
All checks were successful
Gitsokyo/bot-base/pipeline/head This commit looks good
Gitsokyo/bot-base/pipeline/tag This commit looks good

This commit is contained in:
Suwako Moriya 2020-04-28 00:42:13 +02:00
parent f6b8448cf8
commit 2c54c3108f
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5
4 changed files with 74 additions and 15 deletions

1
.gitignore vendored
View File

@ -77,3 +77,4 @@ data/*
/src/datas/ /src/datas/
/src/doctest_config.toml /src/doctest_config.toml
/datas /datas
requirements.txt

9
.releaseignore Normal file
View File

@ -0,0 +1,9 @@
.git
.gitignore
.releaseignore
Dockerfile
Jenkinsfile
Pipfile
Pipfile.lock
doc
scripts

View File

@ -2,7 +2,8 @@ FROM python:3.8
RUN apt-get update && apt-get install -y\ RUN apt-get update && apt-get install -y\
rsync \ rsync \
openssh-client openssh-client \
zip
RUN pip install pipenv RUN pip install pipenv

76
Jenkinsfile vendored
View File

@ -7,10 +7,31 @@ pipeline {
environment { environment {
SPHINXOPTS = '-w sphinx-build.log' SPHINXOPTS = '-w sphinx-build.log'
DEPLOY_HOST = 'docs@moriya.zapto.org' DEPLOY_HOST = 'docs@moriya.zapto.org'
DEPLOY_PATH = 'www/docs/bot-base/' PROJECT_NAME = 'bot-base'
DEPLOY_DOC_PATH = "www/docs/${env.PROJECT_NAME}/"
DEPLOY_REL_PATH = "www/releases/${env.PROJECT_NAME}/"
TAG_NAME = """${TAG_NAME ?: ""}"""
ARTIFACTS = "${WORKSPACE}/.artifacts"
}
stages {
stage('Generate release archives') {
steps {
sh 'git clean -fxd'
sh 'mkdir -p ${ARTIFACTS}/build'
sh 'mkdir -p /tmp/build'
sh 'pipenv lock -r | tee requirements.txt'
sh 'echo .artifacts >> .releaseignore'
sh 'rsync -avr --exclude-from=.releaseignore ./ /tmp/build'
sh 'tar -C /tmp/build -cvzf ${ARTIFACTS}/build/${TAG_NAME:-${GIT_BRANCH#*/}}.tar.gz --owner=0 --group=0 .'
sh 'cd /tmp/build && zip ${ARTIFACTS}/build/${TAG_NAME:-${GIT_BRANCH#*/}}.zip -r .'
}
post {
always {
archiveArtifacts artifacts: ".artifacts/build/*", fingerprint: true
}
}
} }
stages {
stage('Install Dependencies') { stage('Install Dependencies') {
steps { steps {
sh 'pipenv sync --verbose --sequential --dev' sh 'pipenv sync --verbose --sequential --dev'
@ -31,14 +52,14 @@ pipeline {
stage('Build Documentation') { stage('Build Documentation') {
steps { steps {
sh 'rm -f doc/sphinx-build.log'
sh '''cd doc sh '''cd doc
pipenv run make html''' pipenv run make html'''
sh 'tar -C doc/build/html -czf docs-${BUILD_TAG}.tar.gz .' sh 'mkdir -p ${ARTIFACTS}/doc'
sh 'tar -C doc/build/html -czf ${ARTIFACTS}/doc/html.tar.gz .'
} }
post { post {
success { success {
archiveArtifacts artifacts: "docs-${env.BUILD_TAG}.tar.gz", fingerprint: true archiveArtifacts artifacts: ".artifacts/doc/*", fingerprint: true
} }
failure { failure {
sh 'cat doc/sphinx-build.log' sh 'cat doc/sphinx-build.log'
@ -47,9 +68,6 @@ pipeline {
} }
stage('Deploy Documentation') { stage('Deploy Documentation') {
environment {
TAG_NAME = """${TAG_NAME ?: ""}"""
}
when { when {
anyOf { anyOf {
branch 'stable' branch 'stable'
@ -58,22 +76,52 @@ pipeline {
} }
} }
steps { steps {
sh 'rm -f rsync.log'
sshagent(credentials: ['1cf72f47-b70c-4f90-a958-020956099d19']) { sshagent(credentials: ['1cf72f47-b70c-4f90-a958-020956099d19']) {
sh 'echo ${TAG_NAME:-${GIT_BRANCH#*/}}' sh 'echo ${TAG_NAME:-${GIT_BRANCH#*/}}'
sh 'echo ${DEPLOY_HOST}:${DEPLOY_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/ >> debug.log' sh 'echo ${DEPLOY_HOST}:${DEPLOY_DOC_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'
sh 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes ${DEPLOY_HOST} mkdir -p ${DEPLOY_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/' sh 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes ${DEPLOY_HOST} mkdir -p ${DEPLOY_DOC_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'
sh '''rsync -aze 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes' \ sh '''rsync -aze 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes' \
--log-file=rsync.log \ --log-file=rsync-doc.log \
--delete \ --delete \
doc/build/html/ ${DEPLOY_HOST}:${DEPLOY_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/''' doc/build/html/ ${DEPLOY_HOST}:${DEPLOY_DOC_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'''
} }
} }
post { post {
failure { failure {
sh 'cat doc/debug.log doc/rsync.log' sh 'cat rsync-doc.log'
}
}
}
stage('Deploy Release Files') {
when {
anyOf {
branch 'stable'
branch 'master'
buildingTag()
}
}
steps {
sshagent(credentials: ['1cf72f47-b70c-4f90-a958-020956099d19']) {
sh 'echo ${TAG_NAME:-${GIT_BRANCH#*/}}'
sh 'echo ${DEPLOY_HOST}:${DEPLOY_REL_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'
sh 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes ${DEPLOY_HOST} mkdir -p ${DEPLOY_REL_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'
sh '''rsync -aze 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes' \
--log-file=rsync-rel.log \
--delete \
${ARTIFACTS}/ ${DEPLOY_HOST}:${DEPLOY_REL_PATH}${TAG_NAME:-${GIT_BRANCH#*/}}/'''
}
}
post {
failure {
sh 'cat rsync-rel.log'
} }
} }
} }
} }
post {
always {
sh 'git clean -fxd'
}
}
} }