CLI · Winter Console

The service command

service works with the services components() declares: it shows them, writes what they need into the Dockerfile and shows what to add to compose.

Subcommands list · dockerWrites DockerfileNever edits compose

What service is and why

service is the command for the application’s services: a database, a cache, a queue running in one container with the application.

The problem. Every service needs something in the image — packages, directories, volumes — and all of it is written into the Dockerfile and compose by hand, and has to be remembered on every change of a version or a path.

The solution. A service describes what it needs. call service docker writes the Dockerfile — without it the program is not in the image. Compose is yours: the command only shows what to add to it, and you decide.

Subcommands

Subcommand Purpose
list The declared services: class, package, priority, apk packages, volumes, variables
docker Writes a block into the Dockerfile, shows what compose needs

list

bash
php call service list

For each service — what it is and what it needs:

text
[ redis ]
class       Main\Services\Redis
package     the project
priority    High
packages    redis
volume      redis-data → /var/lib/redis
[ redis ]

package is the Composer package the service class comes from, with its version; the project is a class of the project itself.

docker

bash
php call service docker

Syntax

text
call service docker [--dry] [--service=name]

Parameters

--dry — show what would be written, and change nothing.

--service=name — the compose service the application runs as, for the hint. By default the first one in docker-compose.yml, and server without one.

What it does

  • Dockerfile — one block between the # winter:services and # winter:services end marks: apk packages, directories owned by winter, run commands, ENV variables. The first time the block goes before the first COPY of the last stage, then it is replaced in place. With no services left, the block is removed.
  • compose — not changed. The command prints what to add to it:
    • stop_grace_period — the application’s stop time plus 5 seconds. Without it Docker kills the container after 10 seconds;
    • volumes for the services’ data — if the data must outlive a recreated container. Not needed? Leave them out. The path is already inside a volume of yours? Skip that one.

Result

text
  Dockerfile .................................................... [UPDATED]
[i] Compose is yours: add to docker-compose.yml, service "server", what fits:
[ docker-compose.yml ]
  services:
    server:
      stop_grace_period: 70s
      volumes:
        - postgres-data:/var/lib/postgresql/data
  volumes:
    postgres-data:
[ docker-compose.yml ]
[i] stop_grace_period: a stop needs 70s; without it Docker kills the container after 10s.
[i] volumes: keep the data when the container is recreated. Leave them out if it need not survive; skip one whose path is already inside a volume of yours.
[i] Rebuild the image to take it in:  docker compose up -d --build

Run again with nothing changed: Dockerfile … [UNCHANGED], the same hint.

Errors

  • No Dockerfile — No Dockerfile in the project: create one with `call cfg docker` first.
  • The block’s start mark is there and its end is not (the block was edited by hand) — the command guesses nothing and asks to put # winter:services end back or remove the block.
  • Two services ask for one thing in two ways (a directory with two modes, one variable with two values) — an error naming what differs; nothing is written.
  • A component has $grace = 0 (wait as long as it takes) — the hint has no stop_grace_period, and a warning says so.

Next