refactor(compose): Refactor for upstream correctness (#1)

This commit is contained in:
hygienic-books 2024-06-04 01:33:11 +02:00
parent 7982c081e5
commit 2ec27b49f4

View File

@ -21,8 +21,10 @@ When everything's ready start Zabbix with Docker Compose, otherwise head down to
Define variables assuming the official Zabbix Docker repo lives at `/opt/git/github.com/zabbix/zabbix-docker/branches/latest`: Define variables assuming the official Zabbix Docker repo lives at `/opt/git/github.com/zabbix/zabbix-docker/branches/latest`:
``` ```
export UPSTREAM_REPO_DIR='/opt/git/github.com/zabbix/zabbix-docker/branches/latest' export UPSTREAM_REPO_DIR='/opt/git/github.com/zabbix/zabbix-docker/branches/latest'
export UPSTREAM_REPO_TAG='6.4.4' export UPSTREAM_REPO_TAG='6.4.15'
export UPSTREAM_COMPOSE_FILE="${UPSTREAM_REPO_DIR%/}"'/docker-compose_v3_alpine_pgsql_latest.yaml' export UPSTREAM_COMPOSE_FILE="${UPSTREAM_REPO_DIR%/}"'/docker-compose_v3_alpine_pgsql_latest.yaml'
export UPSTREAM_COMPOSE_DB_FILE="${UPSTREAM_REPO_DIR%/}"'/compose_databases.yaml'
export UPSTREAM_ENV_FILE="${UPSTREAM_REPO_DIR%/}"'/.env'
export COMPOSE_CTX='bi_colombo' export COMPOSE_CTX='bi_colombo'
export COMPOSE_PROJECT_NAME='zabbixserver-'"${COMPOSE_CTX}" export COMPOSE_PROJECT_NAME='zabbixserver-'"${COMPOSE_CTX}"
export COMPOSE_ENV_FILE=<add accordingly> export COMPOSE_ENV_FILE=<add accordingly>
@ -37,9 +39,9 @@ docker context create fully.qualified.domain.name --docker 'host=ssh://root@full
## Pull ## Pull
Pull newest image versions: Pull newest image versions. Do this locally on your deployment machine, not on the actual app machine. Chances are the app machine cannot even pull directly from your container registry anyways:
``` ```
docker compose --project-name "${COMPOSE_PROJECT_NAME}" --file "${UPSTREAM_COMPOSE_FILE}" --env-file "${COMPOSE_ENV_FILE}" pull docker compose --project-name "${COMPOSE_PROJECT_NAME}" --file "${UPSTREAM_COMPOSE_FILE}" --env-file "${UPSTREAM_ENV_FILE}" --env-file "${COMPOSE_ENV_FILE}" pull
``` ```
## Copy to target ## Copy to target
@ -47,28 +49,36 @@ docker compose --project-name "${COMPOSE_PROJECT_NAME}" --file "${UPSTREAM_COMPO
Copy images to target Docker host, that is assuming you deploy to a machine that itself has no network route to reach Docker Hub. Copying in its simplest form involves a local `docker save` and a remote `docker load`. Consider the helper mini-project [quico.space/Quico/copy-docker](https://quico.space/Quico/copy-docker) where [copy-docker.sh](https://quico.space/Quico/copy-docker/src/branch/main/copy-docker.sh) allows the following workflow: Copy images to target Docker host, that is assuming you deploy to a machine that itself has no network route to reach Docker Hub. Copying in its simplest form involves a local `docker save` and a remote `docker load`. Consider the helper mini-project [quico.space/Quico/copy-docker](https://quico.space/Quico/copy-docker) where [copy-docker.sh](https://quico.space/Quico/copy-docker/src/branch/main/copy-docker.sh) allows the following workflow:
``` ```
source "${COMPOSE_ENV_FILE}" source "${UPSTREAM_ENV_FILE}" "${COMPOSE_ENV_FILE}" 2>/dev/null
while IFS= read -r image; do while IFS= read -r image; do
copy-docker.sh "${image}" fully.qualified.domain.name copy-docker "$(eval echo "${image}")" containers-1.ops.loft.seneve.de
done < <(grep -Pi -- '^[^#]*image:' "${UPSTREAM_COMPOSE_FILE}" | awk '{print $2}') done < <(grep -Pih -- '^[^#]*image:' "${UPSTREAM_COMPOSE_FILE}" "${UPSTREAM_COMPOSE_DB_FILE}" | awk '{print $2}')
``` ```
This first `grep`s a list of images and their tags from Zabbix' official Docker Compose file: This first `grep`s a list of images and their tags from Zabbix' official Docker Compose files:
``` ```
# grep -Pi -- '^[^#]*image:' "${UPSTREAM_COMPOSE_FILE}" | awk '{print $2}' # grep -Pi -- '^[^#]*image:' "${UPSTREAM_COMPOSE_FILE}" | awk '{print $2}'
zabbix/zabbix-server-pgsql:alpine-6.4-latest "${ZABBIX_SERVER_PGSQL_IMAGE}:${ZABBIX_ALPINE_IMAGE_TAG}${ZABBIX_IMAGE_TAG_POSTFIX}"
zabbix/zabbix-web-nginx-pgsql:alpine-6.4-latest "${ZABBIX_WEB_NGINX_PGSQL_IMAGE}:${ZABBIX_ALPINE_IMAGE_TAG}${ZABBIX_IMAGE_TAG_POSTFIX}"
postgres:14-alpine "${POSTGRESQL_IMAGE}:${POSTGRESQL_IMAGE_TAG}"
busybox busybox
``` ```
It then pushes each image to your remote host where the image is needed. Note that `busybox` implies `busybox:latest` by convention. It then expands each variable via `eval echo "${image}"` like so:
```
zabbix/zabbix-server-pgsql:alpine-6.4-latest
zabbix/zabbix-web-nginx-pgsql:alpine-6.4-latest
postgres:15-alpine
busybox
```
... and pushes each resulting image string to your remote host where the image is needed. Note that `busybox` implies `busybox:latest` by convention.
## Start ## Start
Run Zabbix like so Run Zabbix like so
``` ```
docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT_NAME}" --file "${UPSTREAM_COMPOSE_FILE}" --env-file "${COMPOSE_ENV_FILE}" up --detach docker --context 'fully.qualified.domain.name' compose --project-name "${COMPOSE_PROJECT_NAME}" --file "${UPSTREAM_COMPOSE_FILE}" --env-file "${UPSTREAM_ENV_FILE}" --env-file "${COMPOSE_ENV_FILE}" up --detach
``` ```
## Additional files ## Additional files
@ -196,17 +206,17 @@ while IFS= read -r; do commitDate=$(grep -Pio '^.+?(?=[[:space:]])' <<< "${REPLY
# Output goes like: # Output goes like:
... ...
2023-03-07-191829 9f2e726e554b23595489eb66c8e11e5d114b573f 6.4.0 2024-02-01-100454 4d62e7af5cf884763c5e66a5e376a77972fb632f 6.4.11
2023-04-03-105513 9f16f6d773a2a46f1595c86077899d1e040db283 6.4.1 2024-02-26-142242 a4e950ac473a82c2982ed2ebb5b82e4b2204e78a 6.4.12
2023-04-25-133446 0fa87156974e799e04bf99e5300bad6830d754ab 6.4.2 2024-03-25-175845 6b85028331f30dcd3440888d846babd12eb01ae2 6.4.13
2023-05-30-151931 d7b0eab80723a2c562a13ee866c4cd384af96d3b 6.4.3 2024-04-22-124800 7cb4ec29d4c34f006f2c92403022fb32eb778276 6.4.14
2023-06-27-133008 482e21c7803c2878e522aba0325bf04533efa61a 6.4.4 2024-05-21-131508 170db44b637acdb37d3c0f7b71d623c5488446e4 6.4.15
... ...
``` ```
Switch to desired tag Switch to desired tag
``` ```
git -C '/opt/git/github.com/zabbix/zabbix-docker/branches/latest' checkout 'tags/6.4.4' git -C '/opt/git/github.com/zabbix/zabbix-docker/branches/latest' checkout 'tags/6.4.15'
``` ```
## Apply patch ## Apply patch
@ -222,12 +232,11 @@ Apply `zabbix-docker.patch` to Docker Compose file. We use Zabbix' `docker-compo
git -C '/opt/git/github.com/zabbix/zabbix-docker/branches/latest' am '/opt/containers/zabbixserver/zabbix-docker.patch' git -C '/opt/git/github.com/zabbix/zabbix-docker/branches/latest' am '/opt/containers/zabbixserver/zabbix-docker.patch'
# Output will be: # Output will be:
Applying: refactor(compose): Remove trailing whitespace Applying: refactor(compose): Remove unneeded components
Applying: refactor(compose): 4 leading spaces Applying: refactor(zabbix-server): Set bind mounts
Applying: refactor(compose): Indent comments Applying: feat(stack): Extend env vars
Applying: refactor(zabbix-server): Set correct libs paths Applying: refactor(compose): Remove secrets and unneeded volume
Applying: refactor(zabbix-server): Set TLS cert file names Applying: refactor(zabbix-web-nginx): Exposed ports
Applying: feat(zabbix-server): Replace env files with variables
... ...
``` ```