Skip to content
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
wants to merge 90 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 Mar 21, 2024
32c8fa8
PMM-12899 update grafana spec
ademidoff Mar 21, 2024
37e005a
PMM-12899 fix the build_command
ademidoff Mar 21, 2024
c863f50
PMM-12899 fix builddeps
ademidoff Mar 21, 2024
853be6e
PMM-12899 use rpmbuild:3
ademidoff Mar 21, 2024
d57ec55
PMM-12641 Fix the dashboard upgrade (#2926)
ademidoff Mar 26, 2024
5c7821f
PMM-12899 prevent grafana from using own GOPATH
ademidoff Mar 31, 2024
42a02a9
PMM-12899 use a dedicated folder for yarn cache
ademidoff Mar 31, 2024
6d0b02b
PMM-12899 extract server rpm script
ademidoff Apr 1, 2024
0a32c59
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Apr 1, 2024
098e894
PMM-12899 fix server param evaluation
ademidoff Apr 1, 2024
c80fe45
Merge branch 'PMM-12899-use-module-and-build-cache' of github.com:per…
ademidoff Apr 1, 2024
aa5729f
PMM-12899 clean up server RPM specs
ademidoff Apr 1, 2024
aa5e8b8
PMM-12899 fix directory permissions
ademidoff Apr 1, 2024
ee45fd6
PMM-12899 remove unnecessary macro
ademidoff Apr 1, 2024
afde65a
PMM-12899 revert QAN package name
ademidoff Apr 1, 2024
f28cbcc
PMM-12899 merge update.sh to build.sh
ademidoff Apr 2, 2024
66dc390
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Apr 2, 2024
093179a
PMM-12899 reorganize the script structure
ademidoff Apr 2, 2024
12fd453
PMM-12899 get rid of `exit 0` in callee scripts
ademidoff Apr 2, 2024
9587f21
PMM-12899 clean up pmm-update.spec
ademidoff Apr 2, 2024
13b4f65
PMM-12899 send exec time to the log file
ademidoff Apr 2, 2024
6f9eac8
PMM-12899 remove a redundant directory
ademidoff Apr 2, 2024
3eb50f8
PMM-12899 add total exec time
ademidoff Apr 2, 2024
36869b7
PMM-12899 reorg some variables
ademidoff Apr 2, 2024
bf640ca
PMM-12899 fix the regexp
ademidoff Apr 3, 2024
f28202a
PMM-12899 structure the code
ademidoff Apr 3, 2024
a0f7b50
PMM-12899 add a flag to skip building server docker
ademidoff Apr 3, 2024
988cfb0
PMM-12899 fix a failure of find when no files are found
ademidoff Apr 3, 2024
8216d65
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Apr 3, 2024
d2c4ecb
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Apr 6, 2024
0582998
PMM-12899 update the documentation
ademidoff Apr 10, 2024
0e0bde7
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Apr 16, 2024
ccf3bf0
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Jul 14, 2024
ea42fe7
PMM-12899 update README.md
ademidoff Oct 12, 2024
87cc6a2
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Oct 12, 2024
fc248de
PMM-12899 fix duplicate labels in Dockerfile
ademidoff Oct 12, 2024
4b469bd
PMM-12899 add a config file for all PMM components
ademidoff Oct 14, 2024
6d590ce
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Oct 19, 2024
f35a85f
PMM-12899 simplify init, add usage
ademidoff Oct 19, 2024
1aad3f7
PMM-12899 fix architecture for the client
ademidoff Oct 19, 2024
23aaaf6
PMM-12899 fix the build time for MacOS
ademidoff Oct 19, 2024
c2357c5
PMM-12899 fix git commit variable
ademidoff Oct 20, 2024
7925079
PMM-12899 don't use S3 cache for local builds
ademidoff Oct 20, 2024
1d8fe37
PMM-12899 dont chown with an id external to the container
ademidoff Nov 1, 2024
48d481f
PMM-12899 refactor the log output
ademidoff Nov 1, 2024
dd2779a
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Nov 1, 2024
e8e3f0f
PMM-12899 don't chown with builder id outside of container
ademidoff Nov 1, 2024
01427fc
Merge branch 'PMM-12899-use-module-and-build-cache' of github.com:per…
ademidoff Nov 1, 2024
344b783
PMM-12899 add aarch to grafana.spec
ademidoff Nov 1, 2024
7aa9a30
PMM-12899 add aarch64 to grafana.spec
ademidoff Nov 1, 2024
f28ecde
PMM-12899 add the platform
ademidoff Nov 1, 2024
87d75a7
PMM-12899 use docker volumes for caching
ademidoff Nov 1, 2024
15d9344
PMM-12899 exit if the spec cannot be found
ademidoff Nov 1, 2024
5a8f6e4
PMM-12899 fix yarn cache
ademidoff Nov 1, 2024
e326d94
PMM-12899 fix the platform
ademidoff Nov 1, 2024
9010f42
PMM-12899 chown the cache dirs before starting
ademidoff Nov 1, 2024
0ff180f
PMM-12899 remove GOARCH setting
ademidoff Nov 1, 2024
c9d8e35
PMM-12899 add --platform to --help
ademidoff Nov 1, 2024
46c8934
PMM-12899 do not upload to S3 when building locally
ademidoff Nov 1, 2024
10ea625
PMM-12899 fix a typo
ademidoff Nov 1, 2024
891a2f0
PMM-12899 clean up scripts
ademidoff Nov 3, 2024
b193355
PMM-12899 revert changes to grafana.spec
ademidoff Nov 4, 2024
53de284
PMM-12899 revert changes to grafana.spec
ademidoff Nov 4, 2024
a7ebc00
PMM-12899 update goreleaser to latest
ademidoff Nov 4, 2024
6ea7125
PMM-12899 use a different Go version for grafana
ademidoff Nov 4, 2024
f3b7ece
PMM-12899 fix copying ansible files
ademidoff Nov 4, 2024
3293ab5
PMM-12899 fix copying Dockerfile
ademidoff Nov 4, 2024
d501abc
PMM-12899 fix legacy Docker label format
ademidoff Nov 4, 2024
15be815
PMM-12899 do not use the repo subpaths for mutations
ademidoff Nov 4, 2024
eeccd8a
PMM-12899 use a dedicated spec directory
ademidoff Nov 4, 2024
8c8bf03
PMM-12899 fix the spec directory evaluation
ademidoff Nov 4, 2024
4aa5012
PMM-12899 create rpms directories first
ademidoff Nov 4, 2024
eaaeaf2
PMM-12899 fix find syntax
ademidoff Nov 4, 2024
2325c53
PMM-12899 fix find syntax to search for both files and dirs
ademidoff Nov 4, 2024
dc6cadd
PMM-12899 revert changes made to grafana.spec
ademidoff Nov 5, 2024
2819fc9
PMM-12899 try not to use cache for grafana
ademidoff Nov 5, 2024
cd0df5c
PMM-12899 try not to use cache for grafana
ademidoff Nov 5, 2024
f5dc745
PMM-12899 fix the cache directory not being writable
ademidoff Nov 5, 2024
a28edba
PMM-12899 use no Go cache for grafana
ademidoff Nov 5, 2024
44fc04b
PMM-12899 use no Go cache for grafana
ademidoff Nov 5, 2024
e1fbeca
PMM-12899 remove docker tarballs
ademidoff Nov 5, 2024
c94b549
PMM-12899 add --client-only parameter
ademidoff Nov 5, 2024
687d3b6
Merge branch 'v3' into PMM-12899-use-module-and-build-cache
ademidoff Nov 5, 2024
8944ef5
PMM-12899 rename build.sh to build
ademidoff Nov 5, 2024
69899db
PMM-12899 purge more files before starting
ademidoff Nov 5, 2024
a8756ab
PMM-12899 pass NO_VCS parameter to go build
ademidoff Nov 5, 2024
be7405e
PMM-12899 add dist directory to .gitignore
ademidoff Nov 5, 2024
93d5d7c
PMM-12899 create cache directories in rpmbuild
ademidoff Nov 5, 2024
45fd300
PMM-12899 fix "build_command" extrapolation
ademidoff Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ jobs:
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_TOKEN_PMM_CI }}
SLACK_CHANNEL: "pmm-ci"
SLACK_USERNAME: "PR pipelines bot"
SLACK_ICON_EMOJI: ":chestnut:"
SLACK_USERNAME: "Build bot"
SLACK_ICON_EMOJI: ":octocat:"
Copy link
Member Author

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 - :octocat: seems to be much more to the point here :)

SLACK_COLOR: "#00FF00"
SLACK_TITLE: "Finished ${{ github.event.repository.name }} workflow"
SLACK_MESSAGE: "${{ github.event.inputs.repo || github.repository }}:${{ github.event.inputs.branch || github.head_ref }}"
Expand All @@ -160,8 +160,8 @@ jobs:
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_TOKEN_PMM_CI }}
SLACK_CHANNEL: "pmm-ci"
SLACK_USERNAME: "PR pipelines bot"
SLACK_ICON_EMOJI: ":chestnut:"
SLACK_USERNAME: "Build bot"
SLACK_ICON_EMOJI: ":octocat:"
SLACK_COLOR: "#FF0000"
SLACK_TITLE: "Finished ${{ github.event.repository.name }} workflow"
SLACK_MESSAGE: "Workflow failed: ${{ github.event.inputs.repo || github.repository }}:${{ github.event.inputs.branch || github.head_ref }}"
Expand Down
18 changes: 10 additions & 8 deletions build/docker/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ RUN microdnf install shadow-utils jq -y
RUN groupadd -g 1002 pmm-agent && \
useradd -u 1002 -r -g pmm-agent -s /sbin/nologin \
-d /usr/local/percona/pmm \
-c "PMM 2.X Client User" pmm-agent
-c "PMM 3.x Client User" pmm-agent

FROM redhat/ubi9-micro

ARG VERSION
ARG BUILD_DATE

LABEL org.opencontainers.image.created ${BUILD_DATE}
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.title Percona Monitoring and Management Client
LABEL org.opencontainers.image.vendor Percona
LABEL org.opencontainers.image.version ${VERSION}

COPY LICENSE /licenses/
COPY --from=users --chown=0:0 /etc/passwd /etc/passwd
COPY --from=users --chown=0:0 /etc/group /etc/group
Expand All @@ -32,10 +26,18 @@ RUN install -d -o pmm-agent -g pmm-agent -m 0775 /usr/local/percona/pmm
ADD pmm-client.tar.gz /tmp/

RUN cd /tmp/pmm-client-* \
&& env PMM_USER=pmm-agent PMM_GROUP=root ./install_tarball \
&& PMM_USER=pmm-agent PMM_GROUP=root ./install_tarball \
&& cd /tmp \
&& rm -rf /tmp/pmm-client*

LABEL org.opencontainers.image.created ${BUILD_DATE}
LABEL org.opencontainers.image.licenses Apache-2.0
LABEL org.opencontainers.image.title Percona Monitoring and Management Client
LABEL org.opencontainers.image.vendor Percona
LABEL org.opencontainers.image.version ${VERSION}
LABEL org.opencontainers.image.source https://github.com/percona/pmm/blob/main/build/docker/client/Dockerfile
LABEL org.opencontainers.image.docs https://docs.percona.com/percona-monitoring-and-management/setting-up/client/index.html#docker

USER pmm-agent
WORKDIR /usr/local/percona/pmm/
ENV PATH /usr/local/percona/pmm/bin/:$PATH
Expand Down
14 changes: 8 additions & 6 deletions build/docker/server/Dockerfile.el9
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ ENV LC_ALL=en_US.utf8
ENV GF_PLUGIN_DIR=/srv/grafana/plugins
ENV PS1="[\u@\h \W] # "

LABEL org.opencontainers.image.created ${BUILD_DATE}
LABEL org.opencontainers.image.licenses AGPL-3.0
LABEL org.opencontainers.image.title Percona Monitoring and Management
LABEL org.opencontainers.image.vendor Percona LLC
LABEL org.opencontainers.image.version ${VERSION}

EXPOSE 8080 8443

WORKDIR /opt
Expand All @@ -40,6 +34,14 @@ RUN install -T -p -m 644 /opt/ansible/ansible.cfg /etc/ansible/ansible.cfg && \
ansible-playbook -vvv -i 'localhost,' -c local /opt/ansible/pmm-docker/update.yml && \
ansible-playbook -vvv -i 'localhost,' -c local /opt/ansible/pmm/post-build-actions.yml

LABEL org.opencontainers.image.created ${BUILD_DATE}
LABEL org.opencontainers.image.licenses AGPL-3.0
LABEL org.opencontainers.image.title Percona Monitoring and Management
LABEL org.opencontainers.image.vendor Percona LLC
LABEL org.opencontainers.image.version ${VERSION}
LABEL org.opencontainers.image.source https://github.com/percona/pmm/blob/main/build/docker/server/Dockerfile.el9
LABEL org.opencontainers.image.docs https://docs.percona.com/percona-monitoring-and-management/setting-up/server/docker.html

USER pmm

HEALTHCHECK --interval=3s --timeout=2s --start-period=10s --retries=3 CMD curl -sf http://127.0.0.1:8080/v1/readyz
Expand Down
29 changes: 0 additions & 29 deletions build/docker/server/create_users.sh

This file was deleted.

34 changes: 34 additions & 0 deletions build/local/README.md
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
110 changes: 110 additions & 0 deletions build/local/build.sh
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
101 changes: 101 additions & 0 deletions build/local/update.sh
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
Loading
Loading