diff --git a/Jenkinsfile b/Jenkinsfile index d6b546a..80fc06c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,12 +28,12 @@ pipeline { } stage('Build') { steps { - sh label: 'Build binaries', script: 'bundle exec rake jwt-provider:build' + sh label: 'Build binaries', script: 'bundle exec rake build' } } stage('Build artifact') { steps { - sh label: 'Build artifact', script: "bundle exec rake jwt-provider: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 } } diff --git a/Jenkinsfile.uitidv1 b/Jenkinsfile.uitidv1 deleted file mode 100644 index ad817dc..0000000 --- a/Jenkinsfile.uitidv1 +++ /dev/null @@ -1,149 +0,0 @@ -pipeline { - agent none - - environment { - PIPELINE_VERSION = build.pipelineVersion() - REPOSITORY_NAME = 'uitdatabank-jwt-provider-uitidv1' - GIT_CHECKOUT_FOLDER = "jwt-provider-uitidv1" - } - - stages { - stage('Pre build') { - steps { - setBuildDisplayName to: env.PIPELINE_VERSION - sendBuildNotification() - } - } - - stage('Setup and build') { - agent { label 'ubuntu && 16.04 && php7.4' } - environment { - GIT_SHORT_COMMIT = build.shortCommitRef() - ARTIFACT_VERSION = "${env.PIPELINE_VERSION}" + '+sha.' + "${env.GIT_SHORT_COMMIT}" - } - stages { - stage('Setup') { - steps { - sh label: 'Install rubygems', script: 'bundle install --deployment' - } - } - // we need to combine build and build artifact because we checkout a tag. - // once checked out, the rake tasks no longer exist ... - stage('Build & Build artifact') { - steps { - withCredentials([sshUserPrivateKey(credentialsId: "git@jenkins.publiq.be", keyFileVariable: 'PRIVATE_KEY')]) { - sh label: 'Build & Build artifact', script: "bundle exec rake jwt-provider-uitidv1:build_artifact ARTIFACT_VERSION=${env.ARTIFACT_VERSION} GIT_CHECKOUT_FOLDER=${env.GIT_CHECKOUT_FOLDER} GIT_SSH_COMMAND='ssh -i \"${env.PRIVATE_KEY}\" -o StrictHostKeyChecking=no'" - archiveArtifacts artifacts: "${env.GIT_CHECKOUT_FOLDER}/pkg/*${env.ARTIFACT_VERSION}*.deb", onlyIfSuccessful: true - } - } - } - } - post { - cleanup { - cleanWs() - } - } - } - - stage('Upload artifact') { - agent any - options { skipDefaultCheckout() } - steps { - copyArtifacts filter: "${env.GIT_CHECKOUT_FOLDER}/pkg/*.deb", projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER) - uploadAptlyArtifacts artifacts: '*.deb', repository: env.REPOSITORY_NAME - createAptlySnapshot name: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", repository: env.REPOSITORY_NAME - } - post { - cleanup { - cleanWs() - } - } - } - - stage('Deploy to development') { - agent any - options { skipDefaultCheckout() } - environment { - APPLICATION_ENVIRONMENT = 'development' - } - steps { - publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'xenial' - } - } - - stage('Deploy to acceptance') { - agent any - 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' - } - post { - always { - sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*" - } - } - } - - stage('Deploy to testing') { - input { message "Deploy to Testing?" } - agent any - 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' - } - post { - always { - sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*" - } - } - } - - stage('Deploy to production') { - input { message "Deploy to Production?" } - agent any - 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' - } - post { - always { - sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${env.JOB_NAME} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*" - } - cleanup { - cleanupAptlySnapshots repository: env.REPOSITORY_NAME - } - } - } - - stage('Tag release') { - agent { label 'ubuntu && 16.04' } - steps { - copyArtifacts filter: "${env.GIT_CHECKOUT_FOLDER}/pkg/*.deb", projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER) - tagRelease commitHash: artifact.metadata(artifactFilter: '*.deb', field: 'git-ref') - } - post { - cleanup { - cleanWs() - } - } - } - } - - post { - always { - sendBuildNotification() - } - } -} diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake new file mode 100644 index 0000000..3f9b02f --- /dev/null +++ b/lib/tasks/build.rake @@ -0,0 +1,5 @@ +desc "Build binaries" +task :build do |task| + system('composer2 install --no-dev --ignore-platform-reqs --prefer-dist --optimize-autoloader') or exit 1 + FileUtils.rm('web/jwt-example.php', :force => true) +end diff --git a/lib/tasks/build_artifact.rake b/lib/tasks/build_artifact.rake new file mode 100644 index 0000000..7eb219e --- /dev/null +++ b/lib/tasks/build_artifact.rake @@ -0,0 +1,33 @@ +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-jwt-provider' + vendor = 'publiq VZW' + maintainer = 'Infra publiq ' + license = 'Apache-2.0' + description = 'JSON Web Token provider (via Auth0) for UiTDatabank 3' + source = 'https://github.com/cultuurnet/jwt-provider' + build_url = ENV['JOB_DISPLAY_URL'].nil? ? "" : ENV['JOB_DISPLAY_URL'] + + basedir = '/var/www/udb3-jwt-provider' + + FileUtils.mkdir_p('pkg') + FileUtils.touch('config.yml') + + system("fpm -s dir -t deb -n #{artifact_name} -v #{version} -a all -p pkg \ + -x '.git*' -x pkg -x config.dist.yml -x 'Gemfile*' -x Jenkinsfile -x .bundle -x vendor/bundle \ + --config-files #{basedir}/config.yml \ + --prefix #{basedir} \ + --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 diff --git a/lib/tasks/jwt-provider-uitidv1/build_artifact.rake b/lib/tasks/jwt-provider-uitidv1/build_artifact.rake deleted file mode 100644 index 97f2943..0000000 --- a/lib/tasks/jwt-provider-uitidv1/build_artifact.rake +++ /dev/null @@ -1,49 +0,0 @@ -require 'git' - -namespace 'jwt-provider-uitidv1' do - 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-jwt-provider-uitidv1' - vendor = 'publiq VZW' - maintainer = 'Infra publiq ' - license = 'Apache-2.0' - description = 'JSON Web Token provider for UiTDatabank 3' - source = 'https://github.com/cultuurnet/jwt-provider' - build_url = ENV['JOB_DISPLAY_URL'].nil? ? "" : ENV['JOB_DISPLAY_URL'] - - # git parameters - git_url = 'git@github.com:cultuurnet/jwt-provider' - git_tag = 'refs/tags/uitidv1' - git_checkout_folder = ENV['GIT_CHECKOUT_FOLDER'].nil? ? "jwt-provider-uitidv1" : ENV['GIT_CHECKOUT_FOLDER'] - - # clone the jwt-provider repo to a separate folder and checkout the uitidv1 git tag - g = Git.clone(git_url, git_checkout_folder) - g.checkout(git_tag) - - # change into the cloned jwt-provider folder - # build the software and the package - g.chdir do - system('composer2 install --no-dev --ignore-platform-reqs --prefer-dist --optimize-autoloader') or exit 1 - - FileUtils.mkdir_p('pkg') - FileUtils.touch('config.yml') - - system("fpm -s dir -t deb -n #{artifact_name} -v #{version} -a all -p pkg \ - -x '.git*' -x pkg -x config.dist.yml -x 'Gemfile*' -x Jenkinsfile -x .bundle -x vendor/bundle \ - --config-files /var/www/udb3-jwt-provider-uitidv1/config.yml \ - --prefix /var/www/udb3-jwt-provider-uitidv1 \ - --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 - end -end diff --git a/lib/tasks/jwt-provider/build.rake b/lib/tasks/jwt-provider/build.rake deleted file mode 100644 index b5d9965..0000000 --- a/lib/tasks/jwt-provider/build.rake +++ /dev/null @@ -1,7 +0,0 @@ -namespace 'jwt-provider' do - desc "Build binaries" - task :build do |task| - system('composer2 install --no-dev --ignore-platform-reqs --prefer-dist --optimize-autoloader') or exit 1 - FileUtils.rm('web/jwt-example.php', :force => true) - end -end diff --git a/lib/tasks/jwt-provider/build_artifact.rake b/lib/tasks/jwt-provider/build_artifact.rake deleted file mode 100644 index f0ee49f..0000000 --- a/lib/tasks/jwt-provider/build_artifact.rake +++ /dev/null @@ -1,33 +0,0 @@ -namespace 'jwt-provider' do - 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-jwt-provider' - vendor = 'publiq VZW' - maintainer = 'Infra publiq ' - license = 'Apache-2.0' - description = 'JSON Web Token provider (via Auth0) for UiTDatabank 3' - source = 'https://github.com/cultuurnet/jwt-provider' - build_url = ENV['JOB_DISPLAY_URL'].nil? ? "" : ENV['JOB_DISPLAY_URL'] - - FileUtils.mkdir_p('pkg') - FileUtils.touch('config.yml') - - system("fpm -s dir -t deb -n #{artifact_name} -v #{version} -a all -p pkg \ - -x '.git*' -x pkg -x config.dist.yml -x 'Gemfile*' -x Jenkinsfile -x .bundle -x vendor/bundle \ - --config-files /var/www/udb3-jwt-provider/config.yml \ - --prefix /var/www/udb3-jwt-provider \ - --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 -end