From 4e5131b276e816c9783f676936a1117818d2e946 Mon Sep 17 00:00:00 2001 From: Alexey Mukas <91831719+ritbl@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:37:07 +0200 Subject: [PATCH] PMM-10900: custom image and option to run pmm with external clickhouse (#1314) --- .env.example | 9 +++++ .gitignore | 2 ++ Makefile | 12 +++++++ docker-compose.yml | 84 +++++++++++++++++++++++++++++++++++++++++++--- managed/Makefile | 7 +++- 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000..823d894998 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Percona PMM dev container +#PMM_CONTAINER=perconalab/pmm-server:dev-container + +# Native ARM image +#PMM_CONTAINER=ritbl/pmm-x:v2.31.0 + +CH_IMAGE=clickhouse/clickhouse-server:22.6.9.11-alpine +CH_PORT=9000 +CH_HOSTNAME=ch diff --git a/.gitignore b/.gitignore index 94bfe332ab..f08a1d82b2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ pmm-agent-dev.yaml # ViM temporary files *.sw[o,p] + +.env diff --git a/Makefile b/Makefile index 81e1032704..940143a1a9 100644 --- a/Makefile +++ b/Makefile @@ -2,28 +2,40 @@ include Makefile.include +ifeq ($(PROFILES),) +PROFILES := 'pmm' +endif + env-up: ## Start devcontainer. + COMPOSE_PROFILES=$(PROFILES) \ docker-compose up -d env-up-rebuild: env-update-image ## Rebuild and start devcontainer. Useful for custom $PMM_SERVER_IMAGE + COMPOSE_PROFILES=$(PROFILES) \ docker-compose up --build -d env-update-image: ## Pull latest dev image + COMPOSE_PROFILES=$(PROFILES) \ docker-compose pull env-compose-up: env-update-image + COMPOSE_PROFILES=$(PROFILES) \ docker-compose up --detach --renew-anon-volumes --remove-orphans env-devcontainer: + COMPOSE_PROFILES=$(PROFILES) \ docker exec -it --workdir=/root/go/src/github.com/percona/pmm pmm-managed-server .devcontainer/setup.py env-down: ## Stop devcontainer. + COMPOSE_PROFILES=$(PROFILES) \ docker-compose down --remove-orphans env-remove: + COMPOSE_PROFILES=$(PROFILES) \ docker-compose down --volumes --remove-orphans TARGET ?= _bash env: ## Run `make TARGET` in devcontainer (`make env TARGET=help`); TARGET defaults to bash. + COMPOSE_PROFILES=$(PROFILES) \ docker exec -it --workdir=/root/go/src/github.com/percona/pmm pmm-managed-server make $(TARGET) diff --git a/docker-compose.yml b/docker-compose.yml index 57340d936d..ec4ad356c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ version: '3.7' services: pmm-managed-server: - image: perconalab/pmm-server:dev-container + profiles: + - pmm + image: ${PMM_CONTAINER:-perconalab/pmm-server:dev-container} # build: # context: . # args: @@ -19,15 +21,86 @@ services: - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} - AWS_SECRET_KEY=${AWS_SECRET_KEY} - ENABLE_BACKUP_MANAGEMENT=1 + # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost + # - PERCONA_TEST_PLATFORM_INSECURE=1 + # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= + # - PERCONA_TEST_TELEMETRY_INTERVAL=10s + # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s + # - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=127.0.0.1:9000 + # - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm + # - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 + # - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 + # - PMM_DEBUG=1 + + extra_hosts: + - host.docker.internal:host-gateway + # - portal.localhost:${PORTAL_HOST:-host-gateway} + # - check.localhost:${PORTAL_CHECK_HOST:-host-gateway} + # - pmm.localhost:${PORTAL_PMM_HOST:-host-gateway} + # - check-dev.percona.com:${PORTAL_PMM_HOST:-host-gateway} + + # for delve + cap_add: + - SYS_PTRACE + security_opt: + - seccomp:unconfined + + # see https://github.com/golang/go/wiki/LinuxKernelSignalVectorBug#what-to-do + ulimits: + memlock: 67108864 + + ports: + - ${PMM_PORT_HTTP:-80}:80 + - ${PMM_PORT_HTTPS:-443}:443 + # For headless delve + - ${PMM_PORT_DELVE:-2345}:2345 + # PG + - ${PMM_PORT_PG:-15432}:5432 + # CH + - ${PMM_PORT_CH_TCP:-11000}:9000 + - ${PMM_PORT_CH_HTTP:-11123}:8123 + volumes: + - ./:/root/go/src/github.com/percona/pmm + - ./Makefile.devcontainer:/root/go/src/github.com/percona/pmm/Makefile:ro # change Makefile in devcontainer + # caching + - go-modules:/root/go/pkg/mod + - root-cache:/root/.cache + + # PMM with external ClickHouse DB + ch: + profiles: + - pmm-ch + image: ${CH_IMAGE:-clickhouse/clickhouse-server:22.6.9.11-alpine} + platform: linux/amd64 + hostname: ${CH_HOSTNAME:-ch} + ports: + - ${CH_PORT:-9000}:9000 + pmm-managed-server-ch: + profiles: + - pmm-ch + depends_on: + - ch + image: ${PMM_CONTAINER:-perconalab/pmm-server:dev-container} + container_name: pmm-managed-server + hostname: pmm-managed-server + networks: + - ${NETWORK:-default} + environment: + - PMM_RELEASE_PATH=/root/go/bin + - REVIEWDOG_GITHUB_API_TOKEN=${REVIEWDOG_GITHUB_API_TOKEN} + - ENABLE_DBAAS=${ENABLE_DBAAS:-0} + - AWS_ACCESS_KEY=${AWS_ACCESS_KEY} + - AWS_SECRET_KEY=${AWS_SECRET_KEY} + - ENABLE_BACKUP_MANAGEMENT=1 # - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost # - PERCONA_TEST_PLATFORM_INSECURE=1 # - PERCONA_TEST_PLATFORM_PUBLIC_KEY= # - PERCONA_TEST_TELEMETRY_INTERVAL=10s # - PERCONA_TEST_TELEMETRY_RETRY_BACKOFF=10s -# - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=127.0.0.1:9000 -# - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm -# - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 -# - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 + - PERCONA_TEST_PMM_CLICKHOUSE_ADDR=${CH_HOSTNAME:-ch}:9000 + - PERCONA_TEST_PMM_CLICKHOUSE_DATABASE=pmm + - PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE=10000 + - PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE=2 # - PMM_DEBUG=1 extra_hosts: @@ -59,6 +132,7 @@ services: - ${PMM_PORT_CH_HTTP:-11123}:8123 volumes: - ./:/root/go/src/github.com/percona/pmm +# - "../grafana/public:/usr/share/grafana/public" - ./Makefile.devcontainer:/root/go/src/github.com/percona/pmm/Makefile:ro # change Makefile in devcontainer # caching - go-modules:/root/go/pkg/mod diff --git a/managed/Makefile b/managed/Makefile index 52f42a1d85..0235e57d9a 100644 --- a/managed/Makefile +++ b/managed/Makefile @@ -36,8 +36,13 @@ release: ## Build pmm-managed release binaries. env CGO_ENABLED=0 go build -v $(PMM_LD_FLAGS) -o $(PMM_RELEASE_PATH)/ ./cmd/... $(PMM_RELEASE_PATH)/pmm-managed --version +ARCH=$(shell uname -m) release-dev: - go build -race -gcflags="all=-N -l" -v $(PMM_LD_FLAGS) -o $(PMM_RELEASE_PATH)/ ./cmd/... + @if [ $(ARCH) = "aarch64" ]; then\ + go build -gcflags="all=-N -l" -v $(PMM_LD_FLAGS) -o $(PMM_RELEASE_PATH)/ ./cmd/... + else \ + go build -race -gcflags="all=-N -l" -v $(PMM_LD_FLAGS) -o $(PMM_RELEASE_PATH)/ ./cmd/... + fi PMM_TEST_FLAGS ?= -timeout=90s PMM_TEST_RUN_UPDATE ?= 0