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

Makefile: build promtail with CGO_ENABLED if GOHOSTOS=GOOS=linux #809

Merged
merged 2 commits into from
Aug 12, 2019

Conversation

rfratto
Copy link
Member

@rfratto rfratto commented Jul 29, 2019

No description provided.

@rfratto rfratto requested a review from slim-bean July 29, 2019 13:16
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rfratto
Copy link
Member Author

rfratto commented Jul 30, 2019

I want to hold off on this a bit for #762 since I know there will be merge conflicts

@sh0rez
Copy link
Member

sh0rez commented Jul 31, 2019

Update: see below

Can you please check the Docker container? It fails for me with

standard_init_linux.go:207: exec user process caused "no such file or directory"

Altough the /usr/local/bin/promtail is in place, it cannot be executed by hand:

/usr/bin # stat promtail
  File: promtail
  Size: 59509104        Blocks: 116232     IO Block: 4096   regular file
Device: beh/190d        Inode: 2032        Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-07-31 08:41:02.000000000
Modify: 2019-07-31 08:36:25.000000000
Change: 2019-07-31 08:36:30.000000000

/usr/bin # ./promtail
sh: ./promtail: not found

Other info:

/usr/bin # file promtail
promtail: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, Go BuildID=_sO-pfbrRk_qJH8MhCzo/Pwigi6dJO36ey-UilkK4/POa4moLK7qN8unm6QH_M/Yeujh4VTwFz48MW6LDnT, BuildID[sha1]=e87eb02001377e33f9c8ca263a0f13825e219549, stripped
/usr/bin # ldd promtail
        /lib64/ld-linux-x86-64.so.2 (0x7fc4c96d8000)
        libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fc4c96d8000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fc4c96d8000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc4c96d8000)

@sh0rez
Copy link
Member

sh0rez commented Jul 31, 2019

Okay, solved it myself. So long story short:

  1. The build image is debian. Debian uses glibc.
  2. The final container is alpine. Alpine uses muslc.
  3. You made the binary dynamic. This means it is dynamic against glibc.
  4. Alpine cannot execute glibc stuff
  5. Add libc6-compat, then it can
diff --git a/cmd/promtail/Dockerfile b/cmd/promtail/Dockerfile
index a038009..eb0f15e 100644
--- a/cmd/promtail/Dockerfile
+++ b/cmd/promtail/Dockerfile
@@ -9,7 +9,7 @@ WORKDIR /go/src/github.com/grafana/loki
 RUN make clean && make promtail

 FROM       alpine:3.9
-RUN        apk add --update --no-cache ca-certificates tzdata
+RUN        apk add --update --no-cache ca-certificates tzdata libc6-compat
 COPY       --from=build /go/src/github.com/grafana/loki/cmd/promtail/promtail /usr/bin/promtail
 COPY       cmd/promtail/promtail-local-config.yaml /etc/promtail/local-config.yaml
 COPY       cmd/promtail/promtail-docker-config.yaml /etc/promtail/docker-config.yaml

@rfratto
Copy link
Member Author

rfratto commented Jul 31, 2019

@sh0rez thanks for investigating!

For promtail to be able to read from the systemd journal, libsystemd.so
must be present at runtime. There is currently no package for alpine
that provides this file and such, debian should be used instead. A
future solution for providing an alpine-based build should be
considered in the future and will be tracked in grafana#838.

This commit also updates the Dockerfile to default to using the
latest loki-build-image. If a specific version is required, it should
be provided as a build arg to docker build.
@rfratto rfratto force-pushed the promtail_cgo branch 2 times, most recently from 38f6c06 to c7ccf78 Compare August 2, 2019 13:52
@rfratto rfratto merged commit 297f0e9 into grafana:master Aug 12, 2019
@rfratto rfratto deleted the promtail_cgo branch September 25, 2019 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants