Documentation
¶
Index ¶
- type Middleware
- func (Middleware) CaddyModule() caddy.ModuleInfo
- func (m *Middleware) Cleanup() error
- func (m *Middleware) Provision(ctx caddy.Context) error
- func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (m *Middleware) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware struct {
// Secret is the shared webhook credential. It must match the `{secret}`
// path segment on every deploy request. Required.
Secret string `json:"secret,omitempty"`
// DockerHosts is the list of Docker Engine API endpoints to consider
// (for example `unix:///var/run/docker.sock` or `tcp://host:2375`).
// Only hosts where the named container is already running are updated.
// Defaults to the local Docker socket when omitted.
DockerHosts []string `json:"docker_hosts,omitempty"`
// contains filtered or unexported fields
}
Middleware is an HTTP handler that implements a rolling deployment strategy for Docker containers. It exposes a deploy webhook and leaves all other requests to the next handler in the chain.
### Caddyfile example
Enable the webhook on `deploy.example.com` (HTTPS via Caddy's automatic certificates). Caddy must be able to reach each Docker Engine API endpoint listed in `docker_hosts`:
```
deploy.example.com {
rolling_deployment {
secret {$ROLLING_DEPLOY_SECRET}
docker_hosts unix:///var/run/docker.sock tcp://docker-b.internal:2375
}
}
```
### Who triggers a deploy, and how
Typically a CI/CD job (GitHub Actions, GitLab CI, etc.) or an operator calls the webhook after publishing a new image. Any HTTP method is accepted; `GET` or `POST` are common:
```
curl -si \
"https://deploy.example.com/webhooks/rolling-deployment/${ROLLING_DEPLOY_SECRET}/api/ghcr.io/acme/api:1.2.3"
```
Path shape:
`/webhooks/rolling-deployment/{secret}/{container}/{image}`
- `{secret}` must match the configured `secret` (constant-time compared).
- `{container}` is the exact Docker **container name** that must already be running (e.g. `api`).
- `{image}` is the new image reference and may contain `/` (e.g. `ghcr.io/acme/api:1.2.3`).
### Exact effect of that request
For the example above, assuming a container named `api` is running on both configured hosts and currently uses `ghcr.io/acme/api:1.2.2`:
- Hosts **without** a running `api` container are skipped.
- On each selected host, in order: pull `ghcr.io/acme/api:1.2.3`, snapshot the running `api` container's create config, rename it aside as `api_rollback_YYYYMMDDHHMMSS`, create and start a new `api` container with the **same** env/labels/mounts/ports/networks/restart policy but the new image, then remove the backup on success.
- Fail-fast: if a later host fails, earlier hosts stay on `1.2.3` (HTTP `207`), and the failed host is rolled back when possible.
- A second overlapping deploy for the same container name returns HTTP `409`.
Successful responses are JSON listing per-host outcomes by `host_index` (index into `docker_hosts`). Docker host URLs and daemon error text are not returned in the body; see Caddy logs for details.
func (Middleware) CaddyModule ¶
func (Middleware) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*Middleware) Cleanup ¶
func (m *Middleware) Cleanup() error
Cleanup implements caddy.CleanerUpper, closing all Docker clients.
func (*Middleware) Provision ¶
func (m *Middleware) Provision(ctx caddy.Context) error
Provision implements caddy.Provisioner.
func (Middleware) ServeHTTP ¶
func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP implements caddyhttp.MiddlewareHandler.
Only /webhooks/rolling-deployment/{secret}/{service_container}/{service_image} is handled here (terminal). All other requests are passed to the next handler.
func (*Middleware) UnmarshalCaddyfile ¶
func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (*Middleware) Validate ¶
func (m *Middleware) Validate() error
Validate implements caddy.Validator.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package deploy performs rolling container deployments across one or more Docker hosts, using docker.Client instances for the underlying operations.
|
Package deploy performs rolling container deployments across one or more Docker hosts, using docker.Client instances for the underlying operations. |
|
Package docker provides Docker Engine operations used by rolling deployments.
|
Package docker provides Docker Engine operations used by rolling deployments. |