mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 10:42:25 -05:00
Merge pull request #845 from alphagov/remove_jenkinsfiles
Remove Jenkinsfiles, add PaaS build/upload artifact tasks
This commit is contained in:
250
Jenkinsfile
vendored
250
Jenkinsfile
vendored
@@ -1,250 +0,0 @@
|
|||||||
#!groovy
|
|
||||||
|
|
||||||
def deployDatabaseMigrations(cfEnv) {
|
|
||||||
waitUntil {
|
|
||||||
try {
|
|
||||||
lock(cfEnv) {
|
|
||||||
withCredentials([
|
|
||||||
string(credentialsId: 'paas_username', variable: 'CF_USERNAME'),
|
|
||||||
string(credentialsId: 'paas_password', variable: 'CF_PASSWORD')
|
|
||||||
]) {
|
|
||||||
withEnv(["CF_SPACE=${cfEnv}"]) {
|
|
||||||
sh 'make cf-deploy-api-db-migration-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
} catch(err) {
|
|
||||||
echo "Deployment to ${cfEnv} failed: ${err}"
|
|
||||||
try {
|
|
||||||
slackSend channel: '#govuk-notify', message: "Deployment to ${cfEnv} failed. Please retry or abort: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'danger'
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending Slack message failed: ${err2}"
|
|
||||||
}
|
|
||||||
input "Stage failed. Retry?"
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def deploy(cfEnv) {
|
|
||||||
waitUntil {
|
|
||||||
try {
|
|
||||||
lock(cfEnv) {
|
|
||||||
withCredentials([
|
|
||||||
string(credentialsId: 'paas_username', variable: 'CF_USERNAME'),
|
|
||||||
string(credentialsId: 'paas_password', variable: 'CF_PASSWORD')
|
|
||||||
]) {
|
|
||||||
withEnv(["CF_SPACE=${cfEnv}"]) {
|
|
||||||
parallel deployApi: {
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-api"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, deployDeliveryCeleryBeat: {
|
|
||||||
sleep(10)
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-delivery-celery-beat"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, deployDeliveryWorker: {
|
|
||||||
sleep(20)
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-delivery-worker"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, deployDeliveryWorkerSender: {
|
|
||||||
sleep(30)
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-delivery-worker-sender"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, deployDeliveryWorkerDatabase: {
|
|
||||||
sleep(40)
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-delivery-worker-database"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, deployDeliveryWorkerResearch: {
|
|
||||||
sleep(50)
|
|
||||||
retry(3) {
|
|
||||||
withEnv(["CF_APP=notify-delivery-worker-research"]) {
|
|
||||||
sh 'make cf-deploy-with-docker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gitCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
|
||||||
sh("git tag -f deployed-to-cf-${cfEnv} ${gitCommit}")
|
|
||||||
sh("git push -f origin deployed-to-cf-${cfEnv}")
|
|
||||||
}
|
|
||||||
true
|
|
||||||
} catch(err) {
|
|
||||||
echo "Deployment to ${cfEnv} failed: ${err}"
|
|
||||||
try {
|
|
||||||
slackSend channel: '#govuk-notify', message: "Deployment to ${cfEnv} failed. Please retry or abort: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'danger'
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending Slack message failed: ${err2}"
|
|
||||||
}
|
|
||||||
input "Stage failed. Retry?"
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def buildJobWithRetry(jobName) {
|
|
||||||
waitUntil {
|
|
||||||
try {
|
|
||||||
build job: jobName
|
|
||||||
true
|
|
||||||
} catch(err) {
|
|
||||||
echo "${jobName} failed: ${err}"
|
|
||||||
try {
|
|
||||||
slackSend channel: '#govuk-notify', message: "${jobName} failed. Please retry or abort: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'danger'
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending Slack message failed: ${err2}"
|
|
||||||
}
|
|
||||||
input "${jobName} failed. Retry?"
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
node {
|
|
||||||
stage('Build') {
|
|
||||||
git url: 'git@github.com:alphagov/notifications-api.git', branch: 'master', credentialsId: 'github_com_and_gds'
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
milestone 10
|
|
||||||
withEnv(["PIP_ACCEL_CACHE=${env.JENKINS_HOME}/cache/pip-accel"]) {
|
|
||||||
sh 'make cf-build-with-docker'
|
|
||||||
}
|
|
||||||
|
|
||||||
stash name: 'source', excludes: 'venv/**,wheelhouse/**', useDefaultExcludes: false
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Test') {
|
|
||||||
milestone 20
|
|
||||||
sh 'make test-with-docker'
|
|
||||||
|
|
||||||
try {
|
|
||||||
junit 'test_results.xml'
|
|
||||||
} catch(err) {
|
|
||||||
echo "Collecting jUnit results failed: ${err}"
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
withCredentials([string(credentialsId: 'coveralls_repo_token_api', variable: 'COVERALLS_REPO_TOKEN')]) {
|
|
||||||
sh 'make coverage-with-docker'
|
|
||||||
}
|
|
||||||
} catch(err) {
|
|
||||||
echo "Coverage failed: ${err}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Preview') {
|
|
||||||
if (deployToPreview == "true") {
|
|
||||||
milestone 30
|
|
||||||
deployDatabaseMigrations 'preview'
|
|
||||||
buildJobWithRetry 'notify-functional-tests-preview'
|
|
||||||
deploy 'preview'
|
|
||||||
} else {
|
|
||||||
echo 'Preview skipped.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Preview tests') {
|
|
||||||
if (deployToPreview == "true") {
|
|
||||||
buildJobWithRetry 'notify-functional-tests-preview'
|
|
||||||
buildJobWithRetry 'run-ruby-client-integration-tests'
|
|
||||||
buildJobWithRetry 'run-python-client-integration-tests'
|
|
||||||
buildJobWithRetry 'run-net-client-integration-tests'
|
|
||||||
buildJobWithRetry 'run-node-client-integration-tests'
|
|
||||||
buildJobWithRetry 'run-java-client-integration-tests'
|
|
||||||
buildJobWithRetry 'run-php-client-integration-tests'
|
|
||||||
} else {
|
|
||||||
echo 'Preview tests skipped.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Staging') {
|
|
||||||
if (deployToStaging == "true") {
|
|
||||||
milestone 40
|
|
||||||
input 'Approve?'
|
|
||||||
node {
|
|
||||||
unstash 'source'
|
|
||||||
deployDatabaseMigrations 'staging'
|
|
||||||
buildJobWithRetry 'notify-functional-tests-staging'
|
|
||||||
deploy 'staging'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo 'Staging skipped.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Staging tests') {
|
|
||||||
if (deployToStaging == "true") {
|
|
||||||
buildJobWithRetry 'notify-functional-tests-staging'
|
|
||||||
buildJobWithRetry 'notify-functional-provider-tests-staging'
|
|
||||||
} else {
|
|
||||||
echo 'Staging tests skipped'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Prod') {
|
|
||||||
if (deployToProduction == "true") {
|
|
||||||
milestone 50
|
|
||||||
input 'Approve?'
|
|
||||||
node {
|
|
||||||
unstash 'source'
|
|
||||||
deployDatabaseMigrations 'production'
|
|
||||||
buildJobWithRetry 'notify-functional-admin-tests-production'
|
|
||||||
buildJobWithRetry 'notify-functional-api-email-test-production'
|
|
||||||
buildJobWithRetry 'notify-functional-api-sms-test-production'
|
|
||||||
deploy 'production'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo 'Production skipped.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Prod tests') {
|
|
||||||
if (deployToProduction == "true") {
|
|
||||||
buildJobWithRetry 'notify-functional-admin-tests-production'
|
|
||||||
buildJobWithRetry 'notify-functional-api-email-test-production'
|
|
||||||
buildJobWithRetry 'notify-functional-api-sms-test-production'
|
|
||||||
buildJobWithRetry 'notify-functional-provider-email-test-production'
|
|
||||||
buildJobWithRetry 'notify-functional-provider-sms-test-production'
|
|
||||||
} else {
|
|
||||||
echo 'Production tests skipped.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException fie) {
|
|
||||||
currentBuild.result = 'ABORTED'
|
|
||||||
} catch (err) {
|
|
||||||
currentBuild.result = 'FAILURE'
|
|
||||||
echo "Pipeline failed: ${err}"
|
|
||||||
slackSend channel: '#govuk-notify', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} failed (<${env.BUILD_URL}|Open>)", color: 'danger'
|
|
||||||
} finally {
|
|
||||||
node {
|
|
||||||
try {
|
|
||||||
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'notify-support+jenkins@digital.cabinet-office.gov.uk', sendToIndividuals: false])
|
|
||||||
} catch(err) {
|
|
||||||
echo "Sending email failed: ${err}"
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sh 'make clean-docker-containers'
|
|
||||||
} catch(err) {
|
|
||||||
echo "Cleaning up Docker containers failed: ${err}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
#!groovy
|
|
||||||
|
|
||||||
node {
|
|
||||||
try {
|
|
||||||
stage('Download') {
|
|
||||||
step([$class: 'WsCleanup'])
|
|
||||||
|
|
||||||
echo "Downloading build artifact.."
|
|
||||||
withCredentials([
|
|
||||||
string(credentialsId: "${aws_env}_aws_access_key", variable: 'AWS_ACCESS_KEY_ID'),
|
|
||||||
string(credentialsId: "${aws_env}_aws_secret_key", variable: 'AWS_SECRET_ACCESS_KEY')
|
|
||||||
]) {
|
|
||||||
sh 'aws s3 cp --region eu-west-1 s3://${dns_name}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip source.zip'
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Extracting build artifact.."
|
|
||||||
sh 'unzip -q source.zip'
|
|
||||||
}
|
|
||||||
stage('Deploy') {
|
|
||||||
lock(cf_space) {
|
|
||||||
withCredentials([
|
|
||||||
string(credentialsId: 'paas_username', variable: 'CF_USERNAME'),
|
|
||||||
string(credentialsId: 'paas_password', variable: 'CF_PASSWORD')
|
|
||||||
]) {
|
|
||||||
if (env.CF_APP == 'notify-api-db-migration') {
|
|
||||||
sh "CF_SPACE=${cf_space} make cf-deploy-api-db-migration-with-docker"
|
|
||||||
} else {
|
|
||||||
sh "CF_SPACE=${cf_space} make cf-deploy-with-docker"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(err) {
|
|
||||||
currentBuild.result = 'FAILURE'
|
|
||||||
echo "PaaS deployment to ${cf_space} failed: ${err}"
|
|
||||||
try {
|
|
||||||
slackSend channel: '#govuk-notify', message: "PaaS deployment to ${cf_space} failed: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'danger'
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending Slack message failed: ${err2}"
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
stage('Post-build') {
|
|
||||||
if (cf_space == 'production') {
|
|
||||||
try {
|
|
||||||
slackSend channel: '#govuk-notify', message: "PaaS deployment to ${cf_space} finished: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'good'
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending Slack message failed: ${err2}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'notify-support+jenkins@digital.cabinet-office.gov.uk', sendToIndividuals: false])
|
|
||||||
} catch(err2) {
|
|
||||||
echo "Sending email failed: ${err2}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
10
Makefile
10
Makefile
@@ -99,9 +99,19 @@ build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy
|
|||||||
|
|
||||||
.PHONY: upload-codedeploy-artifact ## Upload the deploy artifact for CodeDeploy
|
.PHONY: upload-codedeploy-artifact ## Upload the deploy artifact for CodeDeploy
|
||||||
upload-codedeploy-artifact: check-env-vars
|
upload-codedeploy-artifact: check-env-vars
|
||||||
|
$(if ${DEPLOY_BUILD_NUMBER},,$(error Must specify DEPLOY_BUILD_NUMBER))
|
||||||
aws s3 cp --region eu-west-1 --sse AES256 target/notifications-api.zip s3://${DNS_NAME}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip
|
aws s3 cp --region eu-west-1 --sse AES256 target/notifications-api.zip s3://${DNS_NAME}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip
|
||||||
aws s3 cp --region eu-west-1 --sse AES256 target/notifications-api-db-migration.zip s3://${DNS_NAME}-codedeploy/notifications-api-db-migration-${DEPLOY_BUILD_NUMBER}.zip
|
aws s3 cp --region eu-west-1 --sse AES256 target/notifications-api-db-migration.zip s3://${DNS_NAME}-codedeploy/notifications-api-db-migration-${DEPLOY_BUILD_NUMBER}.zip
|
||||||
|
|
||||||
|
.PHONY: build-paas-artifact
|
||||||
|
build-paas-artifact: build-codedeploy-artifact ## Build the deploy artifact for PaaS
|
||||||
|
|
||||||
|
.PHONY: upload-paas-artifact ## Upload the deploy artifact for PaaS
|
||||||
|
upload-paas-artifact:
|
||||||
|
$(if ${DEPLOY_BUILD_NUMBER},,$(error Must specify DEPLOY_BUILD_NUMBER))
|
||||||
|
$(if ${JENKINS_S3_BUCKET},,$(error Must specify JENKINS_S3_BUCKET))
|
||||||
|
aws s3 cp --region eu-west-1 --sse AES256 target/notifications-api.zip s3://${JENKINS_S3_BUCKET}/build/notifications-api/${DEPLOY_BUILD_NUMBER}.zip
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: venv generate-version-file ## Run tests
|
test: venv generate-version-file ## Run tests
|
||||||
./scripts/run_tests.sh
|
./scripts/run_tests.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user