- C# 97.3%
- Dockerfile 2.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| ASK.LiveCompose | ||
| ASK.LiveCompose.Tests | ||
| LICENSES | ||
| .gitignore | ||
| ASK.LiveCompose.sln | ||
| compose.yml | ||
| Dockerfile | ||
| README.md | ||
| REUSE.toml | ||
LiveCompose
LiveCompose is a lightweight API that allows you to update your Docker Compose services via webhooks. It simplifies the deployment process by enabling you to pull updates and run your services with minimal effort, making it ideal for continuous integration workflows.
Features
- Execute compose
ps/pull/up/down/restart/logson whole project or specific services in a Docker Compose file via API calls. - Modify environment variables in the
.envfile using query strings. - Access real-time service logs.
- Unique project ID generation for easy management.
- Integrated Rate Limiting
Warning
All API calls must be made over HTTPS to ensure security. It is essential to set up a reverse proxy (such as Nginx or Traefik) for SSL termination before deploying LiveCompose. Additionally, implement IP restrictions in your reverse proxy configuration to control access to the API and enhance security. Direct HTTP calls should be avoided to protect sensitive data.
Project Auth-Tokens and Authentication
Each project has its own Auth-Token, chosen at deployment time. LiveCompose never stores it in clear: the project directory (the one containing the compose file) must contain a .livecompose-token file holding the SHA-256 hash (hexadecimal) of the token.
- A project without
.livecompose-tokenfile cannot be accessed through the API. - The file is read on each request: a token can be changed without restarting LiveCompose.
- The token must be sent using the
X-Auth-TokenHTTP Header. - The file name can be changed with the ASK_LiveCompose__TokenFileName environment variable (default:
.livecompose-token).
Create the token file manually:
TOKEN=$(openssl rand -hex 32)
printf '%s' "$TOKEN" | sha256sum > /path/to/project/.livecompose-token
chmod 600 /path/to/project/.livecompose-token
echo "$TOKEN" # store it as a masked variable in your CI
Or with Ansible (app_livecompose_token being stored in Ansible Vault):
- name: LiveCompose access token
ansible.builtin.copy:
dest: "{{ app_dir }}/.livecompose-token"
content: "{{ app_livecompose_token | hash('sha256') }}\n"
mode: "0600"
up, pull and down always run to completion, even if the client disconnects (CI timeout, network failure...), so a project is never left half deployed.
When a docker command fails, the last line of the response is Docker command failed with exit code X. and the connection is aborted, so curl exits with a non-zero code and CI jobs fail accordingly.
Deployment
You can deploy LiveCompose using the Docker image askbe/livecompose.
Important
The directories of your compose projects (here
/srv/apps) must be mounted at the same path inside the LiveCompose container: docker commands run in the project directory, and the.envand.livecompose-tokenfiles are read from there.
Important Reverse Proxy Configuration
When deploying a reverse proxy, ensure you configure it to allow traffic only from specific IP addresses that require access to the LiveCompose API. This adds an additional layer of security.
Using Docker Command
Run the following command to start the LiveCompose service:
docker run -d \
--name livecompose \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /srv/apps:/srv/apps \
-p 9000:8080 \
askbe/livecompose:latest
Using Docker Compose (Optional)
If you prefer to use Docker Compose, here’s a sample docker-compose.yml file:
services:
livecompose:
image: askbe/livecompose:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /srv/apps:/srv/apps
ports:
- 9000:8080
To start the service using Docker Compose, run:
docker-compose up -d
This will achieve the same result as the direct Docker command.
Limit Available Projects
Only the projects whose directory contains a .livecompose-token file are available through the API (see Project Auth-Tokens and Authentication). To disable API access to a project, delete this file.
Projects are discovered on demand with docker compose ls -a: a project created after LiveCompose started is available without restart, as long as its containers have been created at least once (e.g. a first docker compose up on the host).
Restrict Access by Source Address
Declare the addresses allowed to reach LiveCompose, in CIDR notation:
- ASK_LiveCompose__TrustedNetworks__0: Address or network of the reverse proxy, or of a client calling LiveCompose directly without reverse proxy (e.g. a GitLab runner on the same private network). Use
192.0.2.10/32for a single server. Add__1,__2... for several entries.
Once at least one entry is declared:
- LiveCompose only accepts connections from these addresses (and loopback), any other connection is rejected with
403 Forbidden. - The client IP address logged for each authentication attempt is read from the
X-Forwarded-Forheader, when present.
This filter is the recommended protection whenever the LiveCompose port is published. To restrict the clients reaching LiveCompose through the reverse proxy, configure it on the proxy itself (e.g. Traefik ipAllowList middleware).
Warning
- Traffic to LiveCompose is plain HTTP and carries the auth tokens: use a private network or a VPN between LiveCompose and its proxy or clients.
- Do not declare a docker network subnet unless LiveCompose is only reachable from that network: connections made from the docker host to a published port come from the gateway of the docker network, they would be allowed.
Rate Limiting
Rate limiting is enabled on the api by default and can be customized using the following environment variables (default limit is 5req/sec):
- ASK_LiveCompose__EnableRateLimit: Boolean, Enable to Disable Rate Limiting (default : true)
- ASK_LiveCompose__RateLimit: Number of request allowed by Window (default :5)
- ASK_LiveCompose__RateDelaySecond: Window Delay Seconds (default :1)
- ASK_LiveCompose__RateLimitQueueSize : Number of requests put in queue before dropping requests (default: 0)
Example Usage
Here’s how you can use curl to update your services, retrieve logs, and check status.
1. Docker compose up a project:
A complete project
curl -X POST \
-H X-Auth-Token:701b0bbeb927cbeb41435c1b5dc39d57\
"https://yourdomain.com/projects/reverse_proxy/up"
A single service
curl -X POST \
-H X-Auth-Token:701b0bbeb927cbeb41435c1b5dc39d57\
"https://yourdomain.com/projects/reverse_proxy/services/service_a/up"
Note
It's also possible to update the environment variables in the
.envfile. Simply pass the variable name to update prefixed with "ENV_" in the query string parameters.Example:
curl -X POST \ -H X-Auth-Token:701b0bbeb927cbeb41435c1b5dc39d57\ "https://yourdomain.com/projects/reverse_proxy/up?ENV_VAR1=value1&ENV_VERSION=2.4.0"
Note
upis executed with--wait: the call only ends once the services are running (or healthy when they define a healthcheck), and fails if one of them does not start. Services that are expected to exit (one-shot jobs) make the call fail.
2. Docker compose down a project:
A complete project
curl -X POST \
-H X-Auth-Token:701b0bbeb927cbeb41435c1b5dc39d57\
"https://yourdomain.com/projects/reverse_proxy/down"
A single service
curl -X POST \
-H X-Auth-Token:701b0bbeb927cbeb41435c1b5dc39d57\
"https://yourdomain.com/projects/reverse_proxy/services/service_a/down"
3. docker compose pull a project:
A complete project
curl -X POST \
-H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/pull"
A single service
curl -X POST \
-H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/services/app/pull"
4. docker compose logs:
A complete project
curl -H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/logs"
A single service
curl -H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/services/app/logs"
Note
The following query string parameters can be specified while requesting logs
f=true: Boolean value, Follow log output until the client disconnects (default false)t=true: Boolean value, Add timestamp before each line (default false)n=xxx: Number of lines to show from the end of the logs for each container or "All" for everything (default All)since=xxx: Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)Example:
curl -H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\ "https://yourdomain.com/projects/bookstack/logs?since=15s"
5. docker compose restart:
A complete project
curl -X POST \
-H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/restart"
A single service
curl -X POST \
-H X-Auth-Token:234b034b927cbeb41435c1b5dc39345\
"https://yourdomain.com/projects/bookstack/services/app/restart"
Note
restartonly restarts the existing containers: changes to the compose file, the.envfile or the images are not applied, useupfor that.
6. Check Docker Compose Status:
curl -H X-Auth-Token:234b034b927cbeb41435c1b5dc39345 "https://yourdomain.com/projects/bookstack"
Usage with Gitlab-ci
Sample job to deploy in staging environment
Two variables are defined at CI level
- TEST_DEPLOYMENT_KEY: The auth token for the project
- TEST_DEPLOYMENT_SERVER : The url to the deployed ask.livecompose service
deploy-test:
stage: deploy
image: curlimages/curl:latest
rules: # only run if a tag is created
- if: $CI_COMMIT_TAG
when: manual # Deployment is manual (remove this line to make it automatic)
environment: # see https://docs.gitlab.com/ee/ci/environments/ for more information about environments
name: test
url: https://staging.example.com
script:
# Pull new version and update VERSION environment variable in the .env file
- curl --fail -X POST -H X-Auth-Token:${TEST_DEPLOYMENT_KEY} "${TEST_DEPLOYMENT_SERVER}/projects/project_name/pull?ENV_VERSION=${CI_COMMIT_TAG}"
# Restart the containers, the job fails if a service does not start (or is not healthy)
- curl --fail -X POST -H X-Auth-Token:${TEST_DEPLOYMENT_KEY} "${TEST_DEPLOYMENT_SERVER}/projects/project_name/up"
# Display the startup logs of service app
- curl -H X-Auth-Token:${TEST_DEPLOYMENT_KEY} "${TEST_DEPLOYMENT_SERVER}/projects/project_name/services/app/logs?n=50"
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss improvements.
License
This project is licensed under the GPL-3.0-or-later License or later. See the LICENSES folder for details.