Skip to content

Deployment

The server only pulls and runs images. They are built, tested, scanned and signed in GitHub Actions when a release of magenxcommerce-docker is published, and magenx-deputy-go deploys each release to the server. What runs on the server is in Docker stack.

mergesigned webhook

Push to main

release-please
release PR

Build changed images
scan · test stack

Push to ghcr.io
cosign sign + SBOM

Stack bundle
to S3, signed

Publish release

deputy on the server
verify · pull · up

The release workflow runs on every push to main:

  1. release-please keeps a release PR from conventional commits: fix: is a patch, feat: a minor and feat!: a major version. Merging it creates a draft release vX.Y.Z.
  2. Each image gets a fingerprint: a hash of its build arguments (including the base image digests), target, build context and build secret. An image whose fingerprint already exists in the registry is reused, so only changed images are built.
  3. Changed images are scanned with Trivy. A CRITICAL or HIGH CVE that has a fixed version fails the release; CVEs without a fix are listed in the job summary. Syft writes an SPDX SBOM of each image.
  4. The whole stack starts on the runner and must pass every health check.
  5. The images are pushed to ghcr.io and tagged with the release version. Every digest is signed with cosign, with its SBOM as a signed attestation. Unchanged images keep their digest, so the server doesn’t recreate those containers.
  6. The release gets docker-compose.release.yml, which pins every image by digest, and sbom.tar.gz. The repository at the release commit plus that lock file are packed into a stack bundle, signed, and uploaded to S3 for deputy.
  7. The release is published, and the workflow sends deputy a signed webhook. The job waits for the deploy and fails if it fails.

A nightly workflow re-checks the signatures of the latest release and scans its images for CVEs published since. Findings go into one open issue labelled image-cve.

The server needs Debian 12/13 or Ubuntu 22/24, a load balancer in front of it for TLS (see Overview), a Magento Marketplace key pair, and a GitHub token with read:packages to pull the images.

The first deploy can’t be left to deputy alone: deputy’s up --wait needs every health check to pass, and the GraphQL worker’s check queries the store, which only works once Magento is installed. So the backing services come up first, Magento is installed, and then deputy takes over.

  1. Run docker.sh with the brand name as root. It turns on user namespace remapping, installs Docker, clones the stack to /opt/<brand>/docker, opens .env and .env.secrets in an editor, generates passwords, and creates the Magento folder layout.

  2. Log in to the image registry:

    Terminal window
    docker login ghcr.io
  3. In /opt/<brand>/docker, download the lock file of the release to deploy and check its signatures:

    Terminal window
    gh release download vX.Y.Z -p docker-compose.release.yml --clobber
    bash scripts/verify_release.sh docker-compose.release.yml

    docker.sh doesn’t install the GitHub CLI; the lock file can also be downloaded from the release page.

  4. Use the lock file for every compose command in this shell, so the setup scripts pull the release images instead of building them, and start the backing services:

    Terminal window
    export COMPOSE_FILE=docker-compose.yml:docker-compose.release.yml
    docker compose pull mariadb opensearch cache session rabbitmq magento
    docker compose up -d --no-build --wait mariadb opensearch cache session rabbitmq
  5. Create the OpenSearch and RabbitMQ users, then install Magento (or import an existing database, see below):

    Terminal window
    bash opensearch/create_user.sh
    bash rabbitmq/create_user.sh
    bash scripts/install_magento.sh
  6. Set up private admin access, Cloudflare Tunnel or Tailscale, and point the Magento admin URL to its hostname.

  7. Set up deputy (next section) and send it the webhook for the same release, by re-running the release workflow’s publish job. Deputy uses the same compose project name, takes over the running containers and starts the rest.

deputy is a small service on the server that deploys both Magento code and stack releases. For a stack release it:

  1. Skips the release if current already points to it.
  2. Downloads the bundle from S3, checks its SHA256 against the webhook and its cosign signature against a public key configured on the server. It never trusts a key from the bundle.
  3. Requires every image in the lock file to be pinned by digest and verifies each one with cosign.
  4. Unpacks it to /opt/<brand>/stack/releases/vX.Y.Z and links .env.secrets from /opt/<brand>/docker.
  5. Refuses an image change of a service in confirm_services (by default MariaDB and OpenSearch) unless the webhook confirms it.
  6. Pulls, switches current, and runs docker compose up -d --no-build --wait.
  7. If up or the health check fails, it points current back to the previous release and starts it again.

deputy takes the services to start from its own stack.profiles setting, not from COMPOSE_PROFILES in .env. Set it to [cloudflare, observability] to deploy cloudflared, the collector and OpenObserve, with tailscale in place of cloudflare for the Tailscale setup. Its server setup is in the deputy README, section Docker stack deploys.

Once deputy deploys, run one-off commands from the deployed release with the lock file, never docker compose up in /opt/<brand>/docker: that clone isn’t updated and would start older compose files under the same project name.

Terminal window
cd /opt/<brand>/stack/current
docker compose -f docker-compose.yml -f docker-compose.release.yml run --rm magento cache:flush

docker.sh adds the alias doco for docker compose. The examples below assume the lock file is in use, as above.

  • Magento CLI, Composer and n98-magerun2, each in a container that is removed afterwards:

    Terminal window
    doco run --rm magento cache:flush
    doco run --rm magento setup:upgrade
    doco run --rm magento composer require vendor/module
    doco run --rm magento n98 sys:info
  • Database shell, and importing a dump. -T is required with a file on stdin, and the password goes in MYSQL_PWD because there is no terminal to type it. A dump usually drops and recreates its tables, so back up first:

    Terminal window
    . .env.secrets && doco exec -e MYSQL_PWD="$MARIADB_ROOT_PASSWORD" mariadb mariadb -uroot
    . .env.secrets && doco exec -T -e MYSQL_PWD="$MARIADB_ROOT_PASSWORD" mariadb mariadb -uroot <brand> < backup.sql
  • PHP OPcache status and reset, with cachetool over FastCGI:

    Terminal window
    bash scripts/opcache.sh opcache:status
    bash scripts/opcache.sh opcache:reset
  • Every password is in .env.secrets. The Magento admin is on the private admin hostname (Cloudflare Tunnel or Tailscale), at the random path ADMIN_PATH from that file. See Security and admin access.

SymptomCause and fix
required variable VALKEY_PASSWORD is missing a value: missing, load .env.secretsThe shell has no COMPOSE_ENV_FILES, for example in screen or after su without -. export COMPOSE_ENV_FILES=.env,.env.secrets, or open a login shell.
cannot attach stdin to a TTY-enabled containerdocker compose exec with a file on stdin. Add -T.
doco run --rm magento exits without outputUsually the same missing .env.secrets, or no Magento code in public/current yet.
A script fails with curl: not found inside a containerThe hardened runtime images have no curl. Run the request from the host, from a -dev image, or with bash /dev/tcp as the stack’s own scripts do.
The admin URL answers 403 on the shop domainExpected: the admin is on the private hostname. Open https://<private hostname>/, or see Magento admin URL.
cloudflared or tailscale stays unhealthycloudflared: TUNNEL_TOKEN is missing or wrong, or outbound traffic to Cloudflare is blocked. tailscale: the node isn’t logged in; check TS_AUTHKEY and its tag:magento tag, then doco exec tailscale tailscale --socket=/tmp/tailscaled.sock status.
The first deploy fails at up --waitMagento isn’t installed yet, so the GraphQL worker’s health check fails. Follow A new server.
A release fails on a CVEUpdate the base image digest or the package. If the fix can’t be taken yet, add the CVE to .trivyignore with the image, the reason and a review date.