Skip to content

Fix ONCE environment variable ignorance #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ RUN \
curl -SLf https://github.com/docker/compose/releases/download/v${COMPOSE_VERSION}/docker-compose-linux-${DOWNLOAD_ARCH} -o /usr/local/lib/docker/cli-plugins/docker-compose && \
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
COPY --from=builder /go/src/app/main /usr/local/bin/docker-compose-watcher
CMD ["docker-compose-watcher", "-once=0", "-printSettings"]
CMD ["docker-compose-watcher", "-printSettings"]
24 changes: 16 additions & 8 deletions src/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"os"
"strconv"
"strings"
)

// Settings holds the program runtime configuration
Expand Down Expand Up @@ -34,7 +33,7 @@ func ReadSettings() {
s.boolFlagEnv(&s.Dry, "dry", "DRY", false, "dry run: check and pull, but don't restart")
s.boolFlagEnv(&s.Help, "help", "HELP", false, "print usage instructions")
s.int64FlagEnv(&s.Interval, "interval", "INTERVAL", 60, "interval in minutes between runs")
s.boolFlagEnv(&s.Once, "once", "ONCE", true, "run once and exit, do not run in background")
s.boolFlagEnv(&s.Once, "once", "ONCE", false, "run once and exit, do not run in background")
s.boolFlagEnv(&s.PrintSettings, "printSettings", "PRINT_SETTINGS", false, "print used settings")
s.stringFlagEnv(&s.UpdateLog, "updateLog", "UPDATE_LOG", "", "update log file")
//s.boolFlagEnv(&s.CompleteStop, "completeStop", "COMPLETE_STOP", false, "Restart all services in docker-compose.yml (even unmanaged) after a new image is pulled")
Expand All @@ -51,23 +50,32 @@ func ReadSettings() {
func (settings *Settings) boolFlagEnv(p *bool, name string, env string, value bool, usage string) {
flag.BoolVar(p, name, value, usage+" (env "+env+")")
val := os.Getenv(env)
if (val != "") && (val != "0") && (strings.ToLower(val) != "false") {
*p = true
if val != "" {
b, err := strconv.ParseBool(val)
if err != nil {
log.Fatal(err)
}
*p = b
}
}

func (settings *Settings) int64FlagEnv(p *int64, name string, env string, value int64, usage string) {
flag.Int64Var(p, name, value, usage+" (env "+env+")")
if os.Getenv(env) != "" {
i, _ := strconv.ParseInt(os.Getenv(env), 10, 0)
val := os.Getenv(env)
if val != "" {
i, err := strconv.ParseInt(val, 10, 0)
if err != nil {
log.Fatal(err)
}
*p = i
}
}

func (settings *Settings) stringFlagEnv(p *string, name string, env string, value string, usage string) {
flag.StringVar(p, name, value, usage+" (env "+env+")")
if os.Getenv(env) != "" {
*p = os.Getenv(env)
val := os.Getenv(env)
if val != "" {
*p = val
}
}

Expand Down