Skip to content

Fix Dockerfile compatibility with Alpine Linux #80

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

Merged

Conversation

jordanjennings
Copy link

@jordanjennings jordanjennings commented Jun 3, 2020

In order to support Alpine Linux the CGO_ENABLED=0 flag is needed, which is set in .goreleaser.yml but was not set in the Dockerfile.

Before this change the binary built via the Dockerfile was not compatible with the hashicorp/terraform base image, which is based on Alpine Linux.

In other words this is what happened if you tried to build master and use it directly via the Dockerfile:

❯ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

❯ docker build -t jordanjennings/databricks-terraform:master .
Sending build context to Docker daemon  20.83MB
Step 1/9 : FROM golang:1.13

... lots of build output removed ...

Successfully built ed0089b8fd5d
Successfully tagged jordanjennings/databricks-terraform:master

❯ docker run --rm -it --entrypoint sh jordanjennings/databricks-terraform:master

/ # ls -al ~/.terraform.d/plugins/
total 30044
drwxr-xr-x    2 root     root          4096 Jun  2 20:33 .
drwxr-xr-x    3 root     root          4096 Jun  2 20:33 ..
-rwxr-xr-x    1 root     root      30755834 Jun  2 20:33 terraform-provider-databricks

/ # ~/.terraform.d/plugins/terraform-provider-databricks 
sh: /root/.terraform.d/plugins/terraform-provider-databricks: not found

Here's the same thing with the CGO_ENABLED=0 flag as included in this PR (error message as expected):

❯ docker run --rm -it --entrypoint sh jordanjennings/databricks-terraform:pr
/ # ~/.terraform.d/plugins/terraform-provider-databricks 
2020/06/03 14:28:39 dev, commit , built at unknown
This binary is a plugin. These are not meant to be executed directly.
Please execute the program that consumes these plugins, which will
load any plugins automatically

I don't know if CGO_ENABLED=0 is something that should instead be set in the Makefile, but setting in the Dockerfile was the more isolated way to handle it here.

In order to support Alpine Linux the CGO_ENABLED=0 flag
is needed, which is set in .goreleaser.yml but was not
set in the Dockerfile.

Before this change the binary built via the Dockerfile
was not compatible with hashicorp/terraform base image,
which is based on Alpine Linux.
@codecov-commenter
Copy link

Codecov Report

Merging #80 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #80   +/-   ##
=======================================
  Coverage   48.74%   48.74%           
=======================================
  Files          44       44           
  Lines        5943     5943           
=======================================
  Hits         2897     2897           
  Misses       2993     2993           
  Partials       53       53           
Flag Coverage Δ
#client 88.78% <ø> (ø)
#provider 37.22% <ø> (ø)

@stikkireddy
Copy link
Contributor

Hey @jordanjennings good find, I was able to recreate the issue: it seems to be related to one of the packages: "net". You can find more info here: https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host

It seems turning of CGO in the build process is one way of fixing this. The client library heavily uses the net library for api calls.

Thanks again for the contribution, LGTM so merging! 👍

@stikkireddy stikkireddy merged commit 6f6fc0b into databricks:master Jun 5, 2020
@jordanjennings jordanjennings deleted the fix-dockerfile-binary branch June 5, 2020 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants