-
Notifications
You must be signed in to change notification settings - Fork 131
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
PMM-12899 Use module and build cache #2916
Draft
ademidoff
wants to merge
90
commits into
v3
Choose a base branch
from
PMM-12899-use-module-and-build-cache
base: v3
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.
Draft
Changes from 2 commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
1ef83f3
PMM-12899 Use module and build cache
ademidoff 32c8fa8
PMM-12899 update grafana spec
ademidoff 37e005a
PMM-12899 fix the build_command
ademidoff c863f50
PMM-12899 fix builddeps
ademidoff 853be6e
PMM-12899 use rpmbuild:3
ademidoff d57ec55
PMM-12641 Fix the dashboard upgrade (#2926)
ademidoff 5c7821f
PMM-12899 prevent grafana from using own GOPATH
ademidoff 42a02a9
PMM-12899 use a dedicated folder for yarn cache
ademidoff 6d0b02b
PMM-12899 extract server rpm script
ademidoff 0a32c59
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff 098e894
PMM-12899 fix server param evaluation
ademidoff c80fe45
Merge branch 'PMM-12899-use-module-and-build-cache' of github.com:per…
ademidoff aa5729f
PMM-12899 clean up server RPM specs
ademidoff aa5e8b8
PMM-12899 fix directory permissions
ademidoff ee45fd6
PMM-12899 remove unnecessary macro
ademidoff afde65a
PMM-12899 revert QAN package name
ademidoff f28cbcc
PMM-12899 merge update.sh to build.sh
ademidoff 66dc390
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff 093179a
PMM-12899 reorganize the script structure
ademidoff 12fd453
PMM-12899 get rid of `exit 0` in callee scripts
ademidoff 9587f21
PMM-12899 clean up pmm-update.spec
ademidoff 13b4f65
PMM-12899 send exec time to the log file
ademidoff 6f9eac8
PMM-12899 remove a redundant directory
ademidoff 3eb50f8
PMM-12899 add total exec time
ademidoff 36869b7
PMM-12899 reorg some variables
ademidoff bf640ca
PMM-12899 fix the regexp
ademidoff f28202a
PMM-12899 structure the code
ademidoff a0f7b50
PMM-12899 add a flag to skip building server docker
ademidoff 988cfb0
PMM-12899 fix a failure of find when no files are found
ademidoff 8216d65
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff d2c4ecb
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff 0582998
PMM-12899 update the documentation
ademidoff 0e0bde7
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff ccf3bf0
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff ea42fe7
PMM-12899 update README.md
ademidoff 87cc6a2
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff fc248de
PMM-12899 fix duplicate labels in Dockerfile
ademidoff 4b469bd
PMM-12899 add a config file for all PMM components
ademidoff 6d590ce
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff f35a85f
PMM-12899 simplify init, add usage
ademidoff 1aad3f7
PMM-12899 fix architecture for the client
ademidoff 23aaaf6
PMM-12899 fix the build time for MacOS
ademidoff c2357c5
PMM-12899 fix git commit variable
ademidoff 7925079
PMM-12899 don't use S3 cache for local builds
ademidoff 1d8fe37
PMM-12899 dont chown with an id external to the container
ademidoff 48d481f
PMM-12899 refactor the log output
ademidoff dd2779a
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff e8e3f0f
PMM-12899 don't chown with builder id outside of container
ademidoff 01427fc
Merge branch 'PMM-12899-use-module-and-build-cache' of github.com:per…
ademidoff 344b783
PMM-12899 add aarch to grafana.spec
ademidoff 7aa9a30
PMM-12899 add aarch64 to grafana.spec
ademidoff f28ecde
PMM-12899 add the platform
ademidoff 87d75a7
PMM-12899 use docker volumes for caching
ademidoff 15d9344
PMM-12899 exit if the spec cannot be found
ademidoff 5a8f6e4
PMM-12899 fix yarn cache
ademidoff e326d94
PMM-12899 fix the platform
ademidoff 9010f42
PMM-12899 chown the cache dirs before starting
ademidoff 0ff180f
PMM-12899 remove GOARCH setting
ademidoff c9d8e35
PMM-12899 add --platform to --help
ademidoff 46c8934
PMM-12899 do not upload to S3 when building locally
ademidoff 10ea625
PMM-12899 fix a typo
ademidoff 891a2f0
PMM-12899 clean up scripts
ademidoff b193355
PMM-12899 revert changes to grafana.spec
ademidoff 53de284
PMM-12899 revert changes to grafana.spec
ademidoff a7ebc00
PMM-12899 update goreleaser to latest
ademidoff 6ea7125
PMM-12899 use a different Go version for grafana
ademidoff f3b7ece
PMM-12899 fix copying ansible files
ademidoff 3293ab5
PMM-12899 fix copying Dockerfile
ademidoff d501abc
PMM-12899 fix legacy Docker label format
ademidoff 15be815
PMM-12899 do not use the repo subpaths for mutations
ademidoff eeccd8a
PMM-12899 use a dedicated spec directory
ademidoff 8c8bf03
PMM-12899 fix the spec directory evaluation
ademidoff 4aa5012
PMM-12899 create rpms directories first
ademidoff eaaeaf2
PMM-12899 fix find syntax
ademidoff 2325c53
PMM-12899 fix find syntax to search for both files and dirs
ademidoff dc6cadd
PMM-12899 revert changes made to grafana.spec
ademidoff 2819fc9
PMM-12899 try not to use cache for grafana
ademidoff cd0df5c
PMM-12899 try not to use cache for grafana
ademidoff f5dc745
PMM-12899 fix the cache directory not being writable
ademidoff a28edba
PMM-12899 use no Go cache for grafana
ademidoff 44fc04b
PMM-12899 use no Go cache for grafana
ademidoff e1fbeca
PMM-12899 remove docker tarballs
ademidoff c94b549
PMM-12899 add --client-only parameter
ademidoff 687d3b6
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff 8944ef5
PMM-12899 rename build.sh to build
ademidoff 69899db
PMM-12899 purge more files before starting
ademidoff a8756ab
PMM-12899 pass NO_VCS parameter to go build
ademidoff be7405e
PMM-12899 add dist directory to .gitignore
ademidoff 93d5d7c
PMM-12899 create cache directories in rpmbuild
ademidoff 45fd300
PMM-12899 fix "build_command" extrapolation
ademidoff 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Local builds | ||
|
||
This directory contains a set of scripts aimed at providing a simple way to build PMM locally. | ||
|
||
## Background | ||
|
||
Historically, PMM used to be built using Jenkins. This worked well for the team, but not for the community. The learning curve was, and still is, rather steep, and it is hard for folks, even internally, to contribute to. | ||
|
||
Therefore, we decided to make it possible to build PMM locally. This is a work in progress, but we are definitely committed to making it easier to build PMM locally. | ||
|
||
The build process is mostly based on bash scripts, which control the build flow. This was an intentional decision early on to make the build process easy to understand and contribute to. Apart from bash and a few other well-known utilitites like `curl` or `make`, it also uses Docker for environment isolation and caching. | ||
|
||
The build process is designed to be run on a Linux host. We believe it can be run on other flavors of Linux, including MacOS, with little to no modification (TBC). | ||
|
||
## Prerequisites | ||
|
||
Below is a list of prerequisites that are required to build PMM locally. | ||
|
||
- OS: Linux (tested on Oracle Linux 9.3, CentOS 7, Ubuntu 22.04.3 LTS) | ||
- Docker: 25.0.2+ (tested on 25.0.2) | ||
- Docker Compose Plugin: 2.24.7+ (tested on 2.24.7) | ||
- make: 4.3+ (tested on 4.3) | ||
- bash (GNU): 5.1+ (tested on 5.1) | ||
- git: 2.34.1+ (tested on 2.34.1) | ||
- curl: 7.81.0+ (tested on 7.81.0) | ||
- yq: 4.42.0+ (tested on 4.42.1) | ||
- jq: 1.6+ (tested on 1.6) | ||
|
||
## Build Steps | ||
|
||
1. Install the prerequisites | ||
2. Clone the PMM repository | ||
3. Change to the `build/local` directory | ||
4. Run the `build.sh` script |
This file contains 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash -e | ||
|
||
# Update submodules and PR branches | ||
/bin/bash $(dirname $0)/update.sh | ||
|
||
get_branch_name() { | ||
local module="${1:-}" | ||
local branch_name | ||
local path | ||
|
||
path=$(git config -f .gitmodules submodule.${module}.path) | ||
cd "$path" || exit 1 | ||
branch_name=$(git branch --show-current) | ||
cd - > /dev/null | ||
echo $branch_name | ||
} | ||
|
||
# Define global variables | ||
pmm_commit=$(git submodule status | grep 'sources/pmm/src' | awk -F ' ' '{print $1}') | ||
echo $pmm_commit > apiCommitSha | ||
pmm_branch=$(get_branch_name pmm) | ||
echo $pmm_branch > apiBranch | ||
pmm_url=$(git config -f .gitmodules submodule.pmm.url) | ||
echo $pmm_url > apiURL | ||
pmm_qa_branch=$(get_branch_name pmm-qa) | ||
echo $pmm_qa_branch > pmmQABranch | ||
pmm_qa_commit=$(git submodule status | grep 'pmm-qa' | awk -F ' ' '{print $1}') | ||
echo $pmm_qa_commit > pmmQACommitSha | ||
pmm_ui_tests_branch=$(get_branch_name pmm-ui-tests) | ||
echo $pmm_ui_tests_branch > pmmUITestBranch | ||
pmm_ui_tests_commit=$(git submodule status | grep 'pmm-ui-tests' | awk -F ' ' '{print $1}') | ||
echo $pmm_ui_tests_commit > pmmUITestsCommitSha | ||
fb_commit_sha=$(git rev-parse HEAD) | ||
echo $fb_commit_sha > fbCommitSha | ||
|
||
# We use a special docker image to build various PMM artifacts - `perconalab/rpmbuild:ol9`. | ||
# Important: the docker container's user need to be able to write to these directories. | ||
# The docker container's user is `builder` with uid 1000 and gid 1000. You need to make sure | ||
# that the directories we create on the host are owned by a user with same uid and gid. | ||
|
||
# Create cache directories. | ||
test -d "${root_dir}/go-path" || mkdir -p "go-path" | ||
test -d "${root_dir}/go-build" || mkdir -p "go-build" | ||
|
||
PATH_TO_SCRIPTS="sources/pmm/src/github.com/percona/pmm/build/scripts" | ||
export RPMBUILD_DOCKER_IMAGE=perconalab/rpmbuild:ol9 | ||
|
||
# Local reference test environment | ||
# CPU: 4 cores | ||
# RAM: 16GB | ||
# OS: Ubuntu 22.04.1 LTS | ||
|
||
# Build client source: 4m39s from scratch, 0m27s using cache | ||
"$PATH_TO_SCRIPTS/build-client-source" | ||
|
||
# Build client binary: ??? from scratch, 0m20s using cache | ||
"$PATH_TO_SCRIPTS/build-client-binary" | ||
|
||
# Building client source rpm takes 13s (caching does not apply) | ||
"$PATH_TO_SCRIPTS/build-client-srpm" | ||
|
||
# Building client rpm takes 1m40s | ||
"$PATH_TO_SCRIPTS/build-client-rpm" | ||
|
||
# Building client docker image takes 17s | ||
GIT_COMMIT=$(git rev-parse HEAD | head -c 8) | ||
export DOCKER_CLIENT_TAG=local/pmm-client:${GIT_COMMIT} | ||
"$PATH_TO_SCRIPTS/build-client-docker" | ||
|
||
# Building PMM CLient locally (non-CI, i.e. non-Jenkins) | ||
# total time: 6m26s - build from scratch, no initial cache | ||
# total time: 2m49s - subsequent build, using cache from prior builds | ||
|
||
|
||
# Building PMM CLient in a CI environment, i.e. Jenkins running on AWS | ||
# total time: 8m45s - build from scratch, no initial cache | ||
# total time: ??? - subsequent build, using cache from prior builds | ||
|
||
export RPM_EPOCH=1 | ||
export RPMBUILD_DIST="el9" | ||
"$PATH_TO_SCRIPTS/build-server-rpm" percona-dashboards grafana-dashboards | ||
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-managed pmm | ||
"$PATH_TO_SCRIPTS/build-server-rpm" percona-qan-api2 pmm | ||
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-update pmm | ||
"$PATH_TO_SCRIPTS/build-server-rpm" dbaas-controller | ||
"$PATH_TO_SCRIPTS/build-server-rpm" dbaas-tools | ||
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-dump | ||
"$PATH_TO_SCRIPTS/build-server-rpm" grafana-db-migrator | ||
"$PATH_TO_SCRIPTS/build-server-rpm" vmproxy pmm | ||
|
||
# 3rd-party | ||
"$PATH_TO_SCRIPTS/build-server-rpm" victoriametrics | ||
"$PATH_TO_SCRIPTS/build-server-rpm" alertmanager | ||
"$PATH_TO_SCRIPTS/build-server-rpm" grafana | ||
|
||
export DOCKER_TAG=local/pmm-server:${GIT_COMMIT} | ||
export RPMBUILD_DOCKER_IMAGE=perconalab/rpmbuild:ol9 | ||
export RPMBUILD_DIST=el9 | ||
export DOCKERFILE=Dockerfile.el9.local | ||
${PATH_TO_SCRIPTS}/build-server-docker | ||
|
||
# Clean up temporary files | ||
rm -f apiBranch \ | ||
apiCommitSha \ | ||
apiURL \ | ||
fbCommitSha \ | ||
pmmQABranch \ | ||
pmmQACommitSha \ | ||
pmmUITestBranch \ | ||
pmmUITestsCommitSha |
This file contains 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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/bin/bash -e | ||
|
||
needs-to-pull() { | ||
local UPSTREAM=${1:-'@{u}'} | ||
local LOCAL=$(git rev-parse @) | ||
local BASE=$(git merge-base @ "$UPSTREAM") | ||
local REMOTE=$(git rev-parse "$UPSTREAM") | ||
|
||
if [ "$LOCAL" = "$REMOTE" ]; then | ||
return 1 # false, we are up-to-date | ||
fi | ||
|
||
if [ "$LOCAL" = "$BASE" ]; then | ||
return 0 # true, we are behind upstream | ||
fi | ||
} | ||
|
||
rewind() { | ||
local DIR="$1" | ||
local BRANCH="$2" | ||
|
||
cd "$DIR" | ||
CURRENT=$(git branch --show-current) | ||
git fetch | ||
|
||
if [ "$CURRENT" != "$BRANCH" ]; then | ||
echo "Currently on $CURRENT, checking out $BRANCH" | ||
git checkout "$BRANCH" | ||
fi | ||
|
||
if needs-to-pull; then | ||
git pull origin | ||
echo "Submodule has pulled from upstream" | ||
git logs -n 2 | ||
cd - >/dev/null | ||
git add "$DIR" | ||
else | ||
cd - >/dev/null | ||
echo "Submodule is up-to-date with upstream" | ||
fi | ||
} | ||
|
||
check-files() { | ||
local DIR="$1" | ||
|
||
test -z "DIR" && exit 1 | ||
|
||
if [ -d "$DIR/sources" ] && [ -f "$DIR/ci-default.yml" ] && [ -f "$DIR/ci.yml" ]; then | ||
return 0 | ||
fi | ||
|
||
return 1 | ||
} | ||
|
||
main() { | ||
local DEPS= | ||
local CURDIR="$PWD" | ||
local DIR=pmm-submodules | ||
|
||
# Thouroughly verify the presence of known files, otherwise bail out | ||
if check-files "."; then # pwd is pmm-submodules | ||
DIR="." | ||
elif [ -d "$DIR" ]; then # pwd is outside pmm-submodules | ||
if ! check-files "$DIR"; then | ||
echo "FATAL: could not locate known files in ${PWD}/${DIR}" | ||
exit 1 | ||
fi | ||
else | ||
echo "FATAL: could not locate known files in $PWD" | ||
exit 1 | ||
fi | ||
|
||
cd "$DIR" | ||
|
||
# Join the dependencies from ci-default.yml and ci.yml | ||
DEPS=$(yq -o=json eval-all '. as $item ireduce ({}; . *d $item )' ci-default.yml ci.yml | jq '.deps') | ||
|
||
echo "This script rewinds submodule branches as per the joint config of 'ci-default.yml' and 'ci.yml'" | ||
|
||
echo "$DEPS" | jq -c '.[]' | while read -r item; do | ||
branch=$(echo "$item" | jq -r '.branch') | ||
path=$(echo "$item" | jq -r '.path') | ||
name=$(echo "$item" | jq -r '.name') | ||
echo | ||
echo "Rewinding submodule '$name' ..." | ||
echo "path: ${path}, branch: ${branch}" | ||
|
||
rewind "$path" "$branch" | ||
done | ||
|
||
echo | ||
echo "Printing git status..." | ||
git status --short | ||
echo | ||
echo "Printing git submodule status..." | ||
git submodule status | ||
|
||
cd "$CURDIR" > /dev/null | ||
} | ||
|
||
main |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Sorry, I couldn't resist - seems to be much more to the point here :)