What are all the hook types I can use in app.yml

Hello, Trying to setup a hook to automatically connect to my docker network when discourse restarts or boots back up after building. This is so I can use the admin web updater when I can but trying to figure out the best way to go about this. Docs don’t really say all the hook types I can use and Looking up hooks such as after_post_boot and after_restart does nothing. Do these hooks no longer work and if so, why? Here’s my hooks code.

hooks:

begin custom network hook

after_restart:

  • exec:
    cmd:
  • bash
  • “-c”
  • |

Connect Discourse to the custom Docker network if not already connected

NETWORK_NAME=“proxy”
CONTAINER_NAME=$(hostname)

        # Create the network if it doesn't exist
        if ! docker network inspect "$NETWORK_NAME" >/dev/null 2>&1; then
          echo "Creating Docker network: $NETWORK_NAME"
          docker network create "$NETWORK_NAME"
        fi

        # Connect container to the network (ignore if already connected)
        echo "Connecting $CONTAINER_NAME to $NETWORK_NAME..."
        docker network connect "$NETWORK_NAME" "$CONTAINER_NAME" 2>/dev/null || true

        echo "Network connection complete."

END custom network hook

There isn’t actually a fixed global list of hook types in app.yml.
Hooks are provided dynamically by Pups, and you can only attach to the ones that exist inside the templates you include.


:magnifying_glass_tilted_left: How it works

When you see something like:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

that works because the templates contain a step like:

- hook: code
  run:
    - exec: ...

Pups lets you attach commands before or after any of those defined hook points.
So if a template defines hook: code, you can use before_code: or after_code:.
If it defines hook: assets_precompile, you can use before_assets_precompile: or after_assets_precompile: — and so on.

If there’s no hook: restart (for example), then after_restart: simply won’t fire.


:white_check_mark: Hooks known to exist in the stock templates

From the default templates/*.yml shipped with Discourse Docker:

Hook name Common usage Works with
code Main setup stage for plugin clones, custom file edits, etc. before_code: / after_code:
assets_precompile After Rails assets are compiled (e.g., upload to S3, clean up) after_assets_precompile:
web For last-minute tweaks before the web process boots before_web:

You’ll often see after_code: and before_code: used in plugin-install examples — these are the only ones needed in most setups.


:cross_mark: Hooks that don’t exist by default

Names like after_restart or after_post_boot don’t correspond to any hook: inside the standard templates, so Pups doesn’t know where to attach them.
They won’t trigger unless you add a matching hook: restart step in a custom template.


:toolbox: How to find all hooks available on your system

From your /var/discourse folder, run:

grep -R "hook:" -n templates/ samples/

That’ll list every hook name supported by the templates you currently include.
Anything you find there can be used as before_<name>: or after_<name>: inside your hooks: block.


:blue_book: Reference

This behaviour is explained briefly in the Pups README (the config-management tool used by Discourse’s Docker setup):

“Hooks are points in templates that allow commands to be injected before or after a step labelled with hook:.”


:puzzle_piece: In practice

  • Use after_code: for most custom shell commands (like plugin installs).
  • For things that should happen at container boot or restart, use a small startup script or supervisord task instead of inventing new hook names.
  • To add your own hook type, make a new template with a custom hook: something entry, then target it from app.yml.

TL;DR:
Only the hook names that actually appear as hook: entries in your templates exist.
In stock Discourse Docker, that’s basically code, assets_precompile, and web.

2 Likes

For reference I believe the pups repo is here:

@Ethsim2 I do not see anything about

Perhaps you should look through AI’s response before posting it :slightly_smiling_face: .

From the README:

Execute commands before and after a specific command by defining a hook.

1 Like

From GitHub Repo:

how about?

Hooks let you execute custom commands before or after a specific build step, by defining before_<name>: or after_<name>: corresponding to a hook: <name> label in a template.

1 Like

I don’t think hooks are going to help you. You’re saying that when you run the web-updater your container disconnects from the docker network?

I’m pretty sure that the web-updater does not restart the container–that’s how it’s able to run without shutting down Discourse.

1 Like

This is correct.

It also should be noted that hooks are run inside the container, to build the discourse image. Nothing there is run on the host, and there is no way through launcher functions to recreate or destroy docker networks.

Perhaps it would be better to explain what problem you’re running into in your hosting so we have a better understanding what you’re attempting to solve

1 Like

Only updated through cli and that disconnects from the docker network but that’s only because the container restarts from that point. I’ll try the web updater as I have not tried that with this setup yet. I thought the same behavior would indeed happen here as well but if the web updater does not shutdown the containers then there’s really nothing to worry about. Reason "y I stated all of this was because I seen people have issues when running the web updater at that point. but I’ll try the updater and see how it goes.

Jonnyboy! Iphones rock!