From cb8642cc13849b9a7469e903cdc30d49485f2bf1 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 4 May 2021 13:23:10 +0300 Subject: [PATCH] switched to external scripts --- .../src/main/java/buildjob/PlanSpec.java | 28 +-- .../src/main/resources/scripts/build.sh | 30 +++ .../main/resources/scripts/update-version.sh | 12 + .../src/test/java/buildjob/PlanSpecTest.java | 4 +- package.json | 208 +++++++++--------- 5 files changed, 159 insertions(+), 123 deletions(-) create mode 100644 bamboo-specs/src/main/resources/scripts/build.sh create mode 100644 bamboo-specs/src/main/resources/scripts/update-version.sh diff --git a/bamboo-specs/src/main/java/buildjob/PlanSpec.java b/bamboo-specs/src/main/java/buildjob/PlanSpec.java index 32e9c1337..6ecb91786 100644 --- a/bamboo-specs/src/main/java/buildjob/PlanSpec.java +++ b/bamboo-specs/src/main/java/buildjob/PlanSpec.java @@ -20,6 +20,7 @@ import com.atlassian.bamboo.specs.builders.task.TestParserTask; import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask; import com.atlassian.bamboo.specs.builders.task.VcsCommitTask; import com.atlassian.bamboo.specs.builders.trigger.BitbucketServerTrigger; +import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties; import com.atlassian.bamboo.specs.util.BambooServer; /** @@ -77,17 +78,13 @@ public class PlanSpec { return new Job("Build Job: " + project, new BambooKey(project.toUpperCase().replaceAll("-", ""))).tasks( new VcsCheckoutTask().description("Checkout Default Repository") .checkoutItems(new CheckoutItem().defaultRepository()), new ScriptTask().description("Build") - .inlineBody( - "#!/bin/bash\n" + "set -e\n" + "imageName=\"nexus.iqser.com:5001/red/" + project + "\"\n" - + "dockerfileLocation=\"docker/" + project + "/Dockerfile\"\n" - + "docker build -t ${imageName}:latest -f ${dockerfileLocation} .\n" - + "if [[ \"${bamboo.planRepository.branchName}\" == \"master\" ]]\n" + "then\n" - + " ./versions.sh patch\n" + " version=$(cat package.json | jq -r '.version')\n" - + " echo \"Publishing Images with version $version\"\n" - + " echo ${bamboo.bamboo_download_pass} | docker login -u ${bamboo.bamboo_download_user} --password-stdin nexus.iqser.com:5001\n" - + " docker push ${imageName}:latest\n" - + " docker tag ${imageName}:latest ${imageName}:${version}\n" - + " docker push ${imageName}:${version}\n" + "fi\n")).dockerConfiguration( + .location(ScriptTaskProperties.Location.FILE) + .fileFromPath("bamboo-specs/src/main/resources/scripts/build.sh") + .environmentVariables("BAMBOO_DOWNLOAD_PASS=\"${bamboo.bamboo_download_pass}\"") + .environmentVariables("BAMBOO_DOWNLOAD_USER=\"${bamboo.bamboo_download_user}\"") + .environmentVariables("BRANCH_NAME=\"${bamboo.planRepository.branchName}\"") + .environmentVariables("PROJECT=\"" + project + "\"") + ).dockerConfiguration( new DockerConfiguration().image("nexus.iqser.com:5001/infra/release_build:2.9.1") .volume("/var/run/docker.sock", "/var/run/docker.sock")); } @@ -96,12 +93,9 @@ public class PlanSpec { return new Job("Upstream Push", new BambooKey("USPSH")).tasks( new VcsCheckoutTask().description("Checkout Default Repository") .checkoutItems(new CheckoutItem().defaultRepository()), new ScriptTask().description("Build") - .inlineBody( - "#!/bin/bash\n" - + "set -e\n" - + "if [[ \"${bamboo.planRepository.branchName}\" == \"master\" ]]\n" - + "then\n" - + " ./versions.sh patch\n" + "fi\n"), + .location(ScriptTaskProperties.Location.FILE) + .fileFromPath("bamboo-specs/src/main/resources/scripts/update-version.sh") + .environmentVariables("BRANCH_NAME=\"${bamboo.planRepository.branchName}\""), new VcsCommitTask().commitMessage("chore(release)").repository("RED / ui")).dockerConfiguration( new DockerConfiguration().image("nexus.iqser.com:5001/infra/release_build:2.9.1") .volume("/var/run/docker.sock", "/var/run/docker.sock")); diff --git a/bamboo-specs/src/main/resources/scripts/build.sh b/bamboo-specs/src/main/resources/scripts/build.sh new file mode 100644 index 000000000..60c811ef8 --- /dev/null +++ b/bamboo-specs/src/main/resources/scripts/build.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +imageName="nexus.iqser.com:5001/red/$PROJECT" +dockerfileLocation="docker/$PROJECT/Dockerfile" + +docker build -t "${imageName}":latest -f "${dockerfileLocation}" . + +# shellcheck disable=SC2154 +if [[ "${BRANCH_NAME}" == "master" ]] +then + ./versions.sh minor + version=$(jq -r '.version' < package.json) +fi + + +if [[ "${BRANCH_NAME}" == release* ]] +then + ./versions.sh patch + version=$(jq -r '.version' < package.json) +fi + + +if [[ -n ${version+z} ]] +then + echo "Publishing Images with version $version" + echo "${BAMBOO_DOWNLOAD_PASS} | docker login -u ${BAMBOO_DOWNLOAD_USER} --password-stdin nexus.iqser.com:5001" + docker push "${imageName}":latest + docker tag "${imageName}":latest "${imageName}":"${version}" + docker push "${imageName}":"${version}" +fi diff --git a/bamboo-specs/src/main/resources/scripts/update-version.sh b/bamboo-specs/src/main/resources/scripts/update-version.sh new file mode 100644 index 000000000..86735e403 --- /dev/null +++ b/bamboo-specs/src/main/resources/scripts/update-version.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [[ "${BRANCH_NAME}" == "master" ]] +then + ./versions.sh minor +fi + + +if [[ "${BRANCH_NAME}" == release* ]] +then + ./versions.sh patch +fi diff --git a/bamboo-specs/src/test/java/buildjob/PlanSpecTest.java b/bamboo-specs/src/test/java/buildjob/PlanSpecTest.java index fada379d8..48e728822 100644 --- a/bamboo-specs/src/test/java/buildjob/PlanSpecTest.java +++ b/bamboo-specs/src/test/java/buildjob/PlanSpecTest.java @@ -7,10 +7,10 @@ import com.atlassian.bamboo.specs.api.util.EntityPropertiesBuilders; import org.junit.Test; public class PlanSpecTest { + @Test public void checkYourPlanOffline() throws PropertiesValidationException { Plan plan = new PlanSpec().createDockerBuildPlan(); - EntityPropertiesBuilders.build(plan); } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 9885d3509..d7479e1e2 100644 --- a/package.json +++ b/package.json @@ -1,107 +1,107 @@ { - "name": "redaction", - "version": "1.0.113", - "private": true, - "license": "MIT", - "scripts": { - "affected": "nx affected", - "affected:apps": "nx affected:apps", - "affected:build": "nx affected:build", - "affected:dep-graph": "nx affected:dep-graph", - "affected:e2e": "nx affected:e2e", - "affected:libs": "nx affected:libs", - "affected:lint": "nx affected:lint", - "affected:test": "nx affected:test", - "build": "nx build", - "build-lint-all": "ng lint --project=red-ui-http --fix && ng build --project=red-ui-http && ng lint --project=red-ui --fix && ng build --project=red-ui --prod", - "dep-graph": "nx dep-graph", - "e2e": "nx e2e", - "format": "nx format:write", - "format:check": "nx format:check", - "format:write": "nx format:write", - "help": "nx help", - "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", - "lint": "nx workspace-lint && nx lint", - "nx": "nx", - "start": "nx serve", - "test": "nx test", - "update": "nx migrate latest", - "workspace-schematic": "nx workspace-schematic" - }, - "husky": { - "hooks": { - "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix" + "name": "redaction", + "version": "2.0.0", + "private": true, + "license": "MIT", + "scripts": { + "affected": "nx affected", + "affected:apps": "nx affected:apps", + "affected:build": "nx affected:build", + "affected:dep-graph": "nx affected:dep-graph", + "affected:e2e": "nx affected:e2e", + "affected:libs": "nx affected:libs", + "affected:lint": "nx affected:lint", + "affected:test": "nx affected:test", + "build": "nx build", + "build-lint-all": "ng lint --project=red-ui-http --fix && ng build --project=red-ui-http && ng lint --project=red-ui --fix && ng build --project=red-ui --prod", + "dep-graph": "nx dep-graph", + "e2e": "nx e2e", + "format": "nx format:write", + "format:check": "nx format:check", + "format:write": "nx format:write", + "help": "nx help", + "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", + "lint": "nx workspace-lint && nx lint", + "nx": "nx", + "start": "nx serve", + "test": "nx test", + "update": "nx migrate latest", + "workspace-schematic": "nx workspace-schematic" + }, + "husky": { + "hooks": { + "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix" + } + }, + "dependencies": { + "@angular/animations": "~11.0.1", + "@angular/cdk": "~11.0.1", + "@angular/common": "~11.0.1", + "@angular/compiler": "~11.0.1", + "@angular/core": "~11.0.1", + "@angular/forms": "~11.0.1", + "@angular/material": "~11.0.1", + "@angular/material-moment-adapter": "^11.0.2", + "@angular/platform-browser": "~11.0.1", + "@angular/platform-browser-dynamic": "~11.0.1", + "@angular/router": "~11.0.1", + "@angular/service-worker": "~11.0.1", + "@ngx-translate/core": "^13.0.0", + "@ngx-translate/http-loader": "^6.0.0", + "@nrwl/angular": "^10.2.0", + "@pdftron/webviewer": "7.3.0-20210223", + "@swimlane/ngx-charts": "^17.0.0", + "file-saver": "^2.0.2", + "jwt-decode": "^3.0.0", + "keycloak-angular": "^8.0.1", + "keycloak-js": "10.0.2", + "lint-staged": "^10.5.0", + "ng2-ace-editor": "^0.3.9", + "ngx-color-picker": "^10.1.0", + "ngx-toastr": "^13.0.0", + "papaparse": "^5.3.0", + "rxjs": "~6.6.0", + "scroll-into-view-if-needed": "^2.2.26", + "streamsaver": "^2.0.5", + "tslib": "^2.0.0", + "zone.js": "~0.10.2" + }, + "devDependencies": { + "@angular-devkit/build-angular": "~0.1100.2", + "@angular-devkit/build-ng-packagr": "~0.1002.0", + "@angular/cli": "~11.0.2", + "@angular/compiler": "~11.0.1", + "@angular/compiler-cli": "~11.0.1", + "@angular/language-service": "~11.0.2", + "@nrwl/cypress": "10.2.0", + "@nrwl/jest": "10.2.0", + "@nrwl/workspace": "10.2.0", + "@types/cypress": "^1.1.3", + "@types/jasmine": "~3.6.0", + "@types/jest": "26.0.8", + "@types/node": "^12.11.1", + "codelyzer": "^6.0.0", + "cypress": "^5.6.0", + "cypress-file-upload": "^4.1.1", + "cypress-keycloak": "^1.5.0", + "cypress-keycloak-commands": "^1.2.0", + "cypress-localstorage-commands": "^1.2.4", + "dotenv": "6.2.0", + "eslint": "6.8.0", + "google-translate-api-browser": "^1.1.71", + "husky": "^4.3.0", + "jest": "26.2.2", + "jest-preset-angular": "8.2.1", + "lodash": "^4.17.20", + "moment": "^2.29.1", + "ng-packagr": "^10.1.2", + "prettier": "2.0.4", + "pretty-quick": "^3.1.0", + "superagent": "^6.1.0", + "superagent-promise": "^1.1.0", + "ts-jest": "26.1.4", + "ts-node": "~8.3.0", + "tslint": "~6.1.0", + "typescript": "~4.0.2" } - }, - "dependencies": { - "@angular/animations": "~11.0.1", - "@angular/cdk": "~11.0.1", - "@angular/common": "~11.0.1", - "@angular/compiler": "~11.0.1", - "@angular/core": "~11.0.1", - "@angular/forms": "~11.0.1", - "@angular/material": "~11.0.1", - "@angular/material-moment-adapter": "^11.0.2", - "@angular/platform-browser": "~11.0.1", - "@angular/platform-browser-dynamic": "~11.0.1", - "@angular/router": "~11.0.1", - "@angular/service-worker": "~11.0.1", - "@ngx-translate/core": "^13.0.0", - "@ngx-translate/http-loader": "^6.0.0", - "@nrwl/angular": "^10.2.0", - "@pdftron/webviewer": "7.3.0-20210223", - "@swimlane/ngx-charts": "^17.0.0", - "file-saver": "^2.0.2", - "jwt-decode": "^3.0.0", - "keycloak-angular": "^8.0.1", - "keycloak-js": "10.0.2", - "lint-staged": "^10.5.0", - "ng2-ace-editor": "^0.3.9", - "ngx-color-picker": "^10.1.0", - "ngx-toastr": "^13.0.0", - "papaparse": "^5.3.0", - "rxjs": "~6.6.0", - "scroll-into-view-if-needed": "^2.2.26", - "streamsaver": "^2.0.5", - "tslib": "^2.0.0", - "zone.js": "~0.10.2" - }, - "devDependencies": { - "@angular-devkit/build-angular": "~0.1100.2", - "@angular-devkit/build-ng-packagr": "~0.1002.0", - "@angular/cli": "~11.0.2", - "@angular/compiler": "~11.0.1", - "@angular/compiler-cli": "~11.0.1", - "@angular/language-service": "~11.0.2", - "@nrwl/cypress": "10.2.0", - "@nrwl/jest": "10.2.0", - "@nrwl/workspace": "10.2.0", - "@types/cypress": "^1.1.3", - "@types/jasmine": "~3.6.0", - "@types/jest": "26.0.8", - "@types/node": "^12.11.1", - "codelyzer": "^6.0.0", - "cypress": "^5.6.0", - "cypress-file-upload": "^4.1.1", - "cypress-keycloak": "^1.5.0", - "cypress-keycloak-commands": "^1.2.0", - "cypress-localstorage-commands": "^1.2.4", - "dotenv": "6.2.0", - "eslint": "6.8.0", - "google-translate-api-browser": "^1.1.71", - "husky": "^4.3.0", - "jest": "26.2.2", - "jest-preset-angular": "8.2.1", - "lodash": "^4.17.20", - "moment": "^2.29.1", - "ng-packagr": "^10.1.2", - "prettier": "2.0.4", - "pretty-quick": "^3.1.0", - "superagent": "^6.1.0", - "superagent-promise": "^1.1.0", - "ts-jest": "26.1.4", - "ts-node": "~8.3.0", - "tslint": "~6.1.0", - "typescript": "~4.0.2" - } }