Skip to content

Commit

Permalink
Merge pull request #957 from cultuurnet/feature/III-6418
Browse files Browse the repository at this point in the history
Update build and deploy configuration for Ubuntu 20.04
  • Loading branch information
willaerk authored Nov 26, 2024
2 parents fef547a + b27ab61 commit bb3dda5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 65 deletions.
34 changes: 17 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline {
}

stage('Setup and build') {
agent { label 'ubuntu && 16.04 && nodejs16' }
agent { label 'ubuntu && 20.04 && nodejs16' }
environment {
GIT_SHORT_COMMIT = build.shortCommitRef()
ARTIFACT_VERSION = "${env.PIPELINE_VERSION}" + '+sha.' + "${env.GIT_SHORT_COMMIT}"
Expand All @@ -28,12 +28,12 @@ pipeline {
}
stage('Build') {
steps {
sh label: 'Build binaries', script: 'bundle exec rake uitdatabank-frontend:build'
sh label: 'Build binaries', script: 'bundle exec rake build'
}
}
stage('Build artifact') {
steps {
sh label: 'Build artifact', script: "bundle exec rake uitdatabank-frontend:build_artifact ARTIFACT_VERSION=${env.ARTIFACT_VERSION}"
sh label: 'Build artifact', script: "bundle exec rake build_artifact ARTIFACT_VERSION=${env.ARTIFACT_VERSION}"
archiveArtifacts artifacts: "pkg/*${env.ARTIFACT_VERSION}*.deb", onlyIfSuccessful: true
}
}
Expand Down Expand Up @@ -67,59 +67,59 @@ pipeline {
APPLICATION_ENVIRONMENT = 'development'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'xenial'
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
}
}

stage('Deploy to acceptance') {
agent any
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'acceptance'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'xenial'
triggerDeployment nodeName: 'udb3-web-acc02', timeout: 600
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
triggerDeployment nodeName: 'uitdatabank-web-acc01', timeout: 600
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
}
}

stage('Deploy to testing') {
input { message "Deploy to Testing?" }
agent any
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'testing'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'xenial'
triggerDeployment nodeName: 'udb3-web-test03', timeout: 600
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
triggerDeployment nodeName: 'uitdatabank-web-test01', timeout: 600
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
}
}

stage('Deploy to production') {
input { message "Deploy to Production?" }
agent any
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'production'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'xenial'
triggerDeployment nodeName: 'udb3-web-prod03', timeout: 600
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
triggerDeployment nodeName: 'uitdatabank-web-prod01', timeout: 600
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
cleanup {
cleanupAptlySnapshots repository: env.REPOSITORY_NAME
Expand All @@ -128,7 +128,7 @@ pipeline {
}

stage('Tag release') {
agent { label 'ubuntu && 16.04' }
agent any
steps {
copyArtifacts filter: 'pkg/*.deb', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
tagRelease commitHash: artifact.metadata(artifactFilter: '*.deb', field: 'git-ref')
Expand Down
7 changes: 7 additions & 0 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
desc "Build binaries"
task :build do |task|
system('yarn install') or exit 1
system('yarn build') or exit 1
system('rm -rf node_modules') or exit 1
system('yarn install --production') or exit 1
end
34 changes: 34 additions & 0 deletions lib/tasks/build_artifact.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
desc "Create a debian package from the binaries."
task :build_artifact do |task|

calver_version = ENV['PIPELINE_VERSION'].nil? ? Time.now.strftime("%Y.%m.%d.%H%M%S") : ENV['PIPELINE_VERSION']
git_short_ref = `git rev-parse --short HEAD`.strip
version = ENV['ARTIFACT_VERSION'].nil? ? "#{calver_version}+sha.#{git_short_ref}" : ENV['ARTIFACT_VERSION']
artifact_name = 'uitdatabank-frontend'
vendor = 'publiq VZW'
maintainer = 'Infra publiq <[email protected]>'
license = 'Apache-2.0'
description = 'Frontend for UiTdatabank'
source = 'https://github.com/cultuurnet/udb3-frontend'
build_url = ENV['JOB_DISPLAY_URL'].nil? ? '' : ENV['JOB_DISPLAY_URL']

FileUtils.mkdir_p('pkg')

system('touch .env') or exit 1

system("fpm -s dir -t deb -n #{artifact_name} -v #{version} -a all -p pkg \
-x '.git*' -x pkg -x vendor -x lib -x Rakefile -x Gemfile -x Gemfile.lock \
-x .bundle -x 'Jenkinsfile*' \
--prefix /var/www/udb3-frontend \
--config-files /var/www/udb3-frontend/.env \
--deb-systemd lib/tasks/uitdatabank-frontend.service \
--before-remove lib/tasks/prerm \
--deb-user www-data --deb-group www-data \
--description '#{description}' --url '#{source}' --vendor '#{vendor}' \
--license '#{license}' -m '#{maintainer}' \
--deb-field 'Pipeline-Version: #{calver_version}' \
--deb-field 'Git-Ref: #{git_short_ref}' \
--deb-field 'Build-Url: #{build_url}' \
."
) or exit 1
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
User=www-data
Group=www-data
PIDFile=/var/run/udb3-frontend.pid
Environment=NEXT_HOST=localhost
PIDFile=/var/run/uitdatabank-frontend.pid
Environment=NEXT_HOST=127.0.0.1
Environment=NEXT_PORT=4000
EnvironmentFile=-/etc/default/udb3-frontend
EnvironmentFile=-/etc/default/uitdatabank-frontend
WorkingDirectory=/var/www/udb3-frontend
ExecStart=/usr/bin/node node_modules/next/dist/bin/next start -H ${NEXT_HOST} -p ${NEXT_PORT}
Restart=on-failure
Expand Down
9 changes: 0 additions & 9 deletions lib/tasks/uitdatabank-frontend/build.rake

This file was deleted.

36 changes: 0 additions & 36 deletions lib/tasks/uitdatabank-frontend/build_artifact.rake

This file was deleted.

0 comments on commit bb3dda5

Please sign in to comment.