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

Use multi-stage Dockerfile instead of building using host's Go binary #167

Closed
ericchiang opened this issue Apr 3, 2018 · 9 comments
Closed
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@ericchiang
Copy link

Something like https://github.com/coreos/dex/blob/master/Dockerfile

@fanminshi
Copy link
Contributor

Is the idea behind this to ensure that the build environment is same for everyone and not dependent on user's local tools?

@ericchiang
Copy link
Author

Yeah. It's a more reproducible build and reduces the use of arbitrary bash scripts.

@spahl
Copy link
Contributor

spahl commented Apr 24, 2018

Taking on this one.

@spahl spahl self-assigned this Apr 24, 2018
@hobti01
Copy link

hobti01 commented May 12, 2018

Is it desirable to use a scratch image for the final result?

FROM gcr.io/coreos-k8s-scale-testing/codegen:1.9.3 as codegen
WORKDIR /go/src/gitlab.com/my-org/my-app
COPY . .
# Re-generate generated code
RUN /go/src/k8s.io/code-generator/generate-groups.sh \
  deepcopy \
  gitlab.com/my-org/my-app/pkg/generated \
  gitlab.com/my-org/my-app/pkg/apis \
  my-org:v1alpha1

FROM golang:alpine as golang
WORKDIR /go/src/gitlab.com/my-org/my-app
COPY . .
COPY --from=codegen /go/src/gitlab.com/my-org/my-app/pkg/apis/my-org/v1alpha1/zz_generated.deepcopy.go \
  /go/src/gitlab.com/my-org/my-app/pkg/apis/my-org/v1alpha1/zz_generated.deepcopy.go
# Static build
RUN CGO_ENABLED=0 go install -v -ldflags '-extldflags "-static"'

FROM alpine:latest as alpine
WORKDIR /usr/share/zoneinfo
RUN apk --no-cache add tzdata zip ca-certificates
# -0 means no compression.  Needed because go's
# tz loader doesn't handle compressed data.
RUN zip --quiet -r -0 /zoneinfo.zip .

FROM scratch
ENTRYPOINT ["/my-app"]
ENV ZONEINFO /zoneinfo.zip
COPY --from=alpine /zoneinfo.zip /
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=golang /go/bin/my-app /my-app

@spahl spahl added refactoring good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Jun 5, 2018
@svenwltr
Copy link

Any updates on this? I am setting up CI for a new project and it would be great if I could utilize the automated build build of Quay.io directly, instead of using something like Travis as an intermediate stage for building the image.

@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 9, 2019
@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci-robot openshift-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 8, 2019
@openshift-bot
Copy link

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci-robot
Copy link

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants