Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server: Decoupled maintenance procedure #447

Merged
merged 9 commits into from
Nov 29, 2024

Conversation

martastain
Copy link
Member

@martastain martastain commented Nov 22, 2024

Configuration examples

Default behavior (all in one)

By default, Ayon runs setup, server and mainenance in the single container.
If no AYON_RUN_ environment variable it is an equivalent to

server:
  image: ynput/ayon:latest
  environment:
    - "AYON_RUN_SETUP=true"
    - "AYON_RUN_SERVER=true"
    - "AYUN_RUN_MAINTENANCE=true"

When the container starts, setup is executed to ensure the database is up to date,
then the server is started and Maintenance procedure is scheduled as its background process.

This is perfectly fine for small, non-scaled deployments.

Separate containers

Maintenance procedure can run scheduled in a separate container.

server:
  image: ynput/ayon:latest
  environment:
    - "AYON_RUN_SETUP=true"
    - "AYON_RUN_SERVER=true"
    - "AYON_RUN_MAINTENANCE=false"

maintenance:
  image: ynput/ayon:latest
  depends_on:
    - server
  environment:
    - "AYON_RUN_SETUP=false"
    - "AYON_RUN_SERVER=false"
    - "AYON_RUN_MAINTENANCE=true"

This way an additional container maintenance is started. This container lives indefinitely
and executes maintenance procedure on times specified in the server settings.

This configuration is useful for scaled deployments, where multiple server containers are running.
But since the maintenance container lives indefinitely, it is not recommended for kubernetes-based
deployments where you pay for the resources you use.

Cron-based maintenance

You may also execute the maintenance procedure using cron. This is useful for deployments
where you have a dedicated server or a VM. In this scenario, server settings cannot be used for
scheduling the maintenance period.

Instead you use cron to execute the following command:

docker compose run server python -m maintenance --one-shot

To schedule the task, create /etc/cron.d/ayon with the following content:

# execute ayon maintenance every day at 3:00
0 3 * * * root cd /opt/ayon && docker compose run server python -m maintenance --one-shot

Separating setup

For scaled deployments, it is not desirable to run setup on every server container.
Instead, you can run setup in a separate container and then start the server containers.

This is tricky to do with docker-compose, but it can be achieved in kubernetes or a shell script.
The following script demonstrates an upgrade procedure of a stack with separate containers.

docker compose pull

# start the database and redis (or ensure they are running)
docker compose up redis db --detach

# run the setup in this case, the procedure is blocking
# so server wont start until setup is finished
docker compose run server python -m setup --ensure-installed

# rebuild and start the server and maintenance containers
doccker compose up server maintenance --detach --build

@martastain martastain linked an issue Nov 22, 2024 that may be closed by this pull request
@martastain martastain self-assigned this Nov 22, 2024
@martastain martastain added the type: enhancement Improvement of existing functionality or minor addition label Nov 22, 2024
@martastain martastain requested a review from iLLiCiTiT November 26, 2024 10:55
@martastain martastain marked this pull request as ready for review November 26, 2024 10:55
@martastain martastain requested review from 64qam and MilaKudr November 26, 2024 10:55
@martastain martastain merged commit 4a56fe8 into develop Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvement of existing functionality or minor addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server maintenance procedure
3 participants