-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathDockerfile
More file actions
198 lines (160 loc) · 8.09 KB
/
Copy pathDockerfile
File metadata and controls
198 lines (160 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
ARG UBUNTU_VERSION=22.04
ARG GO_VERSION=1.26.2
ARG PLAYWRIGHT_GO_VERSION=v0.6100.0
ARG RUNNER_IMAGE="ubuntu:${UBUNTU_VERSION}"
# ----------------------------------------------------------------------------------------------------------------------
# Development stage with tools installed.
# Used for local development and testing.
# ----------------------------------------------------------------------------------------------------------------------
FROM ubuntu:${UBUNTU_VERSION} AS dev-base
ARG GO_VERSION
ARG PLAYWRIGHT_GO_VERSION
WORKDIR /opt/install
COPY scripts/docker /opt/install-scripts
ENV GO_VERSION=${GO_VERSION}
ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOPATH="/go"
ENV GOBIN="/go/bin"
ENV PATH="${GOBIN}:${PATH}"
ENV GOPROXY="https://proxy.golang.org|direct"
ENV PLAYWRIGHT_BROWSERS_PATH="/ms-playwright"
RUN apt-get update && \
apt-get install -y --no-install-recommends bash ca-certificates make unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
RUN bash /opt/install-scripts/install-go.sh "${GO_VERSION}"
RUN bash /opt/install-scripts/install-nodejs.sh
RUN bash /opt/install-scripts/install-postgresql-client.sh
RUN bash /opt/install-scripts/install-gomigrate.sh
RUN bash /opt/install-scripts/install-protoc.sh
RUN export GOMODCACHE=/tmp/go-mod GOCACHE=/tmp/go-build && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.6 && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.6.0 && \
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.26.3 && \
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.26.3 && \
go install github.com/air-verse/air@latest && \
go install github.com/mgechev/revive@v1.8.0 && \
go install gotest.tools/gotestsum@v1.12.3 && \
go install github.com/mxschmitt/playwright-go/cmd/playwright@"${PLAYWRIGHT_GO_VERSION}" && \
rm -rf /tmp/go-mod /tmp/go-build /go/pkg/* /root/.cache/* /root/.config/go/telemetry
WORKDIR /app
RUN mkdir -p "${PLAYWRIGHT_BROWSERS_PATH}"
RUN playwright install chromium-headless-shell --with-deps
RUN rm -rf /opt/install /opt/install-scripts /tmp/*
CMD [ "/bin/bash", "-c", "sleep infinity" ]
# ----------------------------------------------------------------------------------------------------------------------
# Builder stage to create production artifacts.
# Used to build the final runner image.
# ----------------------------------------------------------------------------------------------------------------------
FROM dev-base AS builder
ARG BASE_URL=https://app.superplane.com
ARG VITE_ASSET_BASE_URL=
ARG FRONTEND_PREBUILT=0
WORKDIR /app
COPY pkg /app/pkg
COPY cmd /app/cmd
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
COPY db/migrations /app/db/migrations
COPY db/data_migrations /app/db/data_migrations
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
COPY web_src /app/web_src
COPY protos /app/protos
COPY api/swagger /app/api/swagger
COPY rbac /app/rbac
COPY templates /app/templates
RUN rm -rf build && go build -o build/superplane cmd/server/main.go
WORKDIR /app/web_src
RUN if [ "$FRONTEND_PREBUILT" = "1" ]; then \
echo "Using prebuilt frontend assets from build context"; \
else \
npm install && \
if [ -n "$VITE_ASSET_BASE_URL" ]; then \
VITE_BASE_URL=$BASE_URL VITE_ASSET_BASE_URL=$VITE_ASSET_BASE_URL npm run build; \
else \
VITE_BASE_URL=$BASE_URL npm run build; \
fi; \
fi
# ----------------------------------------------------------------------------------------------------------------------
# Demo runner: single-container image with embedded Postgres and RabbitMQ.
# Used to build the demo image.
# ----------------------------------------------------------------------------------------------------------------------
FROM ${RUNNER_IMAGE} AS demo
ENV DEBIAN_FRONTEND=noninteractive
LABEL org.opencontainers.image.title="superplane-demo" \
org.opencontainers.image.description="SuperPlane demo image with embedded PostgreSQL and RabbitMQ for local trials." \
org.opencontainers.image.vendor="SuperPlane" \
org.opencontainers.image.source="https://github.com/superplanehq/superplane" \
org.opencontainers.image.url="https://superplane.com" \
org.opencontainers.image.documentation="https://docs.superplane.com"
RUN apt-get update && \
apt-get install -y --no-install-recommends \
postgresql \
postgresql-contrib \
rabbitmq-server \
ca-certificates \
curl \
git && \
ln -s /usr/lib/postgresql/*/bin/* /usr/local/bin/ && \
rm -rf /var/lib/apt/lists/*
# Install Node.js for localtunnel.
COPY scripts/docker/install-nodejs.sh /tmp/install-nodejs.sh
RUN bash /tmp/install-nodejs.sh && rm /tmp/install-nodejs.sh
# We still need the PostgreSQL client tools (createdb/migrate) as in the main runner.
COPY scripts/docker/install-postgresql-client.sh /tmp/install-postgresql-client.sh
RUN bash /tmp/install-postgresql-client.sh && rm /tmp/install-postgresql-client.sh
WORKDIR /app
COPY --from=builder /usr/bin/createdb /usr/bin/createdb
COPY --from=builder /usr/bin/migrate /usr/bin/migrate
COPY --from=builder /app/build/superplane /app/build/superplane
COPY --from=builder /app/docker-entrypoint.sh /app/docker-entrypoint.sh
COPY --from=builder /app/db/migrations /app/db/migrations
COPY --from=builder /app/db/data_migrations /app/db/data_migrations
COPY --from=builder /app/pkg/web/assets/dist /app/pkg/web/assets/dist
COPY --from=builder /app/api/swagger /app/api/swagger
COPY --from=builder /app/rbac /app/rbac
COPY --from=builder /app/templates /app/templates
# SuperGit binary is downloaded by release/superplane-demo-image/download-supergit.sh before build.
COPY build/superplane-demo-supergit/supergit /app/supergit
RUN chmod +x /app/supergit
# Trial entrypoint that runs embedded Postgres and RabbitMQ and then SuperPlane.
COPY release/superplane-demo-image/entrypoint.sh /app/entrypoint.sh
COPY release/superplane-demo-image/gen-superplane-env.sh /app/gen-superplane-env.sh
COPY release/superplane-demo-image/spinner.sh /app/spinner.sh
RUN chmod +x /app/entrypoint.sh /app/docker-entrypoint.sh /app/gen-superplane-env.sh /app/spinner.sh
EXPOSE 8000
ENTRYPOINT ["/app/entrypoint.sh"]
# ----------------------------------------------------------------------------------------------------------------------
# Runner stage to run the application.
# Used as the final image.
# ----------------------------------------------------------------------------------------------------------------------
FROM ${RUNNER_IMAGE} AS runner
LABEL org.opencontainers.image.title="superplane" \
org.opencontainers.image.description="SuperPlane" \
org.opencontainers.image.vendor="SuperPlane" \
org.opencontainers.image.source="https://github.com/superplanehq/superplane" \
org.opencontainers.image.url="https://superplane.com" \
org.opencontainers.image.documentation="https://docs.superplane.com"
# postgresql-client needs to be installed here too,
# otherwise the createdb command won't work.
# Install PostgreSQL 17.5 client tools
COPY scripts/docker/install-postgresql-client.sh install-postgresql-client.sh
RUN bash install-postgresql-client.sh
# We don't need Docker health checks, since these containers
# are intended to run in Kubernetes pods, which have probes.
HEALTHCHECK NONE
WORKDIR /app
RUN chown nobody /app
# Copy every artifact needed to run the application from previous stages
COPY --from=builder --chown=nobody:root /usr/bin/createdb /usr/bin/createdb
COPY --from=builder --chown=nobody:root /usr/bin/migrate /usr/bin/migrate
COPY --from=builder --chown=nobody:root /app/build/superplane /app/build/superplane
COPY --from=builder --chown=nobody:root /app/docker-entrypoint.sh /app/docker-entrypoint.sh
COPY --from=builder --chown=nobody:root /app/db/migrations /app/db/migrations
COPY --from=builder --chown=nobody:root /app/db/data_migrations /app/db/data_migrations
COPY --from=builder --chown=nobody:root /app/pkg/web/assets/dist /app/pkg/web/assets/dist
COPY --from=builder --chown=nobody:root /app/api/swagger /app/api/swagger
COPY --from=builder --chown=nobody:root /app/rbac /app/rbac
COPY --from=builder --chown=nobody:root /app/templates /app/templates
USER nobody
CMD ["bash", "/app/docker-entrypoint.sh"]