Skip to content
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

flag: flag.Parse() seemingly doing nothing in Docker container #52212

Closed
5HT2 opened this issue Apr 7, 2022 · 7 comments
Closed

flag: flag.Parse() seemingly doing nothing in Docker container #52212

5HT2 opened this issue Apr 7, 2022 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@5HT2
Copy link

5HT2 commented Apr 7, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/arm64

Does this issue reproduce with the latest release?

Yes. I can only reproduce this issue in the golang:1.18.0 image (not golang:1.18.0-alpine).

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/taro-bot/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build624973754=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Dockerfile: https://github.com/5HT2/taro-bot/blob/8c98aa5584f3e7e4d3fd3267284e12b6caa3090f/Dockerfile
main.go: https://github.com/5HT2/taro-bot/blob/8c98aa5584f3e7e4d3fd3267284e12b6caa3090f/main.go

I'm having an issue where none of my flags are being parsed.

all i know is

  • my os.Args flags DO exist and are being set correctly
  • flag.Parsed is true
  • flag.Parse() is being called
  • printing one of the flags i've called yields the default value for the flag (not the value i've set / the value i can see in os.Args)

I know all this via printing the raw values in order to do some sort of debugging. I have no idea how to get around this or fix it, let alone where the bug stems from.

I do know that this does not happen on the golang:1.18.0-alpine3.15 image. I cannot use this image because Alpine does not have the built-in gcc tools necessary to use go build -buildmode=plugin. This does happen on golang.1.18.0 in my testing, which is Debian.

What did you expect to see?

I expected my flags to be parsed.

What did you see instead?

My flags are not parsed.

@seankhliao
Copy link
Member

so what do we run to reproduce the issue?

@5HT2
Copy link
Author

5HT2 commented Apr 7, 2022

I can put together a small sample project in just a second.

@5HT2
Copy link
Author

5HT2 commented Apr 7, 2022

git clone https://github.com/5HT2C/go-52212
cd go-52212
docker build -t go-52212 .
docker run --name go-52212 --mount type=bind,source="/home/ubuntu/fs",target=/go-52212-files --network host -d --env PLUGIN_DIR="testing" go-52212
docker logs go-52212

Welp, I did put it together, and it doesn't have the same issue. I'm really confused as to what broke here, on taro's end.

@5HT2
Copy link
Author

5HT2 commented Apr 7, 2022

Even stranger, values that aren't even set in my program flags show as non-default values, eg

Step 9/10 : RUN echo "$DEBUG"
---> Running in 23326207052b
false
Removing intermediate container 23326207052b
---> 7273b2a43c4c
Step 10/10 : CMD DEBUG="$DEBUG" TZ="$TZ" PLUGIN_DIR="/taro-bot/bin" /taro-bot/scripts/run.sh

log.Printf("%v\n", *debugLog) gives true, when the flag should default to false according to what I set.

5HT2 added a commit to 5HT2/taro-bot that referenced this issue Apr 7, 2022
@cherrymui
Copy link
Member

What is the output of the unexpected flag values with your example above? Does it need to use plugin to reproduce? Thanks.

@cherrymui cherrymui added this to the Backlog milestone Apr 7, 2022
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 7, 2022
@seankhliao
Copy link
Member

Duplicate of #36263

@seankhliao seankhliao marked this as a duplicate of #36263 Apr 7, 2022
@5HT2
Copy link
Author

5HT2 commented Apr 8, 2022

Oh, thank you, that solved it.

5HT2 added a commit to 5HT2/taro-bot that referenced this issue Apr 8, 2022
@golang golang locked and limited conversation to collaborators Apr 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants