Skip to content

Let a server pull images

$ grim server:ghcr-login --host=vps1

A release builds the image on your side and the server pulls it from ghcr.io. The images are private, so the server needs credentials of its own. You reach for this command when grim server:setup ran without --ghcr-token, when a deploy stops because the registry refuses the pull, or when the token on the server has expired and a new one has to go to every server you have.

Usage

$ grim server:ghcr-login --host=vps1                    # asks for the token, input hidden
$ grim server:ghcr-login --host=vps1 --token=ghp_xxx    # no prompt, for scripts
$ grim server:ghcr-login --all                          # every server you have registered
$ grim server:ghcr-login --host=vps1 --user=acme        # log in under another GitHub name

Run it from anywhere. The server must be in your ~/.grim/servers.json, which is where grim server:setup put it. One of --host and --all is required.

Arguments and options

Register or refresh GHCR credentials on a server (so docker can pull private ghcr.io/{owner}/grim-* images)

Usage

grim server:ghcr-login [--host HOST] [--token TOKEN] [--user USER] [--all]

Options

Option Description
--host=HOST Server alias or host
--token=TOKEN GitHub classic PAT with read:packages scope (interactive prompt when omitted)
--user=USER GitHub username (defaults to your grim-cli auth user)
--all Apply to every server registered in ~/.grim/servers.json

What it actually does

  1. Picks the servers. The one behind --host, or with --all every server in servers.json.
  2. Picks the GitHub name. --user, or the account you logged in with through grim auth:login.
  3. Asks for the token, unless --token carries it. The prompt hides what you type and reminds you which kind of token is accepted.
  4. Logs in on each server. Connects as that server's service user, which is deploy on a production server, checks that Docker is there and runs docker login ghcr.io. Docker keeps the credentials in that user's home, where every later pull finds them.
  5. Prints one result per server, ✓ Login Succeeded or Docker's own error. If any server failed, the command exits with an error and tells you to repeat it for that host.

Pitfalls

GHCR takes a classic token only

A fine-grained token is accepted by GitHub and still cannot pull an image. Create a classic token with the read:packages scope. When the images belong to an organisation, the token's owner needs read access to that organisation's packages.

--all means every server, dev boxes included

--all walks the whole of servers.json and logs in each server's own service user, dev on a shared dev box. That is what you want after rotating one team token. It is not what you want when production and development are meant to use different tokens.

A token on the command line stays in your shell history

--token exists for scripts. At a terminal, leave it out and paste the token at the hidden prompt. Without a terminal there is no prompt, and the command stops with --token is required when running non-interactively.

After it finishes

The server can pull. Repeat the release or the deploy that failed.

$ grim release

Recipes that use it