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

Add documentation for CGO_ENABLED to fix user issues with scc #208

Closed
MikkelHJuul opened this issue Dec 9, 2020 · 2 comments
Closed

Add documentation for CGO_ENABLED to fix user issues with scc #208

MikkelHJuul opened this issue Dec 9, 2020 · 2 comments

Comments

@MikkelHJuul
Copy link

MikkelHJuul commented Dec 9, 2020

A user of scc in containers will run into issues with running the application in alpine if they do not use compiler flag CGO_ENABLED=0.

So I was trying to run scc in a pipeline, and saw iRyanBell's implementation from your README, but I couldn't find the image; I just built my own (mjuul/scc). (I did find the image later: https://github.com/marketplace/actions/scc-docker-action -- I thought it was on docker hub).

But I ran into several issues, firstly with go get where it seems impossible to install v2.13.0 (see my description here: golang/go#35732) well... so I decided to compile it myself and I wrote the Dockerfile below

FROM golang as scc-get

ENV GOOS=linux \
    GOARCH=amd64 

ARG VERSION
RUN git clone --branch $VERSION --depth 1 https://github.com/boyter/scc
WORKDIR /go/scc
RUN go build -ldflags="-s -w"

FROM alpine
COPY --from=scc-get /go/scc/scc /bin/
ENTRYPOINT ["scc"]

then

$ docker build -t scc-image --build-arg VERSION=v2.13.0 .
$ docker run -v /some/local/path/:/root/something -w /root/something scc-image 

You get an error: standard_init_linux.go:211: exec user process caused "no such file or directory"
So I noted that iRyanBell is running the i386 (32 bit) vers. succesfully (which he didn't have to anyway). And that also works. (setting ENV GOARCH=386).

But that is very unsatisfactory; I certainly expect the program to run with the expected behavior on the same architecture.

Searching around I find: https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
and that fixes the issue.

i.e. this works:

FROM golang as scc-get

ENV GOOS=linux \
    GOARCH=amd64 \
    CGO_ENABLED=0

ARG VERSION
RUN git clone --branch $VERSION --depth 1 https://github.com/boyter/scc
WORKDIR /go/scc
RUN go build -ldflags="-s -w"

FROM alpine
COPY --from=scc-get /go/scc/scc /bin/
ENTRYPOINT ["scc"]

So the documentation should mention compiler flag CGO_ENABLED=0 for better compatibility with less dynamic linking.

@boyter
Copy link
Owner

boyter commented Dec 9, 2020

Alpine images... the bane of my existence when doing anything in Go. The amount of times I have had the same issue... well its not a huge amount but enough that its etched into my brain.

If you want to write the documentation into the README ill merge it in and you get the credit :)

Otherwise ill add this in in a week or two. Cheers.

@boyter boyter added this to In progress in Release 3.0.0 Dec 17, 2020
boyter added a commit that referenced this issue Jan 6, 2021
@boyter
Copy link
Owner

boyter commented Jan 6, 2021

Added to README.

@boyter boyter closed this as completed Jan 6, 2021
@boyter boyter moved this from In progress to Done in Release 3.0.0 Jan 6, 2021
lukas-brenning added a commit to lukas-brenning/scc that referenced this issue Jan 13, 2021
* Update README.md

* SLOCCount came before cloc

* resolve boyter#206

* First cut at boyter#210

* Add "gohtml" and "gotxt" to the list of extensions for Go templates

These are the default extensions that e.g. GoLand uses, and some other
tools as well I believe. It's useful as it disambiguates between
templates for html/template and text/template.

* partial fix for boyter#214

* resolve after feedback

* Mostly ready for boyter#211

* real fix for issue214

* few tests and typo

* Resolvehttps://github.com/boyter/issues/208

* Update to remove wrong Go version mentioned boyter#220

Co-authored-by: Ben Boyter <boyter@users.noreply.github.com>
Co-authored-by: AlDanial <al.danial@gmail.com>
Co-authored-by: Ben Boyter <ben@boyter.org>
Co-authored-by: Martin Tournoij <martin@arp242.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Release 3.0.0
  
Done
Development

No branches or pull requests

2 participants