Skip to content

Commit 6151908

Browse files
committed
+ kamal: add note about pre-app-boot
1 parent f046047 commit 6151908

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

docs/deployment/kamal.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,30 @@ accessories:
244244

245245
**IMPORTANT**: The setup above expose the gRPC server to the public (so it's reachable from other machines). We recommend securing access either by setting up firewall rules / virtual network within the cluster or using TLS with a private certificate for gRPC (see [configuration docs](https://docs.anycable.io/anycable-go/configuration?id=tls)).
246246

247-
Alternatively, you may consider adding a standalone load balancer with gRPC support (this is out of scope of this guide).
247+
The setup above has one caveat: since we publish RPC port (`50051`) to the host system, default Kamal rolling updates would fail with the `port is already in use` after Kamal would have tried to launch a new copy of the `rpc` container. To avoid that, we can use the `pre-app-boot` hook to stop RPC containers (it's okay to have a short downtime here, AnyCable server would take care of recovering). This is an example `.kamal/hooks/pre-app-boot` code:
248+
249+
```sh
250+
#!/bin/bash
251+
# This script is a Kamal pre-app-boot hook.
252+
# It uses 'kamal app stop' to stop old containers of the 'rpc' role
253+
# This helps prevent "port already allocated" errors for services with fixed published ports.
254+
255+
# Exit immediately if any command fails.
256+
set -e
257+
258+
KAMAL_CMD="kamal" # Or "./bin/kamal" or "/path/to/kamal_executable"
259+
260+
# The role whose containers need to be stopped.
261+
# This must match the role name in your deploy.yml
262+
ROLES_TO_STOP="rpc"
263+
KAMAL_ARGS=(--roles "$ROLES_TO_STOP")
264+
265+
if "$KAMAL_CMD" app stop --roles "${ROLES_TO_STOP}"; then
266+
echo "'kamal app stop --roles $ROLES_TO_STOP' completed successfully."
267+
else
268+
exit_code=$?
269+
echo "Error: '$KAMAL_CMD app stop --roles $ROLES_TO_STOP' failed with exit code $exit_code." >&2
270+
271+
exit $exit_code
272+
fi
273+
```

0 commit comments

Comments
 (0)