Skip to content

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

@MikkelHJuul

Description

@MikkelHJuul

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions