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

SKAFFOLD_GO_GCFLAGS should not be quoted #4863

Closed
briandealwis opened this issue Oct 6, 2020 · 0 comments · Fixed by #4864
Closed

SKAFFOLD_GO_GCFLAGS should not be quoted #4863

briandealwis opened this issue Oct 6, 2020 · 0 comments · Fixed by #4864
Assignees
Labels
area/build area/debug kind/bug Something isn't working priority/p0 Highest priority. We are actively looking at delivering it.
Milestone

Comments

@briandealwis
Copy link
Member

Expected behavior

skaffold debug provides SKAFFOLD_GO_GCFLAGS to be used in Dockerfiles to build and link Go apps in a form suitable for debugging (as per diff below). But the resulting binaries are still optimized.

--- examples/getting-started/Dockerfile
+++ examples/getting-started/Dockerfile
@@ -1,6 +1,7 @@
 FROM golang:1.12.9-alpine3.10 as builder
 COPY main.go .
-RUN go build -o /app main.go
+ARG SKAFFOLD_GO_GCFLAGS
+RUN set -x; go build -x -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /app main.go

Actual behavior

Note the crazy quoting going on with SKAFFOLD_GO_GCFLAGS, and -N -l is not applied to the actual compile command.

$ cd examples/getting-started
$ skaffold debug
...
Step 4/8 : RUN set -x; eval go build -x -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /app main.go
 ---> Running in 664f5bbb3f87
+ eval go build -x '-gcflags='"'"'all=-N -l'"'" -o /app main.go
+ go build -x '-gcflags=all=-N -l' -o /app main.go
WORK=/tmp/go-build764272742
mkdir -p $WORK/b003/
cat >$WORK/b003/importcfg << 'EOF' # internal
# import config
EOF
cd /usr/local/go/src/errors
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b003/_pkg_.a -trimpath $WORK/b003 -N -l -p errors -std -complete -buildid KFi9vraCRHkOkiSJsJ9s/KFi9vraCRHkOkiSJsJ9s -goversion go1.12.9 -D "" -importcfg $WORK/b003/importcfg -pack -c=2 ./errors.go

Skaffold is single-quoting the environment value set:
https://github.com/GoogleContainerTools/skaffold/blob/master/pkg/skaffold/docker/build_args.go#L34-L35

The use of the build argument requires being quoted:

$ diff
+ARG SKAFFOLD_GO_GCFLAGS
+RUN go build -gcflags=${SKAFFOLD_GO_GCFLAGS} -o /app main.go

$ skaffold debug
Step 4/8 : RUN go build -gcflags=${SKAFFOLD_GO_GCFLAGS} -o /app main.go
 ---> Running in e6ca8ab10074
flag provided but not defined: -l'
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.

We just need to remove the single-quoting of the build definition.area

Workaround

To make this work, use eval go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" ...

Information

  • Skaffold version: v1.15.0
  • Operating system: macOS
@briandealwis briandealwis added kind/bug Something isn't working area/build priority/p0 Highest priority. We are actively looking at delivering it. area/debug labels Oct 6, 2020
@briandealwis briandealwis self-assigned this Oct 6, 2020
@briandealwis briandealwis added this to the v1.16.0 milestone Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build area/debug kind/bug Something isn't working priority/p0 Highest priority. We are actively looking at delivering it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant