Compare commits

...
3 Commits
10 changed files with 225 additions and 30 deletions
+3 -2
View File
@@ -81,10 +81,11 @@ func (p *Proxy) handleConnection(ctx context.Context, localConn net.Conn) {
defer p.activeConns.Done() defer p.activeConns.Done()
defer localConn.Close() defer localConn.Close()
ctx, cancel := context.WithTimeout(ctx, 10*time.Second) // Use a separate context with timeout for dialing the remote address.
dialCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel() defer cancel()
remoteConn, err := p.DialContext(ctx, "tcp", p.RemoteAddr) remoteConn, err := p.DialContext(dialCtx, "tcp", p.RemoteAddr)
if err != nil { if err != nil {
if p.OnError != nil { if p.OnError != nil {
p.OnError(fmt.Errorf("connect remote address '%s': %w", p.RemoteAddr, err)) p.OnError(fmt.Errorf("connect remote address '%s': %w", p.RemoteAddr, err))
@@ -9,8 +9,8 @@ with [Let's Encrypt](https://letsencrypt.org/), and route requests to your servi
## How it works ## How it works
Caddy runs as a global service `caddy` on every machine in your cluster, listening on the host ports 80 (HTTP) and 443 By default, Caddy runs as a global service `caddy` on every machine in your cluster, listening on the host ports 80
(HTTPS). (HTTP) and 443 (HTTPS).
It's deployed during cluster initialisation (`uc machine init`) unless you use the `--no-caddy` flag. It's deployed during cluster initialisation (`uc machine init`) unless you use the `--no-caddy` flag.
See [Managing Caddy](3-managing-caddy.md) for deployment and customisation instructions. See [Managing Caddy](3-managing-caddy.md) for deployment and customisation instructions.
@@ -1,7 +1,7 @@
# Managing Caddy # Managing Caddy
Caddy is automatically deployed as a global service `caddy` when you initialise a cluster with `uc machine init`. It Caddy is automatically deployed as a global service `caddy` when you initialise a cluster with `uc machine init`. By
runs on every machine to handle incoming HTTP/HTTPS traffic and route it to your services. default, it runs on every machine to handle incoming HTTP/HTTPS traffic and route it to your services.
## Checking status ## Checking status
@@ -37,6 +37,13 @@ Deploy a specific version or custom image:
uc caddy deploy --image caddybuilds/caddy-cloudflare:2.10.2 uc caddy deploy --image caddybuilds/caddy-cloudflare:2.10.2
``` ```
Deploy only to a specific machine or a subset of machines (comma-separated list):
```shell
uc caddy deploy --machine machine1
uc caddy deploy --machine machine2,machine3,machine4
```
Deploy with custom global configuration: Deploy with custom global configuration:
```shell ```shell
@@ -90,6 +97,10 @@ services:
x-caddy: Caddyfile x-caddy: Caddyfile
deploy: deploy:
mode: global mode: global
# Optional: deploy only to specific machines.
# x-machines:
# - machine1
# - machine2
``` ```
</TabItem> </TabItem>
@@ -98,26 +109,26 @@ services:
```caddyfile ```caddyfile
# Global options. # Global options.
{ {
debug debug
} }
# A snippet that can be reused in custom Caddy configs for services (x-caddy). # A snippet that can be reused in custom Caddy configs for services (x-caddy).
(my_snippet) { (my_snippet) {
... ...
} }
# Obtain a wildcard TLS certificate for all subdomains of example.name using DNS challenge with Cloudflare. # Obtain a wildcard TLS certificate for all subdomains of example.name using DNS challenge with Cloudflare.
# It will be used for services that publish ports with hostnames under example.name. # It will be used for services that publish ports with hostnames under example.name.
*.example.com { *.example.com {
tls { tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN} dns cloudflare {env.CLOUDFLARE_API_TOKEN}
} }
respond "No host matched" 404 respond "No host matched" 404
} }
# Expose an internal service that is not managed by Uncloud. # Expose an internal service that is not managed by Uncloud.
internal.example.com { internal.example.com {
reverse_proxy 192.168.1.100 reverse_proxy 192.168.1.100
} }
``` ```
@@ -139,8 +150,8 @@ uc deploy
## Verifying config ## Verifying config
View the complete generated Caddyfile served by the `caddy` service. This is useful for debugging and verifying View the complete generated Caddyfile served by the `caddy` service. This is useful for debugging and verifying custom
custom global and service-specific Caddy configs. global and service-specific Caddy configs.
```shell ```shell
uc caddy config uc caddy config
@@ -155,26 +166,26 @@ Example output:
# User-defined global config from service 'caddy'. # User-defined global config from service 'caddy'.
# Global options. # Global options.
{ {
debug debug
} }
# A snippet that can be reused in custom Caddy configs for services (x-caddy). # A snippet that can be reused in custom Caddy configs for services (x-caddy).
(my_snippet) { (my_snippet) {
... ...
} }
# Obtain a wildcard TLS certificate for all subdomains of example.name using DNS challenge with Cloudflare. # Obtain a wildcard TLS certificate for all subdomains of example.name using DNS challenge with Cloudflare.
# It will be used for services that publish ports with hostnames under example.name. # It will be used for services that publish ports with hostnames under example.name.
*.example.com { *.example.com {
tls { tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN} dns cloudflare {env.CLOUDFLARE_API_TOKEN}
} }
respond "No host matched" 404 respond "No host matched" 404
} }
# Expose an internal service that is not managed by Uncloud. # Expose an internal service that is not managed by Uncloud.
internal.example.com { internal.example.com {
reverse_proxy 192.168.1.100 reverse_proxy 192.168.1.100
} }
# Health check endpoint to verify Caddy reachability on this machine. # Health check endpoint to verify Caddy reachability on this machine.
@@ -210,14 +221,14 @@ https://api.example.com {
# User-defined config for service 'web'. # User-defined config for service 'web'.
www.example.com { www.example.com {
redir https://example.com{uri} permanent redir https://example.com{uri} permanent
} }
example.com { example.com {
reverse_proxy 10.210.0.3:8000 { reverse_proxy 10.210.0.3:8000 {
import common_proxy import common_proxy
} }
log log
} }
# Skipped invalid user-defined configs: # Skipped invalid user-defined configs:
+2
View File
@@ -18,6 +18,8 @@ A CLI tool for managing Uncloud resources such as machines, services, and volume
* [uc ctx](uc_ctx.md) - Switch between different cluster contexts. Contains subcommands to manage contexts. * [uc ctx](uc_ctx.md) - Switch between different cluster contexts. Contains subcommands to manage contexts.
* [uc deploy](uc_deploy.md) - Deploy services from a Compose file. * [uc deploy](uc_deploy.md) - Deploy services from a Compose file.
* [uc dns](uc_dns.md) - Manage cluster domain in Uncloud DNS. * [uc dns](uc_dns.md) - Manage cluster domain in Uncloud DNS.
* [uc image](uc_image.md) - Manage images on machines in the cluster.
* [uc images](uc_images.md) - List images on machines in the cluster.
* [uc inspect](uc_inspect.md) - Display detailed information on a service. * [uc inspect](uc_inspect.md) - Display detailed information on a service.
* [uc ls](uc_ls.md) - List services. * [uc ls](uc_ls.md) - List services.
* [uc machine](uc_machine.md) - Manage machines in an Uncloud cluster. * [uc machine](uc_machine.md) - Manage machines in an Uncloud cluster.
+2 -2
View File
@@ -15,8 +15,8 @@ uc deploy [FLAGS] [SERVICE...] [flags]
-n, --no-build Do not build images before deploying services. (default false) -n, --no-build Do not build images before deploying services. (default false)
-p, --profile strings One or more Compose profiles to enable. -p, --profile strings One or more Compose profiles to enable.
--recreate Recreate containers even if their configuration and image haven't changed. --recreate Recreate containers even if their configuration and image haven't changed.
-y, --yes Auto-confirm deployment plan. Enabled by default when running non-interactively, -y, --yes Auto-confirm deployment plan. Should be explicitly set when running non-interactively,
e.g., in CI/CD pipelines. e.g., in CI/CD pipelines. [$UNCLOUD_AUTO_CONFIRM]
``` ```
## Options inherited from parent commands ## Options inherited from parent commands
+24
View File
@@ -0,0 +1,24 @@
# uc image
Manage images on machines in the cluster.
## Options
```
-h, --help help for image
```
## Options inherited from parent commands
```
--connect string Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]
Format: [ssh://]user@host[:port] or tcp://host:port
--uncloud-config string Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default "~/.config/uncloud/config.yaml")
```
## See also
* [uc](uc.md) - A CLI tool for managing Uncloud resources such as machines, services, and volumes.
* [uc image ls](uc_image_ls.md) - List images on machines in the cluster.
* [uc image push](uc_image_push.md) - Upload a local Docker image to the cluster.
@@ -0,0 +1,51 @@
# uc image ls
List images on machines in the cluster.
## Synopsis
List images on machines in the cluster. By default, on all machines. Optionally filter by image name.
```
uc image ls [REPO:[TAG]] [flags]
```
## Examples
```
# List all images on all machines.
uc image ls
# List images on specific machine.
uc image ls -m machine1
# List images on multiple machines.
uc image ls -m machine1,machine2
# List images filtered by name (with any tag) on all machines.
uc image ls myapp
# List images filtered by name pattern on specific machine.
uc image ls "myapp:1.*" -m machine1
```
## Options
```
-c, --context string Name of the cluster context. (default is the current context)
-h, --help help for ls
-m, --machine strings Filter images by machine name or ID. Can be specified multiple times or as a comma-separated list. (default is include all machines)
```
## Options inherited from parent commands
```
--connect string Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]
Format: [ssh://]user@host[:port] or tcp://host:port
--uncloud-config string Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default "~/.config/uncloud/config.yaml")
```
## See also
* [uc image](uc_image.md) - Manage images on machines in the cluster.
@@ -0,0 +1,55 @@
# uc image push
Upload a local Docker image to the cluster.
## Synopsis
Upload a local Docker image to the cluster transferring only the missing layers.
The image is uploaded to the machine which CLI is connected to (default) or the specified machine(s).
```
uc image push IMAGE [flags]
```
## Examples
```
# Push image to the machine the CLI is connected to.
uc image push myapp:latest
# Push image to specific machine.
uc image push myapp:latest -m machine1
# Push image to multiple machines.
uc image push myapp:latest -m machine1,machine2,machine3
# Push image to all machines in the cluster.
uc image push myapp:latest -m all
# Push a specific platform of a multi-platform image.
uc image push myapp:latest --platform linux/amd64
```
## Options
```
-c, --context string Name of the cluster context. (default is the current context)
-h, --help help for push
-m, --machine strings Machine names to push the image to. Can be specified multiple times or as a comma-separated list of machine names.
Use 'all' to push to all machines. (default is connected machine)
--platform string Push a specific platform of a multi-platform image (e.g., linux/amd64, linux/arm64).
Local Docker must be configured to use containerd image store to support multi-platform images.
```
## Options inherited from parent commands
```
--connect string Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]
Format: [ssh://]user@host[:port] or tcp://host:port
--uncloud-config string Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default "~/.config/uncloud/config.yaml")
```
## See also
* [uc image](uc_image.md) - Manage images on machines in the cluster.
+51
View File
@@ -0,0 +1,51 @@
# uc images
List images on machines in the cluster.
## Synopsis
List images on machines in the cluster. By default, on all machines. Optionally filter by image name.
```
uc images [IMAGE] [flags]
```
## Examples
```
# List all images on all machines.
uc images
# List images on specific machine.
uc images -m machine1
# List images on multiple machines.
uc images -m machine1,machine2
# List images filtered by name (with any tag) on all machines.
uc images myapp
# List images filtered by name pattern on specific machine.
uc images "myapp:1.*" -m machine1
```
## Options
```
-c, --context string Name of the cluster context. (default is the current context)
-h, --help help for images
-m, --machine strings Filter images by machine name or ID. Can be specified multiple times or as a comma-separated list. (default is include all machines)
```
## Options inherited from parent commands
```
--connect string Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]
Format: [ssh://]user@host[:port] or tcp://host:port
--uncloud-config string Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default "~/.config/uncloud/config.yaml")
```
## See also
* [uc](uc.md) - A CLI tool for managing Uncloud resources such as machines, services, and volumes.
@@ -31,7 +31,7 @@ uc machine init [USER@HOST:PORT] [flags]
## Options ## Options
``` ```
-c, --context string Name of the new context to be created for the initialised cluster in the Uncloud config. (default "default") -c, --context string Name of the new context to be created in the Uncloud config to manage the cluster. (default "default")
--dns-endpoint string API endpoint for the Uncloud DNS service. (default "https://dns.uncloud.run/v1") --dns-endpoint string API endpoint for the Uncloud DNS service. (default "https://dns.uncloud.run/v1")
-h, --help help for init -h, --help help for init
-n, --name string Assign a name to the machine. -n, --name string Assign a name to the machine.