zitadel

Форк
0
/
workflow.Dockerfile 
302 строки · 8.3 Кб
1
# ##############################################################################
2
# core
3
# ##############################################################################
4

5
# #######################################
6
# download dependencies
7
# #######################################
8
FROM golang:buster AS core-deps
9

10
WORKDIR /go/src/github.com/zitadel/zitadel
11

12
COPY go.mod .
13
COPY go.sum .
14

15
RUN go mod download
16

17
# #######################################
18
# compile custom protoc plugins
19
# #######################################
20
FROM golang:buster AS core-api-generator
21

22
WORKDIR /go/src/github.com/zitadel/zitadel
23

24
COPY go.mod .
25
COPY go.sum .
26
COPY internal/protoc internal/protoc
27
COPY pkg/grpc/protoc/v2 pkg/grpc/protoc/v2
28

29
RUN go install internal/protoc/protoc-gen-authoption/main.go \
30
    && mv $(go env GOPATH)/bin/main $(go env GOPATH)/bin/protoc-gen-authoption \
31
	&& go install internal/protoc/protoc-gen-zitadel/main.go \
32
    && mv $(go env GOPATH)/bin/main $(go env GOPATH)/bin/protoc-gen-zitadel
33

34
# #######################################
35
# build backend stub
36
# #######################################
37
FROM golang:buster AS core-api
38

39
WORKDIR /go/src/github.com/zitadel/zitadel
40

41
COPY go.mod .
42
COPY go.sum .
43
COPY proto proto
44
COPY buf.*.yaml .
45
COPY Makefile Makefile
46
COPY --from=core-api-generator /go/bin /usr/local/bin
47

48
RUN make grpc
49

50
# #######################################
51
# generate code for login ui
52
# #######################################
53
FROM golang:buster AS core-login
54

55
WORKDIR /go/src/github.com/zitadel/zitadel
56

57
COPY Makefile Makefile
58
COPY internal/api/ui/login/static internal/api/ui/login/static
59
COPY internal/api/ui/login/statik internal/api/ui/login/statik
60
COPY internal/notification/static internal/notification/static
61
COPY internal/notification/statik internal/notification/statik
62
COPY internal/static internal/static
63
COPY internal/statik internal/statik
64

65
RUN make static
66

67
# #######################################
68
# generate code for assets
69
# #######################################
70
FROM golang:buster AS core-assets
71
WORKDIR /go/src/github.com/zitadel/zitadel
72

73
COPY go.mod .
74
COPY go.sum .
75
COPY Makefile Makefile
76
COPY internal/api/assets/generator internal/api/assets/generator
77
COPY internal/config internal/config
78
COPY internal/errors internal/errors
79
COPY --from=core-api /go/src/github.com/zitadel/zitadel/openapi/v2 openapi/v2
80

81
RUN make assets
82

83
# #######################################
84
# Gather all core files
85
# #######################################
86
FROM core-deps AS core-gathered
87

88
COPY cmd cmd
89
COPY internal internal
90
COPY pkg pkg
91
COPY proto proto
92
COPY openapi openapi
93
COPY statik statik
94
COPY main.go main.go
95
COPY --from=core-api /go/src/github.com/zitadel/zitadel .
96
COPY --from=core-login /go/src/github.com/zitadel/zitadel .
97
COPY --from=core-assets /go/src/github.com/zitadel/zitadel/internal ./internal
98

99
# ##############################################################################
100
# build console
101
# ##############################################################################
102

103
# #######################################
104
# download console dependencies
105
# #######################################
106
FROM node:20-buster AS console-deps
107

108
WORKDIR /zitadel/console
109

110
COPY console/package.json .
111
COPY console/yarn.lock .
112

113
RUN yarn install --frozen-lockfile
114

115
# #######################################
116
# generate console client
117
# #######################################
118
FROM node:20-buster AS console-client
119

120
WORKDIR /zitadel/console
121

122
# install buf
123
COPY --from=bufbuild/buf:latest /usr/local/bin/* /usr/local/bin/
124
ENV PATH="/usr/local/bin:${PATH}"
125

126
COPY console/package.json .
127
COPY console/buf.*.yaml .
128
COPY proto ../proto
129

130
RUN yarn generate
131

132
# #######################################
133
# Gather all console files
134
# #######################################
135
FROM console-deps as console-gathered
136

137
COPY --from=console-client /zitadel/console/src/app/proto/generated src/app/proto/generated
138

139
COPY console/src src
140
COPY console/angular.json .
141
COPY console/ngsw-config.json .
142
COPY console/tsconfig* .
143

144
# #######################################
145
# Build console
146
# #######################################
147
FROM console-gathered AS console
148
RUN yarn build
149

150
# ##############################################################################
151
# build the executable
152
# ##############################################################################
153

154
# #######################################
155
# build executable
156
# #######################################
157
FROM core-gathered AS compile
158

159
ARG GOOS 
160
ARG GOARCH
161

162
COPY --from=console /zitadel/console/dist/console internal/api/ui/console/static/
163

164
RUN go build -o zitadel -ldflags="-s -w -race" \
165
    && chmod +x zitadel
166

167
ENTRYPOINT [ "./zitadel" ]
168

169
# #######################################
170
# copy executable
171
# #######################################
172
FROM scratch AS copy-executable
173
ARG GOOS 
174
ARG GOARCH
175

176
COPY --from=compile /go/src/github.com/zitadel/zitadel/zitadel /.artifacts/zitadel
177

178
# ##############################################################################
179
#  tests
180
# ##############################################################################
181
FROM ubuntu/postgres:latest AS test-core-base
182

183
ARG DEBIAN_FRONTEND=noninteractive
184

185
RUN apt-get update && \
186
    apt-get install -y --no-install-recommends \
187
        gcc \
188
        make \
189
        ca-certificates \
190
        gcc \
191
        && \
192
    update-ca-certificates; \
193
    rm -rf /var/lib/apt/lists/*
194

195
# install go
196
COPY --from=golang:latest /usr/local/go/ /usr/local/go/
197
ENV PATH="/go/bin:/usr/local/go/bin:${PATH}"
198

199
WORKDIR /go/src/github.com/zitadel/zitadel
200

201
# default vars
202
ENV DB_FLAVOR=postgres
203
ENV POSTGRES_USER=zitadel
204
ENV POSTGRES_DB=zitadel
205
ENV POSTGRES_PASSWORD=postgres
206
ENV POSTGRES_HOST_AUTH_METHOD=trust
207

208
ENV PGUSER=zitadel
209
ENV PGDATABASE=zitadel
210
ENV PGPASSWORD=postgres
211

212
ENV CGO_ENABLED=1
213

214
# copy zitadel files
215
COPY --from=core-deps /go/pkg/mod /root/go/pkg/mod
216
COPY --from=core-gathered /go/src/github.com/zitadel/zitadel .
217

218
# #######################################
219
# unit test core
220
# #######################################
221
FROM test-core-base AS test-core-unit
222
RUN go test -race -v -coverprofile=profile.cov ./...
223

224
# #######################################
225
# coverage output
226
# #######################################
227
FROM scratch AS coverage-core-unit
228
COPY --from=test-core-unit /go/src/github.com/zitadel/zitadel/profile.cov /coverage/
229

230
# #######################################
231
# integration test core
232
# #######################################
233
FROM test-core-base AS test-core-integration
234
ENV DB_FLAVOR=cockroach
235

236
# install cockroach
237
COPY --from=cockroachdb/cockroach:latest /cockroach/cockroach /usr/local/bin/
238
ENV COCKROACH_BINARY=/cockroach/cockroach
239

240
ENV ZITADEL_MASTERKEY=MasterkeyNeedsToHave32Characters
241

242
COPY build/core-integration-test.sh /usr/local/bin/run-tests.sh
243
RUN chmod +x /usr/local/bin/run-tests.sh
244

245
RUN run-tests.sh
246

247
# #######################################
248
# coverage output
249
# #######################################
250
FROM scratch AS coverage-core-integration
251
COPY --from=test-core-integration /go/src/github.com/zitadel/zitadel/profile.cov /coverage/
252

253
# ##############################################################################
254
#  linting
255
# ##############################################################################
256

257
# #######################################
258
# api
259
# #######################################
260
FROM bufbuild/buf:latest AS lint-api
261

262
COPY proto proto
263
COPY buf.*.yaml .
264

265
RUN buf lint
266

267
# #######################################
268
# console
269
# #######################################
270
FROM console-gathered AS lint-console
271

272
COPY console/.eslintrc.js .
273
COPY console/.prettier* .
274
RUN yarn lint
275

276
# #######################################
277
# core
278
# #######################################
279
FROM golangci/golangci-lint:latest AS lint-core
280
ARG LINT_EXIT_CODE=1
281

282
WORKDIR /go/src/github.com/zitadel/zitadel
283

284
COPY .golangci.yaml .
285
COPY .git/ .git/
286
COPY --from=core-deps /go/pkg/mod /go/pkg/mod
287
COPY --from=core-gathered /go/src/github.com/zitadel/zitadel .
288

289
RUN git fetch https://github.com/zitadel/zitadel main:main
290

291
RUN golangci-lint run \
292
    --timeout 10m \
293
    --config ./.golangci.yaml \
294
    --out-format=github-actions:report,colored-line-number \
295
    --issues-exit-code=${LINT_EXIT_CODE} \
296
    --concurrency=$(getconf _NPROCESSORS_ONLN)
297

298
# #######################################
299
# report output
300
# #######################################
301
FROM scratch AS lint-core-report
302
COPY --from=lint-core /go/src/github.com/zitadel/zitadel/report .

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.