markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.19k stars 60 forks source link

Update examples/**/Dockerfile to not use alpine? #135

Open ryanerwin opened 4 years ago

ryanerwin commented 4 years ago

On Ubuntu 20.10 whenever I try to run any of the examples via make/docker I get an error like:

 ~/SourceInstall/pkger/examples/walk/pkger > master v0.17.1 ? > make
pkger
GOOS=linux go build -v -o example
docker build -t pkger:example .
Sending build context to Docker daemon  5.337MB
Step 1/4 : FROM alpine
 ---> d6e46aa2470d
Step 2/4 : EXPOSE 3000
 ---> Using cache
 ---> 633d71f26bcd
Step 3/4 : COPY example /bin/
 ---> 98a719614111
Step 4/4 : CMD /bin/example
 ---> Running in f85a80824d54
Removing intermediate container f85a80824d54
 ---> 651e8c93624b
Successfully built 651e8c93624b
Successfully tagged pkger:example
docker run -p 3000:3000 pkger:example
/bin/sh: /bin/example: not found
make: *** [Makefile:5: default] Error 127

I believe the root problem is Alpine's switch from glibc to musl libc, as even when I enter the docker images directly, I'm unable to execute the ./example binary that was built from the host (glibc).

All of the examples still work fine if in the Dockerfile I just change FROM alpine to FROM ubuntu.

Of course the ubuntu image has a lot more bloat...

REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
ubuntu                                 latest              d70eaf7277ea        4 weeks ago         72.9MB
alpine                                 latest              d6e46aa2470d        5 weeks ago         5.57MB

There are much smaller community provided ubuntu-minimal images, there are also alpine-glibc images, but these require a docker login which definitely isn't ideal for examples...

After changing the image from Alpine to Ubuntu, make runs fine...

 ~/SourceInstall/pkger/examples/walk/pkger > master v0.17.1 ● ? > make
pkger
GOOS=linux go build -v -o example
docker build -t pkger:example .
Sending build context to Docker daemon  5.337MB
Step 1/4 : FROM ubuntu
 ---> d70eaf7277ea
Step 2/4 : EXPOSE 3000
 ---> Using cache
 ---> 607788680277
Step 3/4 : COPY example /bin/
 ---> Using cache
 ---> 57ad94720517
Step 4/4 : CMD /bin/example
 ---> Using cache
 ---> 75452b831659
Successfully built 75452b831659
Successfully tagged pkger:example
docker run -p 3000:3000 pkger:example
public     | 4096  | drwxrwxr-x | 2020-11-26T15:46:23+07:00 |
images     | 4096  | drwxrwxr-x | 2020-11-26T15:46:23+07:00 |
img1.png   | 27718 | -rw-rw-r-- | 2020-11-26T15:46:23+07:00 |
img2.png   | 27718 | -rw-rw-r-- | 2020-11-26T15:46:23+07:00 |
index.html | 257   | -rw-rw-r-- | 2020-11-26T15:46:23+07:00 |