-
Notifications
You must be signed in to change notification settings - Fork 127
Sign and publish pipeline in Buildkite #1175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aed1851
19c8f7a
3433d87
cdbfbe6
2cbfce1
1f5be27
8475771
aeff851
c795a30
6005807
0ab3aca
8dc0cbe
d56742c
9924b03
72273b8
4219d2a
c06cde6
6d64c71
693d072
6e3b29d
acecf2f
0229dde
8b5086b
00d771e
340e69b
5e733e7
1e02593
b15e5d3
78e8fc1
5b1a596
1bbc052
f6153a2
3d7beb8
334ee6e
c7e7ada
4e8f311
a48db31
7f9fb9d
757ddf2
613f5c8
fa6b28e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source .buildkite/scripts/tooling.sh | ||
|
|
||
| with_kubernetes() { | ||
| mkdir -p ${WORKSPACE}/bin | ||
| retry 5 curl -sSLo ${WORKSPACE}/bin/kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64" | ||
| chmod +x ${WORKSPACE}/bin/kind | ||
| kind version | ||
| which kind | ||
|
|
||
| mkdir -p ${WORKSPACE}/bin | ||
| retry 5 curl -sSLo ${WORKSPACE}/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl" | ||
| chmod +x ${WORKSPACE}/bin/kubectl | ||
| kubectl version --client | ||
| which kubectl | ||
| } | ||
|
|
||
| with_go() { | ||
| mkdir -p ${WORKSPACE}/bin | ||
| retry 5 curl -sL -o ${WORKSPACE}/bin/gvm "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-linux-amd64" | ||
| chmod +x ${WORKSPACE}/bin/gvm | ||
| eval "$(gvm $(cat .go-version))" | ||
| go version | ||
| which go | ||
| } | ||
|
|
||
| with_docker_compose() { | ||
| mkdir -p ${WORKSPACE}/bin | ||
| retry 5 curl -SL -o ${WORKSPACE}/bin/docker-compose "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64" | ||
| chmod +x ${WORKSPACE}/bin/docker-compose | ||
| docker-compose version | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,20 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| WORKSPACE="$(pwd)" | ||
| TMP_FOLDER_TEMPLATE_BASE="tmp.elastic-package" | ||
|
|
||
| cleanup() { | ||
| echo "Deleting temporal files..." | ||
| cd ${WORKSPACE} | ||
| rm -rf ${TMP_FOLDER_TEMPLATE_BASE}.* | ||
| echo "Done." | ||
| } | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| export PATH="${WORKSPACE}/bin:${PATH}" | ||
|
|
||
| echo "Checking gsutil command..." | ||
| if ! command -v gsutil &> /dev/null ; then | ||
| echo "⚠️ gsutil is not installed" | ||
|
|
@@ -9,4 +23,146 @@ else | |
| echo "✅ gsutil is installed" | ||
| fi | ||
|
|
||
| gsutil help | ||
| source .buildkite/scripts/install_deps.sh | ||
| source .buildkite/scripts/tooling.sh | ||
|
|
||
| isAlreadyPublished() { | ||
| local packageZip=$1 | ||
|
|
||
| if curl -s --head https://package-storage.elastic.co/artifacts/packages/${packageZip} | grep -q "HTTP/2 200" ; then | ||
| echo "- Already published ${packageZip}" | ||
| return 0 | ||
| fi | ||
| echo "- Not published ${packageZip}" | ||
| return 1 | ||
| } | ||
|
|
||
| REPO_NAME=$(repoName "${BUILDKITE_REPO}") | ||
| BUILD_TAG="buildkite-${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_BUILD_NUMBER}" | ||
|
|
||
| REPO_BUILD_TAG="${REPO_NAME}/${BUILD_TAG}" | ||
|
|
||
| BUILD_PACKAGES_PATH="build/packages" | ||
| TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX" | ||
| JENKINS_TRIGGER_PATH=".buildkite/scripts/triggerJenkinsJob" | ||
| GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json" | ||
|
|
||
| ## Signing | ||
| INFRA_SIGNING_BUCKET_NAME='internal-ci-artifacts' | ||
| INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_SUBFOLDER="${REPO_BUILD_TAG}/signed-artifacts" | ||
| INFRA_SIGNING_BUCKET_ARTIFACTS_PATH="gs://${INFRA_SIGNING_BUCKET_NAME}/${REPO_BUILD_TAG}" | ||
| INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_PATH="gs://${INFRA_SIGNING_BUCKET_NAME}/${INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_SUBFOLDER}" | ||
|
|
||
| ## Publishing | ||
| PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH="gs://elastic-bekitzur-package-storage-internal/queue-publishing/${REPO_BUILD_TAG}" | ||
|
|
||
|
|
||
| google_cloud_auth_signing() { | ||
| local gsUtilLocation=$(mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE}) | ||
|
|
||
| local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME} | ||
| echo "${SIGNING_PACKAGES_GCS_CREDENTIALS_SECRET}" > ${secretFileLocation} | ||
|
|
||
| google_cloud_auth "${secretFileLocation}" | ||
|
|
||
| echo "${gsUtilLocation}" | ||
| } | ||
|
|
||
| google_cloud_auth_publishing() { | ||
| local gsUtilLocation=$(mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE}) | ||
|
|
||
| local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME} | ||
| echo "${PACKAGE_UPLOADER_GCS_CREDENTIALS_SECRET}" > ${secretFileLocation} | ||
|
|
||
| google_cloud_auth "${secretFileLocation}" | ||
|
|
||
| echo "${gsUtilLocation}" | ||
| } | ||
|
|
||
| signPackage() { | ||
| local package=${1} | ||
| local packageZip=$(basename ${package}) | ||
|
|
||
| local gsUtilLocation=$(google_cloud_auth_signing) | ||
|
|
||
| # upload zip package (trailing forward slashes are required) | ||
| echo "Upload package .zip file for signing ${package} to ${INFRA_SIGNING_BUCKET_ARTIFACTS_PATH}" | ||
| gsutil cp ${package} "${INFRA_SIGNING_BUCKET_ARTIFACTS_PATH}/" | ||
|
|
||
| echo "Trigger Jenkins job for signing package ${packageZip}" | ||
| pushd ${JENKINS_TRIGGER_PATH} > /dev/null | ||
|
|
||
| go run main.go \ | ||
| --jenkins-job sign \ | ||
| --folder ${INFRA_SIGNING_BUCKET_ARTIFACTS_PATH} | ||
|
|
||
| sleep 5 | ||
| popd > /dev/null | ||
|
|
||
| echo "Download signatures" | ||
| gsutil cp "${INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_PATH}/${packageZip}.asc" "${BUILD_PACKAGES_PATH}" | ||
|
|
||
| echo "Rename asc to sig" | ||
| for f in $(ls ${BUILD_PACKAGES_PATH}/*.asc); do | ||
| mv "$f" "${f%.asc}.sig" | ||
| done | ||
|
|
||
| ls -l "${BUILD_PACKAGES_PATH}" | ||
|
|
||
| echo "Removing temporal location ${gsUtilLocation}" | ||
| rm -r "${gsUtilLocation}" | ||
| } | ||
|
|
||
| publishPackage() { | ||
| local package=$1 | ||
| local packageZip=$(basename ${package}) | ||
|
|
||
| # create file with credentials | ||
| local gsUtilLocation=$(google_cloud_auth_publishing) | ||
|
|
||
| # upload files (trailing forward slashes are required) | ||
| echo "Upload package .zip file ${package} to ${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}" | ||
| gsutil cp ${package} "${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}/" | ||
| echo "Upload package .sig file ${package}.sig to ${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}" | ||
| gsutil cp ${package}.sig "${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}/" | ||
|
|
||
| echo "Trigger Jenkins job for publishing package ${packageZip}" | ||
| pushd ${JENKINS_TRIGGER_PATH} > /dev/null | ||
|
|
||
| go run main.go \ | ||
| --jenkins-job publish \ | ||
| --package "${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}/${packageZip}" \ | ||
| --signature "${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH}/${packageZip}.sig" | ||
jsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sleep 5 | ||
|
|
||
| popd > /dev/null | ||
|
|
||
| echo "Removing temporal location ${gsUtilLocation}" | ||
| rm -r "${gsUtilLocation}" | ||
| } | ||
|
|
||
| # Required to trigger Jenkins job | ||
| with_go | ||
|
|
||
| # download package artifact from previous step | ||
| mkdir -p "${BUILD_PACKAGES_PATH}" | ||
|
|
||
| buildkite-agent artifact download "${BUILD_PACKAGES_PATH}/*.zip" --step build-package . | ||
| echo "Show artifacts downloaded from previous step ${BUILD_PACKAGES_PATH}" | ||
| ls -l "${BUILD_PACKAGES_PATH}" | ||
|
|
||
| for package in $(ls ${BUILD_PACKAGES_PATH}/*.zip); do | ||
| echo "isAlreadyInstalled ${package}?" | ||
| packageZip=$(basename ${package}) | ||
| if isAlreadyPublished ${packageZip} ; then | ||
| echo "Skipping. ${packageZip} already published" | ||
| continue | ||
| fi | ||
|
|
||
| echo "Signing package ${packageZip}" | ||
| signPackage "${package}" | ||
|
|
||
| echo "Publishing package ${packageZip}" | ||
| publishPackage "${package}" | ||
| done | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will something like this pipeline work to publish packages from integrations repositories? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, something like this script would be the steps to be used/followed in integrations (iterating for each package defined) or other repositories like endpoint-package or apm-server. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| repoName() { | ||
| # Example of URL: git@github.com:acme-inc/my-project.git | ||
| local repoUrl=$1 | ||
|
|
||
| orgAndRepo=$(echo $repoUrl | cut -d':' -f 2) | ||
| echo "$(basename ${orgAndRepo} .git)" | ||
| } | ||
|
|
||
| google_cloud_auth() { | ||
| local keyFile=$1 | ||
|
|
||
| gcloud auth activate-service-account --key-file ${keyFile} 2> /dev/null | ||
|
|
||
| export GOOGLE_APPLICATIONS_CREDENTIALS=${secretFileLocation} | ||
| } | ||
|
|
||
| retry() { | ||
| local retries=$1 | ||
| shift | ||
|
|
||
| local count=0 | ||
| until "$@"; do | ||
| exit=$? | ||
| wait=$((2 ** count)) | ||
| count=$((count + 1)) | ||
| if [ $count -lt "$retries" ]; then | ||
| >&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." | ||
| sleep $wait | ||
| else | ||
| >&2 echo "Retry $count/$retries exited $exit, no more retries left." | ||
| return $exit | ||
| fi | ||
| done | ||
| return 0 | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to shared path and renamed variables