current state: Not Working... at all
I was tweaking the entrypoint and now its like it just randomly drops env-vars or fails to read them *no reason* despite them being confirmed to exist via other methods (manual running of commands within container, sanity checking in the entrypoint)
This commit is contained in:
parent
c7098ae0f6
commit
048450dee9
4 changed files with 101 additions and 62 deletions
|
@ -30,21 +30,42 @@ if [ "$#" -gt 0 ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Set default values (if needed)
|
||||||
|
DEFAULT_DOCKER_HOST="tcp://docker:2376"
|
||||||
|
DEFAULT_DOCKER_TLS_VERIFY="1"
|
||||||
|
DEFAULT_DOCKER_CERT_PATH="/certs/client"
|
||||||
|
|
||||||
|
# Ensure the variables are not empty by using explicit checks
|
||||||
|
DOCKER_HOST="${RUNNER__DOCKER_HOST:-${DOCKER_HOST:-${DEFAULT_DOCKER_HOST}}}"
|
||||||
|
DOCKER_TLS_VERIFY="${RUNNER__DOCKER_TLS_VERIFY:-${DOCKER_TLS_VERIFY:-${DEFAULT_DOCKER_TLS_VERIFY}}}"
|
||||||
|
DOCKER_CERT_PATH="${DOCKER_CERT_PATH:-${DEFAULT_DOCKER_CERT_PATH}}"
|
||||||
|
|
||||||
|
RUNNER__container__DOCKER_HOST="${RUNNER__DOCKER_HOST:-${DOCKER_HOST:-${DEFAULT_DOCKER_HOST}}}"
|
||||||
|
RUNNER__runner__INSECURE="${RUNNER__DOCKER_TLS_VERIFY:-${DOCKER_TLS_VERIFY:-${DEFAULT_DOCKER_TLS_VERIFY}}}"
|
||||||
|
|
||||||
|
RUNNER__container__NETWORK="${RUNNER__container__NETWORK:-host}"
|
||||||
|
RUNNER__container__OPTIONS="${RUNNER__container__OPTIONS:-} -v ${DOCKER_CERT_PATH}:${DOCKER_CERT_PATH}:ro"
|
||||||
|
RUNNER__container__VALID_VOLUMES="${RUNNER__container__VALID_VOLUMES:-} ${DOCKER_CERT_PATH}"
|
||||||
|
RUNNER__container__PRIVILEGED="${RUNNER__container__PRIVILEGED:-true}"
|
||||||
|
|
||||||
|
RUNNER__runner__FILE="${RUNNER__runner__FILE:-/data/runner.json}"
|
||||||
|
|
||||||
|
decho "DOCKER_HOST: ${DOCKER_HOST}"
|
||||||
|
decho "DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY}"
|
||||||
|
decho "DOCKER_CERT_PATH: ${DOCKER_CERT_PATH}"
|
||||||
|
decho "RUNNER__container__DOCKER_HOST: ${RUNNER__container__DOCKER_HOST}"
|
||||||
|
decho "RUNNER__runner__INSECURE: ${RUNNER__runner__INSECURE}"
|
||||||
|
decho "RUNNER__container__NETWORK: ${RUNNER__container__NETWORK}"
|
||||||
|
decho "RUNNER__container__OPTIONS: ${RUNNER__container__OPTIONS}"
|
||||||
|
decho "RUNNER__container__VALID_VOLUMES: ${RUNNER__container__VALID_VOLUMES}"
|
||||||
|
decho "RUNNER__container__PRIVILEGED: ${RUNNER__container__PRIVILEGED}"
|
||||||
|
decho "RUNNER__runner__FILE: ${RUNNER__runner__FILE}"
|
||||||
|
|
||||||
# Use environment variables directly, with fallback defaults if not set
|
# Use environment variables directly, with fallback defaults if not set
|
||||||
RUNNER__CONFIG_FILE="${RUNNER__CONFIG_FILE:-/data/config.yml}"
|
RUNNER__CONFIG_FILE="${RUNNER__CONFIG_FILE:-/data/config.yml}"
|
||||||
ENV_FILE="${ENV_FILE:-/data/.env}"
|
ENV_FILE="${ENV_FILE:-/data/.env}"
|
||||||
RUNNER__RUNNER__FILE="${RUNNER__RUNNER__FILE:-/data/runner.json}"
|
|
||||||
|
|
||||||
# Set config arguments
|
# Set config arguments
|
||||||
CONFIG_ARG="--config ${RUNNER__CONFIG_FILE}"
|
CONFIG_ARG="--config ${RUNNER__CONFIG_FILE}"
|
||||||
|
|
||||||
# Container-specific environment variables
|
|
||||||
RUNNER__CONTAINER__NETWORK="${RUNNER__CONTAINER__NETWORK:-host}"
|
|
||||||
RUNNER__CONTAINER__ENABLE_IPV6="${RUNNER__CONTAINER__ENABLE_IPV6:-false}"
|
|
||||||
RUNNER__CONTAINER__PRIVILEGED="${RUNNER__CONTAINER__PRIVILEGED:-false}"
|
|
||||||
RUNNER__CONTAINER__LABELS="${RUNNER__CONTAINER__LABELS:-}"
|
|
||||||
RUNNER__CONTAINER__VALID_VOLUMES="${RUNNER__CONTAINER__VALID_VOLUMES:-}"
|
|
||||||
|
|
||||||
# Show config variables
|
# Show config variables
|
||||||
decho "CONFIG: ${CONFIG_ARG}"
|
decho "CONFIG: ${CONFIG_ARG}"
|
||||||
|
|
||||||
|
@ -60,8 +81,8 @@ decho "Using environment file: ${ENV_FILE}"
|
||||||
|
|
||||||
# Set extra arguments from environment variables
|
# Set extra arguments from environment variables
|
||||||
EXTRA_ARGS=""
|
EXTRA_ARGS=""
|
||||||
if [[ -n "${RUNNER__CONTAINER__LABELS}" ]]; then
|
if [[ -n "${RUNNER__container__LABELS}" ]]; then
|
||||||
EXTRA_ARGS="${EXTRA_ARGS} --labels ${RUNNER__CONTAINER__LABELS}"
|
EXTRA_ARGS="${EXTRA_ARGS} --labels ${RUNNER__container__LABELS}"
|
||||||
fi
|
fi
|
||||||
decho "EXTRA_ARGS: ${EXTRA_ARGS}"
|
decho "EXTRA_ARGS: ${EXTRA_ARGS}"
|
||||||
|
|
||||||
|
@ -71,8 +92,8 @@ if [[ "${SKIP_WAIT}" != "true" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to register the runner
|
# Try to register the runner
|
||||||
if [[ ! -s "${RUNNER__RUNNER__FILE}" ]]; then
|
if [[ ! -s "${RUNNER__runner__FILE}" ]]; then
|
||||||
touch ${RUNNER__RUNNER__FILE}
|
touch ${RUNNER__runner__FILE}
|
||||||
try=$((try + 1))
|
try=$((try + 1))
|
||||||
success=0
|
success=0
|
||||||
decho "try: ${try}, success: ${success}"
|
decho "try: ${try}, success: ${success}"
|
||||||
|
|
|
@ -78,20 +78,15 @@ services:
|
||||||
FORGEJO_SECRET: "02f8e8ed1bd08d55338026d04b5513684ff23c1f" # shared secret, must match Forgejo's, overrides RUNNER_TOKEN
|
FORGEJO_SECRET: "02f8e8ed1bd08d55338026d04b5513684ff23c1f" # shared secret, must match Forgejo's, overrides RUNNER_TOKEN
|
||||||
RUNNER_TOKEN: ${RUNNER_TOKEN} # token obtained from Forgejo web interface
|
RUNNER_TOKEN: ${RUNNER_TOKEN} # token obtained from Forgejo web interface
|
||||||
|
|
||||||
RUNNER__CONFIG_FILE: config.yml # defaults to /data/config.yml
|
DOCKER_HOST: tcp://docker:2376
|
||||||
RUNNER__NAME: forgejo-runner # defaults to forgejo-runner
|
DOCKER_TLS_VERIFY: 1
|
||||||
RUNNER__RUNNER__FILE: .runner # defaults to /data/runner.json
|
DOCKER_CERT_PATH: /certs/client
|
||||||
|
|
||||||
RUNNER__CONTAINER__PRIVILEGED: "true" # defaults to false for security reasons
|
RUNNER__log__LEVEL: "debug"
|
||||||
RUNNER__CONTAINER_OPTIONS: -v /certs/client:/certs/client:ro # needed for TLS
|
RUNNER__container__PRIVILEGED: "true"
|
||||||
RUNNER__CONTAINER__DOCKER_HOST: "tcp://docker:2376" # defaults to "-", an available docker host will automatically be found
|
RUNNER__runner__LABELS: |
|
||||||
RUNNER__RUNNER__INSECURE: false
|
docker:docker://code.forgejo.org/oci/node:20-bookworm
|
||||||
RUNNER__RUNNER__ENVS: |
|
|
||||||
DOCKER_HOST=tcp://docker:2376
|
DEBUG: "true"
|
||||||
DOCKER_TLS_VERIFY=1
|
SKIP_WAIT: "false"
|
||||||
DOCKER_CERT_PATH=/certs/client # defaults to empty
|
SLEEP_DEBUG: "false" # toggles wether to sleep indefinitely after starting the runner
|
||||||
RUNNER__RUNNER__LABELS: |
|
|
||||||
"docker:docker://code.forgejo.org/oci/node:20-bookworm"
|
|
||||||
|
|
||||||
DEBUG: "true" # defaults to false, set to true to enable debug logging in the entrypoint
|
|
||||||
SKIP_WAIT: "false" # defaults to false, set to true to skip the 10 second wait to allow for forgejo and docker-in-docker to start
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// loadEnvVars loads configuration settings from environment variables
|
// loadEnvVars loads configuration settings from environment variables
|
||||||
|
@ -14,53 +16,59 @@ func loadEnvVars(config *Config) {
|
||||||
// This implementation causes env-vars to override config file settings,
|
// This implementation causes env-vars to override config file settings,
|
||||||
// without writing to the config file.
|
// without writing to the config file.
|
||||||
|
|
||||||
// SkipEnv if variable is set
|
if debug, ok := os.LookupEnv("DEBUG"); ok && debug == "true" {
|
||||||
if _, ok := os.LookupEnv("RUNNER__SKIP_ENV"); ok {
|
log.SetLevel(log.DebugLevel)
|
||||||
return
|
log.Debug("Debug logging enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
loadEnvStr(config, "RUNNER__LOG__LEVEL", &config.Log.Level)
|
loadEnvStr(config, "RUNNER__log__LEVEL", &config.Log.Level)
|
||||||
loadEnvStr(config, "RUNNER__LOG__JOB_LEVEL", &config.Log.JobLevel)
|
loadEnvStr(config, "RUNNER__log__JOB_LEVEL", &config.Log.JobLevel)
|
||||||
|
|
||||||
// Runner
|
// Runner
|
||||||
loadEnvStr(config, "RUNNER__RUNNER__FILE", &config.Runner.File)
|
loadEnvStr(config, "RUNNER__runner__FILE", &config.Runner.File)
|
||||||
loadEnvInt(config, "RUNNER__RUNNER__CAPACITY", &config.Runner.Capacity)
|
loadEnvInt(config, "RUNNER__runner__CAPACITY", &config.Runner.Capacity)
|
||||||
loadEnvTable(config, "RUNNER__RUNNER__ENVS", &config.Runner.Envs)
|
loadEnvTable(config, "RUNNER__runner__ENVS", &config.Runner.Envs)
|
||||||
loadEnvStr(config, "RUNNER__RUNNER__ENV_FILE", &config.Runner.EnvFile)
|
loadEnvStr(config, "RUNNER__runner__ENV_FILE", &config.Runner.EnvFile)
|
||||||
loadEnvDuration(config, "RUNNER__RUNNER__SHUTDOWN_TIMEOUT", &config.Runner.ShutdownTimeout)
|
loadEnvDuration(config, "RUNNER__runner__SHUTDOWN_TIMEOUT", &config.Runner.ShutdownTimeout)
|
||||||
loadEnvBool(config, "RUNNER__RUNNER__INSECURE", &config.Runner.Insecure)
|
loadEnvBool(config, "RUNNER__runner__INSECURE", &config.Runner.Insecure)
|
||||||
loadEnvDuration(config, "RUNNER__RUNNER__FETCH_TIMEOUT", &config.Runner.FetchTimeout)
|
loadEnvDuration(config, "RUNNER__runner__FETCH_TIMEOUT", &config.Runner.FetchTimeout)
|
||||||
loadEnvDuration(config, "RUNNER__RUNNER__FETCH_INTERVAL", &config.Runner.FetchInterval)
|
loadEnvDuration(config, "RUNNER__runner__FETCH_INTERVAL", &config.Runner.FetchInterval)
|
||||||
loadEnvDuration(config, "RUNNER__RUNNER__REPORT_INTERVAL", &config.Runner.ReportInterval)
|
loadEnvDuration(config, "RUNNER__runner__REPORT_INTERVAL", &config.Runner.ReportInterval)
|
||||||
loadEnvList(config, "RUNNER__RUNNER__LABELS", &config.Runner.Labels)
|
loadEnvList(config, "RUNNER__runner__LABELS", &config.Runner.Labels)
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
loadEnvBool(config, "RUNNER__CACHE__ENABLED", config.Cache.Enabled)
|
loadEnvBool(config, "RUNNER__cache__ENABLED", config.Cache.Enabled)
|
||||||
loadEnvStr(config, "RUNNER__CACHE__DIR", &config.Cache.Dir)
|
loadEnvStr(config, "RUNNER__cache__DIR", &config.Cache.Dir)
|
||||||
loadEnvStr(config, "RUNNER__CACHE__HOST", &config.Cache.Host)
|
loadEnvStr(config, "RUNNER__cache__HOST", &config.Cache.Host)
|
||||||
loadEnvUInt16(config, "RUNNER__CACHE__PORT", &config.Cache.Port)
|
loadEnvUInt16(config, "RUNNER__cache__PORT", &config.Cache.Port)
|
||||||
loadEnvStr(config, "RUNNER__CACHE__EXTERNAL_SERVER", &config.Cache.ExternalServer)
|
loadEnvStr(config, "RUNNER__cache__EXTERNAL_SERVER", &config.Cache.ExternalServer)
|
||||||
|
|
||||||
// Container
|
// Container
|
||||||
loadEnvStr(config, "RUNNER__CONTAINER__NETWORK", &config.Container.Network)
|
loadEnvStr(config, "RUNNER__container__NETWORK", &config.Container.Network)
|
||||||
loadEnvStr(config, "RUNNER__CONTAINER__NETWORK_MODE", &config.Container.NetworkMode)
|
loadEnvStr(config, "RUNNER__container__NETWORK_MODE", &config.Container.NetworkMode)
|
||||||
loadEnvBool(config, "RUNNER__CONTAINER__ENABLE_IPV6", &config.Container.EnableIPv6)
|
loadEnvBool(config, "RUNNER__container__ENABLE_IPV6", &config.Container.EnableIPv6)
|
||||||
loadEnvBool(config, "RUNNER__CONTAINER__PRIVILEGED", &config.Container.Privileged)
|
loadEnvBool(config, "RUNNER__container__PRIVILEGED", &config.Container.Privileged)
|
||||||
loadEnvStr(config, "RUNNER__CONTAINER__OPTIONS", &config.Container.Options)
|
loadEnvStr(config, "RUNNER__container__OPTIONS", &config.Container.Options)
|
||||||
loadEnvStr(config, "RUNNER__CONTAINER__WORKDIR_PARENT", &config.Container.WorkdirParent)
|
loadEnvStr(config, "RUNNER__container__WORKDIR_PARENT", &config.Container.WorkdirParent)
|
||||||
loadEnvList(config, "RUNNER__CONTAINER__VALID_VOLUMES", &config.Container.ValidVolumes)
|
loadEnvList(config, "RUNNER__container__VALID_VOLUMES", &config.Container.ValidVolumes)
|
||||||
loadEnvStr(config, "RUNNER__CONTAINER__DOCKER_HOST", &config.Container.DockerHost)
|
loadEnvStr(config, "RUNNER__container__DOCKER_HOST", &config.Container.DockerHost)
|
||||||
loadEnvBool(config, "RUNNER__CONTAINER__FORCE_PULL", &config.Container.ForcePull)
|
loadEnvBool(config, "RUNNER__container__FORCE_PULL", &config.Container.ForcePull)
|
||||||
|
|
||||||
// Host
|
// Host
|
||||||
loadEnvStr(config, "RUNNER__HOST__WORKDIR_PARENT", &config.Host.WorkdirParent)
|
loadEnvStr(config, "RUNNER__host__WORKDIR_PARENT", &config.Host.WorkdirParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadEnvStr loads an environment variable into the provided string pointer if it exists.
|
// General Coverage Docs for below:
|
||||||
|
// loadEnvType, where Type is the type of the variable being loaded, loads an environment variable into the provided pointer if the environment variable exists and is not empty.
|
||||||
|
// The key parameter is the environment variable key to look for.
|
||||||
|
// The dest parameter is a pointer to the variable to load the environment variable into.
|
||||||
|
// Config is present but unused, it remains for future use to prevent the need to redo the above functions.
|
||||||
|
|
||||||
func loadEnvStr(config *Config, key string, dest *string) {
|
func loadEnvStr(config *Config, key string, dest *string) {
|
||||||
// Example: RUNNER__LOG__LEVEL = "info"
|
// Example: RUNNER__LOG__LEVEL = "info"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = v
|
*dest = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +78,7 @@ func loadEnvInt(config *Config, key string, dest *int) {
|
||||||
// Example: RUNNER__RUNNER__CAPACITY = "1"
|
// Example: RUNNER__RUNNER__CAPACITY = "1"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
if intValue, err := strconv.Atoi(v); err == nil {
|
if intValue, err := strconv.Atoi(v); err == nil {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = intValue
|
*dest = intValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +89,7 @@ func loadEnvUInt16(config *Config, key string, dest *uint16) {
|
||||||
// Example: RUNNER__CACHE__PORT = "8080"
|
// Example: RUNNER__CACHE__PORT = "8080"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
if uint16Value, err := strconv.ParseUint(v, 10, 16); err == nil {
|
if uint16Value, err := strconv.ParseUint(v, 10, 16); err == nil {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = uint16(uint16Value)
|
*dest = uint16(uint16Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +100,7 @@ func loadEnvDuration(config *Config, key string, dest *time.Duration) {
|
||||||
// Example: RUNNER__RUNNER__SHUTDOWN_TIMEOUT = "3h"
|
// Example: RUNNER__RUNNER__SHUTDOWN_TIMEOUT = "3h"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
if durationValue, err := time.ParseDuration(v); err == nil {
|
if durationValue, err := time.ParseDuration(v); err == nil {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = durationValue
|
*dest = durationValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +111,7 @@ func loadEnvBool(config *Config, key string, dest *bool) {
|
||||||
// Example: RUNNER__RUNNER__INSECURE = "false"
|
// Example: RUNNER__RUNNER__INSECURE = "false"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
if boolValue, err := strconv.ParseBool(v); err == nil {
|
if boolValue, err := strconv.ParseBool(v); err == nil {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = boolValue
|
*dest = boolValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,6 +135,7 @@ func loadEnvTable(config *Config, key string, dest *map[string]string) {
|
||||||
func loadEnvList(config *Config, key string, dest *[]string) {
|
func loadEnvList(config *Config, key string, dest *[]string) {
|
||||||
// Example: RUNNER__RUNNER__LABELS = "label1, label2, label3"
|
// Example: RUNNER__RUNNER__LABELS = "label1, label2, label3"
|
||||||
if v := os.Getenv(key); v != "" {
|
if v := os.Getenv(key); v != "" {
|
||||||
|
log.Debug("Loading env var: ", key, "=", v)
|
||||||
*dest = splitAndTrim(v)
|
*dest = splitAndTrim(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,5 +173,15 @@ func LoadDefault(file string) (*Config, error) {
|
||||||
// Load environment variables at the end to allow for overriding the default values.
|
// Load environment variables at the end to allow for overriding the default values.
|
||||||
loadEnvVars(cfg)
|
loadEnvVars(cfg)
|
||||||
|
|
||||||
|
// Write the state of the config, including default values, to a debug file.
|
||||||
|
debugFile := file + ".debug.yml"
|
||||||
|
content, err := yaml.Marshal(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("marshal config to debug file %q: %w", debugFile, err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(debugFile, content, 0644); err != nil {
|
||||||
|
return nil, fmt.Errorf("write debug config file %q: %w", debugFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue