Skip to content

Rebuild a server's compose file

$ grim server:sync-compose shop

A server still runs the compose file it got on the day the project was added, the template has changed since, and you are not sitting in the project's checkout. That is the case for this command. It needs nothing but the project's record in your ~/.grim/servers.json: what the stack consists of, it reads from the server.

From inside the project directory, grim server:upgrade is the better tool, because it also honours what grim.json says. The two are compared there.

Usage

$ grim server:sync-compose shop                  # write the file and recreate the containers
$ grim server:sync-compose shop --no-recreate    # write the file, leave the containers alone

Run it from anywhere. The project must have been registered with grim server:add-project on this machine.

Arguments and options

Re-render docker-compose.yml on a server from the current template and recreate containers

Usage

grim server:sync-compose [--no-recreate] [--] <project>

Arguments

Argument Description
project Project name (as registered via server:add-project) (required)

Options

Option Description
--no-recreate Upload new compose but do not restart containers

What it actually does

  1. Looks the project up in servers.json for its host, domain and path.
  2. Reads the compose file on the server to see whether it has a Horizon and a Reverb service. The new file gets the same ones.
  3. Writes /opt/shop/docker-compose.yml from the current template, with the domains attached by grim server:add-domain kept in the Traefik rule.
  4. Makes .env writable for the app. The container's www-data user gets write access to /opt/shop/.env, which the current template mounts into the containers as a file.
  5. Recreates every container of the project with docker compose up -d --force-recreate and shows Docker's output. Skipped with --no-recreate.

Pitfalls

An image name set in grim.json is lost

The command never reads grim.json, so docker.image and docker.owner do not reach the new file. It names the default image. For a project that pulls from its own namespace, use grim server:upgrade from the project directory instead.

The site is interrupted

Recreating every container takes the app away for a moment. With --no-recreate the new file waits on the server until the next deploy or until you restart the stack yourself.

The project is not on record

Project 'shop' not found. Run server:add-project first. means this machine's servers.json does not know the project. It is a local record, not a fact about the server. Run the command where the project was registered.

Only the default environment

There is no --env. The command works on the project's default environment, the first one you registered.

After it finishes

The last line suggests a check to run on the server, inside /opt/shop. It lists the mounted .env as the app container sees it.

$ docker compose exec app ls -la /var/www/html/.env