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

feat(docker): add Dockerfile #25

Closed
wants to merge 1 commit into from
Closed

feat(docker): add Dockerfile #25

wants to merge 1 commit into from

Conversation

philoserf
Copy link
Contributor

@philoserf philoserf commented Nov 22, 2018

This should be added to goreleaser as well. https://goreleaser.com/customization/#Docker

Begins work on issue #10


This change is Reviewable

@philoserf
Copy link
Contributor Author

There are a few ways to complete issue #10.

  • goreleaser provides automation as mentioned above
  • docker hub and quay both offer automated builds free to open source
  • travis-ci also offers a method

I recommend goreleaser if that will be used for other automated build/release tooling.

References:

@Ilyes512
Copy link
Owner

I would probably use 2 dockerfile's... One named Dockefile_goreleaser and generic Dockerfile.

The difference would be that inside the Dockerfile it would build the app from scratch while the goreleaser version would simply be used inside the CI and only copy the already build app.

In the generic Dockerfile we also need to pass (probably 3) build args to pass on the build, commit and version (might be possbly to only pass the version as the other 2 can be generated).

@philoserf
Copy link
Contributor Author

philoserf commented Nov 22, 2018

I will add the build flags to the already provided Dockerfile and add a second for go releaser as described.

I'd like to add a method to automate docker build during local development. That could be introducing a Makefile, a shell script, or an other task runner. I default to make. I work in communities that use ./hack/script and ./scripts/script.

I defer to the style of this project or can defer that automation to a separate offered pull request.

@@ -0,0 +1,13 @@
FROM golang:1.11 as build
Copy link
Owner

Choose a reason for hiding this comment

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

I normally use the image tag that is as precise as possible ie in this case1.11.2-alpine3.8. I could live with 1.11-alpine3.8 so fixes are included when rerunning docker builds.

WORKDIR /
COPY . /
ENV CGO_ENABLED 0
RUN go build -tags 'static' -ldflags '-extldflags "-static"' .
Copy link
Owner

Choose a reason for hiding this comment

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

I would like to (re)check what flags are actually nice to use (and what there use actually means). Here I have added a lot of flags https://github.com/Ilyes512/kubia/blob/master/Dockerfile#L16 Adding -s -w removes some debugging things that would reduce the image size (not that it really matters).

FROM scratch
LABEL maintainer="https://github.com/Ilyes512/boilr"

COPY --from=build /boilr /
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe also add these lines https://github.com/Ilyes512/kubia/blob/master/Dockerfile#L22-L24 It copies ssl certs (at this point it might not be needed cause we are not running a server), but adding /etc/passwd might be nice to add since os/user uses it as a fallback when building the app without cgo enabled.

I know that cobra (and maybe boilr as well - haven't checked it) use https://github.com/mitchellh/go-homedir at the moment, but that package can be replaced with os/user (the fallback was added in a later golang version).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a build tag for static build with osuser. I'll find it.

@philoserf
Copy link
Contributor Author

After playing with goreleaser I'm going to pass on a Dockerfile_goreleaser. I just don't like how it works and the twisting needed to comply with it's opinions.

I will find the full set of build tags required and tighten the FROM pin.

@Ilyes512
Copy link
Owner

Ilyes512 commented Dec 5, 2018

Than I will configure Docker hub auto-builds feature so the images will be available on the public registry. Travis for github releases and home brew. Docker hub for the registry.

@philoserf philoserf closed this Jan 5, 2019
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.

2 participants