mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-11-21 20:27:17 +03:00
feat: improve Docker configuration and detection handling (#242)
- Pass `cfg` to `envcheck.CheckIfDockerRunning` function - Add `Docker` struct to `config.go` for Docker configuration - Update `config.example.yaml` with `docker` configuration options - Modify `CheckIfDockerRunning` in `docker.go` to use Docker host from config if provided Signed-off-by: appleboy <appleboy.tw@gmail.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/242 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: wxiaoguang <wxiaoguang@noreply.gitea.com> Co-authored-by: appleboy <appleboy.tw@gmail.com> Co-committed-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
parent
ec38401097
commit
9e4a5f7363
4 changed files with 25 additions and 4 deletions
|
@ -63,7 +63,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ls.RequireDocker() {
|
if ls.RequireDocker() {
|
||||||
if err := envcheck.CheckIfDockerRunning(ctx); err != nil {
|
if err := envcheck.CheckIfDockerRunning(ctx, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,3 +68,9 @@ container:
|
||||||
# valid_volumes:
|
# valid_volumes:
|
||||||
# - '**'
|
# - '**'
|
||||||
valid_volumes: []
|
valid_volumes: []
|
||||||
|
|
||||||
|
docker:
|
||||||
|
# overrides the docker client host with the specified one.
|
||||||
|
# default value is the value of DOCKER_HOST environment variable.
|
||||||
|
# if DOCKER_HOST is not set, the default value is unix:///var/run/docker.sock
|
||||||
|
host: ""
|
||||||
|
|
|
@ -50,12 +50,18 @@ type Container struct {
|
||||||
ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers.
|
ValidVolumes []string `yaml:"valid_volumes"` // ValidVolumes specifies the volumes (including bind mounts) can be mounted to containers.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Docker represents the configuration for Docker.
|
||||||
|
type Docker struct {
|
||||||
|
Host string `yaml:"host"` // Host specifies the Docker host.
|
||||||
|
}
|
||||||
|
|
||||||
// Config represents the overall configuration.
|
// Config represents the overall configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Log Log `yaml:"log"` // Log represents the configuration for logging.
|
Log Log `yaml:"log"` // Log represents the configuration for logging.
|
||||||
Runner Runner `yaml:"runner"` // Runner represents the configuration for the runner.
|
Runner Runner `yaml:"runner"` // Runner represents the configuration for the runner.
|
||||||
Cache Cache `yaml:"cache"` // Cache represents the configuration for caching.
|
Cache Cache `yaml:"cache"` // Cache represents the configuration for caching.
|
||||||
Container Container `yaml:"container"` // Container represents the configuration for the container.
|
Container Container `yaml:"container"` // Container represents the configuration for the container.
|
||||||
|
Docker Docker `yaml:"docker"` // Docker represents the configuration for Docker.
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadDefault returns the default configuration.
|
// LoadDefault returns the default configuration.
|
||||||
|
|
|
@ -7,12 +7,21 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"gitea.com/gitea/act_runner/internal/pkg/config"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckIfDockerRunning(ctx context.Context) error {
|
func CheckIfDockerRunning(ctx context.Context, cfg *config.Config) error {
|
||||||
// TODO: if runner support configures to use docker, we need config.Config to pass in
|
opts := []client.Opt{
|
||||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
client.FromEnv,
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Docker.Host != "" {
|
||||||
|
opts = append(opts, client.WithHost(cfg.Docker.Host))
|
||||||
|
}
|
||||||
|
|
||||||
|
cli, err := client.NewClientWithOpts(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue