Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BUILD.md
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)


2 changes: 1 addition & 1 deletion docker/DebugDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine
FROM alpine:3.15.0
MAINTAINER Team ACID @ Zalando <team-acid@zalando.de>

# We need root certificates to deal with teams api over https
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY build/* /
RUN addgroup -g 1000 pgo
RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo

USER 1000:1000
USER pgo:pgo

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.


ENTRYPOINT ["/postgres-operator"]

30 changes: 30 additions & 0 deletions docker/NotFromScrachDockerfile
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"]

32 changes: 32 additions & 0 deletions docker/README.md
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 `/`


45 changes: 45 additions & 0 deletions docker/WithBuildDebugDockerfile
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"]

36 changes: 36 additions & 0 deletions docker/WithBuildDockerfile
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"]


7 changes: 7 additions & 0 deletions docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Read this guide if you want to debug the operator, fix bugs or contribute new
features and tests.

## Simple build

To simply build the code and create an image, follow the instructions at:
[docker based code and image build](../docker/README.md)

For setting a full development environment, follow the steps below.

## Setting up Go

Postgres Operator is written in Go. Use the [installation instructions](https://golang.org/doc/install#install)
Expand Down