diff --git a/deploy/ci/console-dev-releases.yml b/deploy/ci/console-dev-releases.yml index 5feec9e486..ef7e39e757 100644 --- a/deploy/ci/console-dev-releases.yml +++ b/deploy/ci/console-dev-releases.yml @@ -81,13 +81,34 @@ jobs: params: file: image-tag/*.tar acl: public-read -- name: build-images +- name: check-github plan: - get: stratos passed: [generate-tag-files] trigger: true - get: image-tag - passed: [generate-tag-files] + passed: [generate-tag-files] + params: + unpack: true + - do: + - task: build + privileged: true + timeout: 30m + file: stratos/deploy/ci/tasks/dev-releases/check-gh-release.yml + params: + GITHUB_TOKEN: ((github-access-token)) + GITHUB_USER: ((helm-repo-github-organization)) + GITHUB_REPO: ((helm-repo-github-repository)) + GIT_USER: ((concourse-user)) + GIT_EMAIL: ((concourse-email)) + GIT_PRIVATE_KEY: ((github-private-key)) +- name: build-images + plan: + - get: stratos + passed: [check-github] + trigger: true + - get: image-tag + passed: [check-github] params: unpack: true - aggregate: diff --git a/deploy/ci/console-make-release.yml b/deploy/ci/console-make-release.yml index 5aa0a7d62b..bc86588195 100644 --- a/deploy/ci/console-make-release.yml +++ b/deploy/ci/console-make-release.yml @@ -68,9 +68,16 @@ jobs: GITHUB_REPO: ((helm-repo-github-repository)) GITHUB_TOKEN: ((github-access-token)) GIT_PRIVATE_KEY: ((github-private-key)) - GITHUB_TOKEN: ((github-access-token)) DOCKER_ORG: ((docker-organization)) DOCKER_REGISTRY: ((docker-registry)) HELM_REPO_PATH: ((helm-repo-path)) HELM_REPO_BRANCH: ((helm-repo-branch)) - + SOURCE_REPO_ORG: ((stratos-repository-organization)) + SOURCE_REPO_REPO: ((stratos-repository)) + HELM_MIRROR_BASE_URL: ((web-server-base-url)) + HELM_RELEASE_GITCLONE: ((release-helm-repo)) + HELM_RELEASE_REPO_NAME: ((release-helm-repo-name)) + HELM_RELEASE_REPO_BRANCH: ((release-helm-repo-branch)) + HELM_RELEASE_REPO_FOLDER: ((release-helm-stable-folder)) + HELM_RELEASE_REGISTRY_HOST: ((release-repository)) + HELM_RELEASE_REGISTRY_ORG: ((release-repository-organization)) diff --git a/deploy/ci/tasks/dev-releases/check-gh-release.yml b/deploy/ci/tasks/dev-releases/check-gh-release.yml new file mode 100644 index 0000000000..84529c8419 --- /dev/null +++ b/deploy/ci/tasks/dev-releases/check-gh-release.yml @@ -0,0 +1,45 @@ +--- +platform: linux +inputs: +- name: stratos +- name: image-tag +image_resource: + type: docker-image + source: + # Generated using scripts/Dockerfile.stratos-ci + repository: splatform/stratos-ci-concourse + tag: "latest" + +run: + path: sh + args: + - -exc + - | + # Check that the Github release DOES NOT exist + ROOT_DIR=${PWD} + VERSION=$(cat image-tag/v2-version) + FULL_VERSION=$(cat image-tag/v2-alpha-tag) + GIT_TAG=$(cat image-tag/v2-tag) + STRATOS=${ROOT_DIR}/stratos + source ${STRATOS}/deploy/ci/tasks/dev-releases/github-helper.sh + + # Check tagged release version is consistent with package.json version + TAG_RELEASE_VERSION=$(echo ${FULL_VERSION} | cut -d"-" -f1) + if [ "${TAG_RELEASE_VERSION}" != "${VERSION}" ]; then + echo "Package.json version is not consistent with tag release version! ${TAG_RELEASE_VERSION} != ${VERSION}" + exit 1 + fi + cd ${ROOT_DIR}/stratos + + # Check that the release exists + set +e + github-release info -t ${GIT_TAG} + RETVAL=$? + set -e + + if [ $RETVAL -eq 0 ]; then + echo "Aborting... release already exists" + exit 1 + fi + + echo "Release does not exist.. OK" diff --git a/deploy/ci/tasks/dev-releases/generate-tag-files.yml b/deploy/ci/tasks/dev-releases/generate-tag-files.yml index f79c7ca43a..7e3876cc8e 100644 --- a/deploy/ci/tasks/dev-releases/generate-tag-files.yml +++ b/deploy/ci/tasks/dev-releases/generate-tag-files.yml @@ -63,13 +63,13 @@ run: echo "Created v2-alpha-tag, v2-version and build-args." - echo "Contens of build-args:" + echo "Contents of build-args:" cat build-args - echo "Contens of ui-build-args:" + echo "Contents of ui-build-args:" cat ui-build-args - echo "Contens of v2-alpha-tag:" + echo "Contents of v2-alpha-tag:" cat v2-alpha-tag echo "Creating tag file tar..." diff --git a/deploy/ci/tasks/dev-releases/make-release.yml b/deploy/ci/tasks/dev-releases/make-release.yml index 6568df36fc..5038d47954 100644 --- a/deploy/ci/tasks/dev-releases/make-release.yml +++ b/deploy/ci/tasks/dev-releases/make-release.yml @@ -4,6 +4,8 @@ inputs: - name: stratos - name: image-tag - name: helm-repo +outputs: +- name: helm-chart image_resource: type: docker-image source: @@ -21,6 +23,9 @@ run: STRATOS=${ROOT_DIR}/stratos source ${STRATOS}/deploy/ci/tasks/dev-releases/create-chart-helper.sh source ${STRATOS}/deploy/ci/tasks/dev-releases/github-helper.sh + + SOURCE_REPO=${SOURCE_REPO_ORG}/${SOURCE_REPO_REPO} + ARTIFACT_REPO=${GITHUB_ORG}/${GITHUB_REPO} HELM_REPO=${ROOT_DIR}/helm-repo/${HELM_REPO_PATH} GIT_TAG=$(cat image-tag/v2-alpha-tag) @@ -32,8 +37,10 @@ run: cd ${ROOT_DIR}/stratos - # Set git username and password so that we can push changes + # Set git username and password so that we can push changes (Don't log) + set +x setupGitConfig + set -x # $VERSION is version number - e.g. 2.3.0 # Find the last tag created for this release tag @@ -51,6 +58,16 @@ run: echo "Making release" + # Check to see if the release tag already exists - if so, abort - we won't re-release + set +e + github-release info -t ${VERSION} + RETVAL=$? + set -e + if [ $RETVAL -eq 0 ]; then + echo "Release already exists... aborting" + exit 1 + fi + # Delete Stable release on GitHub and recreate it again # This ensures it has the correct date/time and appears in the correct place in the release history @@ -87,6 +104,9 @@ run: HELM_FILE=console-helm-chart-${VERSION}-${COMMIT}.tgz helm package console cp console*.tgz ${ROOT_DIR}/helm-chart/${HELM_FILE} + + # Temp folder for helm-chart + mkdir -p ${ROOT_DIR}/helm-chart # Add helm chart to the helm repository cd ${ROOT_DIR}/helm-chart/ @@ -99,7 +119,9 @@ run: helm repo index ./ ${MERGE_INDEX} --url https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases/download/${RELEASE_VERSION}/ cp index.yaml ${HELM_REPO} cd ${HELM_REPO} + set +x setupAndPushChange + set -x # Tag the repo and create the release on GitHub cd ${ROOT_DIR}/stratos @@ -131,13 +153,76 @@ run: github-release release -t ${VERSION} --name "${RELEASE_TITLE}" ${PRE_RELEASE_ARG} --description "${RELEASE_DESCRIPTION}" # Upload Helm chart to release - github-release upload -t ${VERSION} --file ./tmp/${HELM_FILE} --name "${HELM_FILE}" + github-release upload -t ${VERSION} --file ${ROOT_DIR}/helm-chart/${HELM_FILE} --name "${HELM_FILE}" + + # Create a release if the source repo is not the same as the helm repo + if [ "${SOURCE_REPO}" != "${ARTIFACT_REPO}" ]; then + echo "Creating release in GitHub Repository: ${SOURCE_REPO}" + # Create new release in the source repository + github-release release --user ${SOURCE_REPO_ORG} --repo ${SOURCE_REPO_REPO} -t ${VERSION} --name "${RELEASE_TITLE}" ${PRE_RELEASE_ARG} --description "${RELEASE_DESCRIPTION}" + fi + + # Create the PR for the Helm Chart changes if configured + if [ ! -z "${HELM_RELEASE_GITCLONE}" ]; then + echo "Creating PR for Helm Chart Changes for this release" + + NEW_BRANCH="stratos-${VERSION}" + + mkdir -p ${ROOT_DIR}/helm-pr + cd ${ROOT_DIR}/helm-pr + git clone ${HELM_RELEASE_GITCLONE} helm-git-repo + cd helm-git-repo + git checkout ${HELM_RELEASE_REPO_BRANCH} + git checkout -b ${NEW_BRANCH} + cd ${HELM_RELEASE_REPO_FOLDER} + cp ${ROOT_DIR}/helm-chart/${HELM_FILE} . + tar -xvf ${HELM_FILE} + + # Patch the registry hostname and org if needed + if [ ! -z "${HELM_RELEASE_REGISTRY_HOST}" ]; then + echo "Patching Helm Chart Docker Registry and Organisation" + cat ./console/values.yaml + sed -i -e 's/hostname: '"${DOCKER_REGISTRY}"'/hostname: '"${HELM_RELEASE_REGISTRY_HOST}"'/g' ./console/values.yaml + sed -i -e 's/organization: '"${DOCKER_ORG}"'/organization: '"${HELM_RELEASE_REGISTRY_ORG}"'/g' ./console/values.yaml + echo "Updated Chart..." + cat ./console/values.yaml + fi + + rm -rf ./${HELM_FILE} + git add -A + git status + git commit -m "Stratos Release ${VERSION} Helm Chart Changes" + git push -u origin ${NEW_BRANCH} + + # Now create a PR for the changes + URL=https://api.github.com/repos/${HELM_RELEASE_REPO_NAME}/pulls + TITLE="Stratos Release ${VERSION}" + + curl --fail -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_TOKEN}" \ + -d '{"title":"'"${TITLE}"'", "head": "'"${NEW_BRANCH}"'", "base": "'"${HELM_RELEASE_REPO_BRANCH}"'"}' ${URL} + fi set +e + set +x - echo "RELEASE COMPLETE" + echo "==================================================================================================================" + echo "" + echo "RELEASE COMPLETE =================================================================================================" + echo "" echo "Version : ${VERSION}" echo "Base Version : ${LAST_TAG}" echo "" echo "Helm Chart filename : ${HELM_FILE}" echo "Helm Chart URL : https://github.com/${HELM_REPOSITORY}/releases/download/${VERSION}/${HELM_FILE}" + echo "" + echo "==================================================================================================================" + + # If we have a mirror URL for the Helm Chart then output that at the end + if [ ! -z "${HELM_MIRROR_BASE_URL}" ]; then + echo "" + echo "==================================================================================================================" + echo "Helm Chart will be mirrored to:" + echo "${HELM_MIRROR_BASE_URL}${HELM_FILE}" + echo "==================================================================================================================" + fi +