Daemons and Workers
Deployment Sources
Docker Images
Each worker must specify a Docker image to use. Ptah.sh handles this in two ways:
-
For public registries:
- Specify the full form of the Docker image name (e.g.,
ghcr.io/ptah-sh/ptah-server:latest
). - No pre-configuration is needed for public registries.
- Specify the full form of the Docker image name (e.g.,
-
For private registries:
- Pre-configure your private registries in the Ptah.sh dashboard.
- When setting up a worker, select the appropriate private registry from a dropdown in the configuration form.
- Specify the image name and tag for your worker.
This approach streamlines the use of private registries and enhances security by centralizing credential management for private images.
For more detailed information on working with Docker registries in Ptah.sh, including how to pre-configure private registries, see the Docker Registries page.
Git-based Deployments
Ptah.sh supports deploying directly from Git repositories. This allows you to automatically build and deploy your application from your source code.
To set up Git-based deployments, you’ll need to add Ptah.sh’s SSH public key to your repository. The process varies depending on your Git provider:
GitHub
- Go to your repository settings
- Navigate to “Deploy Keys” under “Security”
- Click “Add deploy key”
- Give it a title (e.g., “Ptah.sh Deploy Key”)
- Paste the Ptah.sh public SSH key
- Check “Allow write access” if you need Ptah.sh to push to the repository
- Click “Add key”
GitLab
- Go to your repository settings
- Navigate to “Repository” → “Deploy Keys”
- Add a new deploy key
- Enter a title for the key
- Paste the Ptah.sh public SSH key
- Optionally enable write access
- Click “Add key”
Bitbucket
- Go to repository settings
- Navigate to “Security” → “Access keys”
- Click “Add key”
- Choose “SSH” as the key type
- Enter a label for the key
- Paste the Ptah.sh public SSH key
- Click “Add key”
You can find your Ptah.sh node’s public SSH key in the Node settings section of your Ptah.sh dashboard.
Git with Dockerfile
When using Git as a deployment source with a Dockerfile, Ptah.sh will:
- Clone your repository
- Build the Docker image using the Dockerfile in your repository
- Deploy the resulting image to your worker
To use this deployment method:
- Select “Git with Dockerfile” as the deployment source
- Specify the Git repository URL (supports any Git repository using SSH format)
- Specify the branch or tag to build from
- Specify the path to the Dockerfile if it’s not in the root directory
If you need to use a private Git repository, please add the public SSH key of the Ptah.sh node to the repository settings (usually as a deployment key). You can find the public SSH key in the Node settings in the Ptah.sh dashboard.
Git with Nixpacks
Nixpacks provides a zero-configuration approach to building container images from your source code. When using Git with Nixpacks, Ptah.sh will:
- Clone your repository
- Automatically detect your application’s framework and language
- Build an optimized container image using Nixpacks
- Deploy the resulting image to your worker
Key benefits of using Nixpacks:
- Zero configuration required - works out of the box for most applications
- Supports multiple languages and frameworks including:
- Node.js
- Python
- Ruby
- Go
- Java
- PHP
- Rust
- And many more
You can customize the Nixpacks build process by adding a nixpacks.toml
file to your repository root. This allows you to:
- Specify custom build commands
- Configure environment variables
- Define start commands
- Set up additional system packages
Example nixpacks.toml
:
Launch Modes
Launch modes specify how and when a worker should be started. This feature provides flexibility in managing resource usage and application behavior. Ptah.sh offers the following launch modes:
- Daemon or Queue Worker: The worker runs continuously as a background process.
- Schedule: Cronjob: The worker runs on a predefined schedule, similar to a cron job.
- Backup: create a backup: The worker is launched to create a backup of the service data.
- Restore: restore a backup: The worker is launched to restore service data from a backup.
Each launch mode is designed for specific use cases, allowing you to optimize your service’s behavior and resource utilization.
For more detailed information on launch modes, including how to configure and use them, see the Launch Modes page.
Healthcheck Configuration
Each worker can be configured with a healthcheck to monitor its health and availability. Healthchecks are crucial for maintaining the reliability of your services and enabling automatic recovery from failures.
When configuring a healthcheck, you need to provide the following information:
- Test: The shell command to run inside the container to check its health
- Interval: How often to run the healthcheck (in seconds)
- Timeout: Maximum time to wait for the healthcheck to complete (in seconds)
- Retries: Number of consecutive failures needed to consider the container unhealthy
- Start Period: Initial grace period during which failures don’t count towards the retry limit (in seconds)
Examples
-
For a web server:
- Test:
curl -f http://localhost/ || exit 1
- Interval: 30
- Timeout: 10
- Retries: 3
- Start Period: 40
- Test:
-
For a database:
- Test:
pg_isready -U postgres
- Interval: 10
- Timeout: 5
- Retries: 5
- Start Period: 60
- Test:
-
For a custom application:
- Test:
/app/healthcheck.sh
- Interval: 60
- Timeout: 30
- Retries: 3
- Start Period: 120
- Test:
By configuring healthchecks, you ensure that Docker Swarm can automatically detect and respond to service failures, improving the overall reliability and availability of your application.
Command (Entrypoint)
The command setting for a worker defines the main process that will run inside the container. This is typically the entry point for your application or service. For example:
-
For a Node.js application:
-
For a Python web application using Gunicorn:
-
For a custom shell script:
By specifying the command for each worker, you have fine-grained control over how each component of your service runs.
Release Command
Each worker may have a release command that is executed when the worker is started, before the default command of the container runs. This feature is particularly useful for performing setup tasks, running migrations, or other initialization processes that need to occur before the main application starts.
Release commands are typically used for:
- Database migrations: Updating the database schema before starting the application.
- Asset compilation: Building or compiling assets required by the application.
- Configuration updates: Modifying configuration files based on environment variables.
- Dependency checks: Ensuring all required services are available before starting the main process.
Examples
-
Running database migrations for a Rails application:
-
Running multiple commands in sequence:
To use a release command in Ptah.sh:
- When configuring your service, locate the “Release Command” field in the worker settings.
- Enter the command or script you want to run before the main container process starts.
- Ensure that any necessary dependencies or scripts are included in your Docker image.
By utilizing release commands, you can ensure that your application environment is properly prepared before the main process begins, leading to smoother deployments and reducing potential startup issues.
Backup Command
Each worker may also have a backup command that is executed when the service is stopped. The backup command is designed to create a snapshot of important data before the container is terminated.
Key points about the backup command:
- Execution context: The command runs within the container, similar to using
docker exec
. - Purpose: It’s used to create backups of critical data, configurations, or state information.
- Output handling: The backup file should be created in the current working directory. It will then be automatically compressed (gzipped) and uploaded to the specified S3 Storage.
Examples
-
For a PostgreSQL database:
-
For a Redis instance:
-
For a custom application data directory:
To use a backup command in Ptah.sh:
- When configuring your service, locate the “Backup Command” field in the worker settings.
- Enter the command or script you want to run when the container is about to stop.
- Ensure that your command saves the backup file in the current working directory.
- Ensure that you have configured an S3 Storage destination for your backups.
By utilizing backup commands, you can ensure that critical data is safely preserved before a container is terminated, facilitating easier recovery and data management. Remember that the backup file created in the current working directory will be automatically handled by Ptah.sh for compression and upload to S3 storage.
For more information on configuring and using S3 storage for backups, including setup instructions and restoration processes, see the S3 Storages page.