forked from stackql/stackql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
168 lines (112 loc) · 5.18 KB
/
Dockerfile
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
FROM golang:1.18.4-bullseye AS sourceprep
ENV SRC_DIR=/work/stackql/src
ENV BUILD_DIR=/work/stackql/build
RUN mkdir -p ${SRC_DIR} ${BUILD_DIR}
ADD internal ${SRC_DIR}/internal
ADD pkg ${SRC_DIR}/pkg
ADD stackql ${SRC_DIR}/stackql
ADD test ${SRC_DIR}/test
COPY go.mod go.sum ${SRC_DIR}/
RUN cd ${SRC_DIR} && ls && go get -v -t -d ./...
FROM sourceprep AS builder
ARG BUILDMAJORVERSION="1"
ARG BUILDMINORVERSION="1"
ARG BUILDPATCHVERSION="1"
ARG BUILDCOMMITSHA="1"
ARG BUILDSHORTCOMMITSHA="1"
ARG BUILDDATE="1"
ARG PLANCACHEENABLED="1"
ARG BUILDPLATFORM="1"
ENV BUILDMAJORVERSION=${BUILDMAJORVERSION}
ENV BUILDMINORVERSION=${BUILDMINORVERSION}
ENV BUILDPATCHVERSION=${BUILDPATCHVERSION}
ENV BUILDCOMMITSHA=${BUILDCOMMITSHA}
ENV BUILDSHORTCOMMITSHA=${BUILDSHORTCOMMITSHA}
ENV BUILDDATE=${BUILDDATE}
ENV PLANCACHEENABLED=${PLANCACHEENABLED}
ENV BUILDPLATFORM=${BUILDPLATFORM}
ENV SRC_DIR=/work/stackql/src
ENV BUILD_DIR=/work/stackql/build
RUN cd ${SRC_DIR} \
&& go test --tags "json1 sqleanall" ./... \
&& go build -ldflags "-X github.com/stackql/stackql/internal/stackql/cmd.BuildMajorVersion=$BUILDMAJORVERSION \
-X github.com/stackql/stackql/internal/stackql/cmd.BuildMinorVersion=$BUILDMINORVERSION \
-X github.com/stackql/stackql/internal/stackql/cmd.BuildPatchVersion=$BUILDPATCHVERSION \
-X github.com/stackql/stackql/internal/stackql/cmd.BuildCommitSHA=$BUILDCOMMITSHA \
-X github.com/stackql/stackql/internal/stackql/cmd.BuildShortCommitSHA=$BUILDSHORTCOMMITSHA \
-X \"github.com/stackql/stackql/internal/stackql/cmd.BuildDate=$BUILDDATE\" \
-X \"stackql/internal/stackql/planbuilder.PlanCacheEnabled=$PLANCACHEENABLED\" \
-X github.com/stackql/stackql/internal/stackql/cmd.BuildPlatform=$BUILDPLATFORM" \
--tags "json1 sqleanall" \
-o ${BUILD_DIR}/stackql ./stackql
FROM python:3.11-bullseye AS utility
ARG TEST_ROOT_DIR=/opt/test/stackql
ENV TEST_ROOT_DIR=${TEST_ROOT_DIR}
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
default-jdk \
default-jre \
maven \
openssl \
postgresql-client \
&& pip3 install PyYaml robotframework psycopg2-binary "psycopg[binary]" sqlalchemy \
&& mvn \
org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \
-Dartifact=org.mock-server:mockserver-netty:5.12.0:jar:shaded \
-DoutputDirectory=${TEST_ROOT_DIR}/test/downloads
FROM utility AS certificates
ARG TEST_ROOT_DIR=/opt/test/stackql
ENV TEST_ROOT_DIR=${TEST_ROOT_DIR}
RUN mkdir -p ${TEST_ROOT_DIR}
ADD test ${TEST_ROOT_DIR}/test
RUN openssl req -x509 -keyout ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_server_key.pem -out ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_server_cert.pem -config ${TEST_ROOT_DIR}/test/server/mtls/openssl.cnf -days 365 \
&& openssl req -x509 -keyout ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_client_key.pem -out ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_client_cert.pem -config ${TEST_ROOT_DIR}/test/server/mtls/openssl.cnf -days 365 \
&& openssl req -x509 -keyout ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_rubbish_key.pem -out ${TEST_ROOT_DIR}/test/server/mtls/credentials/pg_rubbish_cert.pem -config ${TEST_ROOT_DIR}/test/server/mtls/openssl.cnf -days 365
FROM python:3.11-bullseye AS registrymock
ARG TEST_ROOT_DIR=/opt/test/stackql
ENV TEST_ROOT_DIR=${TEST_ROOT_DIR}
RUN mkdir -p ${TEST_ROOT_DIR}
COPY --from=certificates /opt/test/stackql ${TEST_ROOT_DIR}/
RUN pip3 install PyYaml \
&& python3 ${TEST_ROOT_DIR}/test/python/registry-rewrite.py
FROM utility AS integration
ARG TEST_ROOT_DIR=/opt/test/stackql
ENV TEST_ROOT_DIR=${TEST_ROOT_DIR}
ARG BUILDMAJORVERSION="1"
ARG BUILDMINORVERSION="1"
ARG BUILDPATCHVERSION="1"
ARG BUILDCOMMITSHA="1"
ARG BUILDSHORTCOMMITSHA="1"
ARG BUILDDATE="1"
ARG PLANCACHEENABLED="1"
ARG BUILDPLATFORM="1"
ENV BUILDMAJORVERSION=${BUILDMAJORVERSION}
ENV BUILDMINORVERSION=${BUILDMINORVERSION}
ENV BUILDPATCHVERSION=${BUILDPATCHVERSION}
ENV BUILDCOMMITSHA=${BUILDCOMMITSHA}
ENV BUILDSHORTCOMMITSHA=${BUILDSHORTCOMMITSHA}
ENV BUILDDATE=${BUILDDATE}
ENV PLANCACHEENABLED=${PLANCACHEENABLED}
ENV BUILDPLATFORM=${BUILDPLATFORM}
RUN mkdir -p ${TEST_ROOT_DIR}/build
COPY --from=registrymock /opt/test/stackql ${TEST_ROOT_DIR}/
COPY --from=builder /work/stackql/build/stackql ${TEST_ROOT_DIR}/build/
RUN robot ${TEST_ROOT_DIR}/test/robot/functional
FROM ubuntu:22.04 AS app
ARG TEST_ROOT_DIR=/opt/test/stackql
ENV TEST_ROOT_DIR=${TEST_ROOT_DIR}
ARG APP_DIR=/srv/stackql
ARG STACKQL_CFG_ROOT=/opt/stackql
ARG STACKQL_PG_PORT=5477
ENV APP_DIR="${APP_DIR}"
ENV STACKQL_CFG_ROOT="${STACKQL_CFG_ROOT}"
ENV STACKQL_PG_PORT="${STACKQL_PG_PORT}"
RUN mkdir -p ${APP_DIR} ${STACKQL_CFG_ROOT}/keys ${STACKQL_CFG_ROOT}/srv/credentials ${STACKQL_CFG_ROOT}/credentials/dummy ${STACKQL_CFG_ROOT}/registry ${STACKQL_CFG_ROOT}/logs ${STACKQL_CFG_ROOT}/db
ENV PATH="${APP_DIR}:${PATH}"
COPY --from=integration ${TEST_ROOT_DIR}/build/stackql ${APP_DIR}/
RUN apt-get update \
&& apt-get install -y ca-certificates \
&& update-ca-certificates
EXPOSE ${STACKQL_PG_PORT}/tcp
WORKDIR ${STACKQL_CFG_ROOT}
CMD ["/bin/bash", "-c", "stackql --pgsrv.port=${STACKQL_PG_PORT} srv"]