-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dockerfile based build plus create postgres-operator images #1066
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
Open
ReSearchITEng
wants to merge
8
commits into
zalando:master
Choose a base branch
from
ReSearchITEng:dockerfile_master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+160
−2
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
efe39dc
Dockerfile based build on alpine plus create postgres-operator-secure…
ReSearchITEng 7f1d10d
code build plus image build - all in docker
ReSearchITEng 9d45f06
Update Dockerfile
ReSearchITEng e78c87b
as requested, move all to docker directory. Add more docs
ReSearchITEng 974f9a0
keep old Dockerfile as original, as it's used by Travis
ReSearchITEng 2972edd
update golang to 1.15
ReSearchITEng d24d763
update golang 1.17
ReSearchITEng 812f549
alpine 3.15.0
ReSearchITEng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Developers | ||
| [developer docs](docs/developer.md) | ||
|
|
||
| # In docker builds | ||
| [docker based builds](docker/README.md) | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ########################################################### | ||
| ### builder image ############################### | ||
| ########################################################### | ||
| FROM golang:1.17.6-alpine3.15 AS builder | ||
|
|
||
| RUN apk --no-cache add ca-certificates make git && update-ca-certificates | ||
| WORKDIR /go/src/github.com/zalando/postgres-operator/ | ||
| COPY . . | ||
| RUN make linux | ||
|
|
||
| ########################################################### | ||
| ### operator image -> the version with full alpine image ## | ||
| ########################################################### | ||
| ## This is optional, only as example. Only last image is used | ||
| FROM alpine:3.15.0 as postgres-operator-alpine | ||
| MAINTAINER Team ACID @ Zalando <team-acid@zalando.de> | ||
| LABEL org.opencontainers.image.authors "Team ACID @ Zalando <team-acid@zalando.de>" | ||
| LABEL org.opencontainers.image.url "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.documentation "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.source "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.title "zalando/posgress-operator" | ||
| LABEL org.opencontainers.image.description "posgress-operator-alpine - full alpine image" | ||
| # We need root certificates to deal with teams api over https | ||
| RUN apk --no-cache add ca-certificates && update-ca-certificates | ||
| COPY --from=builder /go/src/github.com/zalando/postgres-operator/build/* / | ||
| RUN addgroup -g 1000 pgo | ||
| RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo | ||
| USER pgo:pgo | ||
| ENTRYPOINT ["/postgres-operator"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Developers | ||
| [developer docs](docs/developer.md) | ||
|
|
||
| [build docs](../BUILD.md) | ||
|
|
||
| # Build both code and image using Dockerfile | ||
| Most Dockerfiles both build the code as well as the image. | ||
|
|
||
| # Choose the desired build flavour: | ||
| - WithBuildDockerfile -> builds code as well as more secure a version of the image (from scratch instead of basing on alpine) | ||
| - WithBuildDebugDockerfile -> builds a debug version of the image, based on alpine and uses "github.com/derekparker/delve/cmd/dlv". exposes port :7777 | ||
| - NotFromScrachDockerfile -> alpine based image (notFromScratch like in Dockerfile ) | ||
| - Dockerfile -> alpine based image, without the build, it expects binary is build outside. This is used by Makefile (& Travis) | ||
| - DebugDockerfile -> alpine based image, without the build, it expects binary is build outside. This is used by Makefile (& Travis) to make debug image. | ||
|
|
||
| # Command example: | ||
| ```shell | ||
| docker build -f docker/WithBuildDockerfile . | ||
| ``` | ||
| OR, using proxy and eventually also internal go mirrors | ||
| ```shell | ||
| docker build -f docker/WithBuildDockerfile . --build-arg HTTP_PROXY=http://proxy.corp.example.com:1234 --build-arg HTTPS_PROXY=http://proxy.corp.example.com:1234 --build-arg NO_PROXY=.corp.example.com --build-arg GOPROXY=http://golang-intranet-proxy.corp.example.com:8081/repository/goproxy/ --build-arg GOSUMDB=off | ||
| ``` | ||
|
|
||
| # docker.io | ||
| This solution works also when you want to build your fork using docker hub (docker.io) (and share/test your image directly from there). | ||
|
|
||
| For automating docker build. Make sure you pass the context to root of it project. | ||
| Same for for docker hub (docker.io) builds: | ||
| set the **Dockerfile** column to `docker/WithBuildDockerfile` and **context** column to `/` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| ########################################################### | ||
| ### builder image ############################### | ||
| ########################################################### | ||
| ARG GOPROXY=https://proxy.golang.org | ||
| #ARG GONOPROXY | ||
| #ARG GOPRIVATE | ||
| ARG GOSUMDB=sum.golang.org | ||
| #ARG GONOSUMDB | ||
| FROM golang:1.17.6-alpine3.15 AS builder | ||
| RUN apk --no-cache add ca-certificates make git && update-ca-certificates | ||
| WORKDIR /go/src/github.com/zalando/postgres-operator/ | ||
| COPY . . | ||
| RUN make linux | ||
|
|
||
| ########################################################### | ||
| ### operator image -> debug version ################## | ||
| ########################################################### | ||
| FROM golang:1.17.6-alpine3.15 AS postgres-operator-debug | ||
| MAINTAINER Team ACID @ Zalando <team-acid@zalando.de> | ||
| LABEL org.opencontainers.image.authors "Team ACID @ Zalando <team-acid@zalando.de>" | ||
| LABEL org.opencontainers.image.url "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.documentation "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.source "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.title "zalando/posgress-operator" | ||
| LABEL org.opencontainers.image.description "posgress-operator-debug" | ||
|
|
||
| # We need root certificates to deal with teams api over https | ||
| COPY --from=builder /go/src/github.com/zalando/postgres-operator/build/* / | ||
|
|
||
| # We need root certificates to deal with teams api over https | ||
| RUN apk --no-cache add ca-certificates git musl-dev | ||
|
|
||
| RUN addgroup -g 1000 pgo | ||
| RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo | ||
|
|
||
| RUN go get github.com/derekparker/delve/cmd/dlv | ||
| RUN cp /go/bin/dlv /dlv | ||
| RUN chown -R pgo:pgo /dlv | ||
|
|
||
| USER pgo:pgo | ||
| EXPOSE 7777 | ||
| RUN ls -l / | ||
|
|
||
| CMD ["/dlv", "--listen=:7777", "--headless=true", "--api-version=2", "exec", "/postgres-operator"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| ########################################################### | ||
| ### builder image ############################### | ||
| ########################################################### | ||
| ARG GOPROXY=https://proxy.golang.org | ||
| #ARG GONOPROXY | ||
| #ARG GOPRIVATE | ||
| ARG GOSUMDB=sum.golang.org | ||
| #ARG GONOSUMDB | ||
| FROM golang:1.17.6-alpine3.15 AS builder | ||
| RUN apk --no-cache add ca-certificates make git && update-ca-certificates | ||
| WORKDIR /go/src/github.com/zalando/postgres-operator/ | ||
| COPY . . | ||
| RUN make linux | ||
|
|
||
| ################################################################ | ||
| ### operator image -> the more secure version (from scratch) ### | ||
| ################################################################ | ||
| FROM scratch AS postgres-operator-secure | ||
| MAINTAINER Team ACID @ Zalando <team-acid@zalando.de> | ||
| LABEL org.opencontainers.image.authors "Team ACID @ Zalando <team-acid@zalando.de>" | ||
| LABEL org.opencontainers.image.url "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.documentation "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.source "https://github.com/zalando/postgres-operator/" | ||
| LABEL org.opencontainers.image.title "zalando/posgress-operator" | ||
| LABEL org.opencontainers.image.description "posgress-operator-secure from scratch image" | ||
|
|
||
| COPY --from=builder /etc/passwd /etc/group /etc/ | ||
|
|
||
| # We need root certificates to deal with teams api over https | ||
| COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
| COPY --from=builder /go/src/github.com/zalando/postgres-operator/build/* / | ||
|
|
||
| USER nobody | ||
| ENTRYPOINT ["/postgres-operator"] | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, having "named" user prevents kubernetes to check for non root. I think it would be best to keep as it's now.