-
Notifications
You must be signed in to change notification settings - Fork 74
feat: add support for building the "release" Prometheus from source #940
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
Open
bwplotka
wants to merge
2
commits into
master
Choose a base branch
from
build-any-commit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,82 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script created a Prometheus binary to use in benchmarks and place it in $VOLUME/prometheus. | ||
| # It uses $REFERENCE variable to build or fetch the binary. | ||
| # If $USE_REGISTRY is set to "true" it uses the binary from the quay.io/prometheus/prometheus:${REFERENCE}, | ||
| # otherwise it builds it from source, from the given reference (PR number, branch or git SHA). | ||
|
|
||
| # Default values | ||
| DIR="/go/src/github.com/prometheus/prometheus" | ||
|
|
||
| if [[ -z $PR_NUMBER || -z $VOLUME_DIR || -z $GITHUB_ORG || -z $GITHUB_REPO ]]; then | ||
| echo "ERROR:: environment variables not set correctly" | ||
| REFERENCE=${REFERENCE} | ||
|
|
||
| # We want builder to work with the old scenarios, so support PR_NUMBER var for compatibility. | ||
| if [[ -z ${REFERENCE} ]]; then | ||
| REFERENCE=${PR_NUMBER} | ||
| fi | ||
|
|
||
| if [[ -z ${REFERENCE} || -z ${VOLUME_DIR} || -z ${GITHUB_ORG} || -z ${GITHUB_REPO} ]]; then | ||
| echo "ERROR:: environment variables not set correctly, requires REFERENCE (or PR_NUMBER), VOLUME_DIR, GITHUB_ORG, GITHUB_REPO" | ||
| exit 1; | ||
| fi | ||
|
|
||
| # Fetch from quay if requested. | ||
| if [[ "${USE_REGISTRY}" == "true" ]]; then | ||
| echo ">> USE_PRE_BUILD is enabled." | ||
| echo ">> Attempting to download binary from quay.io/prometheus/prometheus:${REFERENCE}" | ||
|
|
||
| IMAGE="quay.io/prometheus/prometheus:${REFERENCE}" | ||
|
|
||
| if ! CONTAINER_ID=$(docker create "${IMAGE}"); then | ||
| echo "ERROR:: Could not pull or create container from ${IMAGE}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo ">> Extracting prometheus binary from ${CONTAINER_ID} container..." | ||
| if ! docker cp "${CONTAINER_ID}:/bin/prometheus" "${VOLUME_DIR}/prometheus"; then | ||
| echo "ERROR:: Failed to copy binary from container" | ||
| docker rm -v "${CONTAINER_ID}" >/dev/null | ||
| exit 1 | ||
| fi | ||
| docker rm -v "${CONTAINER_ID}" >/dev/null | ||
| echo ">> Binary successfully downloaded and copied." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Clone the repository with a shallow clone | ||
| echo ">> Cloning repository $GITHUB_ORG/$GITHUB_REPO (shallow clone)" | ||
| if ! git clone --depth 1 https://github.com/$GITHUB_ORG/$GITHUB_REPO.git $DIR; then | ||
| if ! git clone --depth 1 "https://github.com/$GITHUB_ORG/$GITHUB_REPO.git" "$DIR"; then | ||
| echo "ERROR:: Cloning of repo $GITHUB_ORG/$GITHUB_REPO failed" | ||
| exit 1; | ||
| fi | ||
|
|
||
| cd $DIR || exit 1 | ||
| cd "$DIR" || exit 1 | ||
|
|
||
| echo ">> Fetching Pull Request $GITHUB_ORG/$GITHUB_REPO/pull/$PR_NUMBER" | ||
| if ! git fetch origin pull/$PR_NUMBER/head:pr-branch; then | ||
| echo "ERROR:: Fetching of PR $PR_NUMBER failed" | ||
| exit 1; | ||
| fi | ||
| echo ">> Resolving git state for building from source from ${REFERENCE}..." | ||
|
|
||
| # Attempt 1: Try pulling PR first which will only work if REFERENCE is a PR number. | ||
| if git fetch origin "pull/${REFERENCE}/head:pr-branch" 2>/dev/null; then | ||
| echo ">> Successfully fetched PR reference: pull/${REFERENCE}/head" | ||
| git checkout pr-branch | ||
| else | ||
| # Attempt 2: If PR fetch fails, try assuming it's a branch or Git SHA | ||
| echo ">> Reference 'pull/${REFERENCE}/head' not found; assuming reference is not a PR number. Trying to fetch '${REFERENCE}' as a remote branch or SHA..." | ||
|
|
||
| git checkout pr-branch | ||
| # We fetch specifically the ref to FETCH_HEAD to avoid naming conflicts | ||
| if git fetch origin "${REFERENCE}"; then | ||
| echo ">> Successfully fetched reference: ${REFERENCE}" | ||
| git checkout FETCH_HEAD | ||
| else | ||
| echo "ERROR:: Could not resolve '${REFERENCE}' as a Pull Request, remote branch, or Git SHA." | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo ">> Creating prometheus binaries" | ||
| echo ">> Creating prometheus binary using promu" | ||
| if ! make build PROMU_BINARIES="prometheus"; then | ||
| echo "ERROR:: Building of binaries failed" | ||
| exit 1; | ||
| fi | ||
|
|
||
| echo ">> Copy files to volume" | ||
| cp prometheus $VOLUME_DIR/prometheus | ||
| cp prometheus "$VOLUME_DIR/prometheus" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.