forked from Xeograph/metabase-ocient-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
205 lines (158 loc) · 6.38 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
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
199
200
201
202
203
204
205
ARG METABASE_VERSION=v0.44.4
ARG METABASE_EDITION=oss
#################
# Metabase repo #
#################
FROM clojure:openjdk-11-tools-deps-slim-buster AS stg_base
ARG METABASE_EDITION
ARG METABASE_VERSION
# Reequirements for building the driver
RUN apt-get update \
&& apt-get install -y \
curl \
jq \
make \
npm \
unzip \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& npm install -g yarn
# Set our base workdir
WORKDIR /build
# Initialize Metabase submodule
RUN git init \
&& git submodule add https://github.com/metabase/metabase.git \
&& git submodule init
WORKDIR /build/metabase
RUN git checkout $(curl -s -H "Accept: application/vnd.github+json" https://api.github.com/repos/metabase/metabase/git/ref/tags/${METABASE_VERSION} | jq .object.sha | xargs echo)
# Then prep our Metabase dependencies
# We need to build java deps
# Ref: https://github.com/metabase/metabase/wiki/Migrating-from-Leiningen-to-tools.deps#preparing-dependencies
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -X:deps prep
WORKDIR /build/metabase/bin
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -X:deps prep
WORKDIR /build
################
# Driver stage #
################
FROM stg_base AS stg_driver
COPY deps.edn ./
COPY resources ./resources
COPY src ./src
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -X:deps prep
##############
# Test stage #
##############
FROM stg_driver as stg_unit_test
COPY test ./
# Run the unit tests
RUN --mount=type=cache,target=/root/.m2/repository \
CI=true \
DRIVERS=ocient \
clojure -X:dev:unit-test \
:project-dir "\"$(pwd)\""
###############
# Build stage #
###############
FROM stg_unit_test as stg_build
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -X:build:deps prep \
:project-dir "\"$(pwd)\""
# Then build the driver
RUN clojure -X:build \
:project-dir "\"$(pwd)\"" \
:target-dir "./target" \
-v 100
############################
# Export the Ocient driver #
############################
FROM scratch as stg_export
COPY --from=stg_build /build/target/ocient.metabase-driver.jar /
####################
# Test build stage #
####################
FROM stg_base as stg_test_uberjar
ARG METABASE_EDITION
WORKDIR /build/metabase
COPY deps.edn /build/metabase/modules/drivers/ocient/
COPY src/ /build/metabase/modules/drivers/ocient/
COPY resources/metabase-plugin.yaml /build/metabase/modules/drivers/ocient/resources/
COPY test/ /build/metabase/modules/drivers/ocient/
# FIXME Can we get rid of the patch here and build an uberjar via clojure???
COPY patches/test-tarball.patch /build/
RUN git apply /build/test-tarball.patch
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -X:test:deps prep
ENV CI=true
ENV INTERACTIVE=false
ENV MB_EDITION=${METABASE_EDITION}
# Build frontend (needs to run for some frontend tests)
RUN --mount=type=cache,target=/root/.m2/repository \
yarn build && \
yarn build-static-viz
# Build the uberjar
RUN --mount=type=cache,target=/root/.m2/repository \
clojure -T:dev:build uberjar
######################
# Test tarball stage #
######################
FROM stg_test_uberjar as stg_test_tarball
ARG GIT_SHA
ARG GIT_USER_NAME
ARG GIT_USER_EMAIL
ARG GIT_DIRTY
ARG METABASE_VERSION
ARG METABASE_OCIENT_VERSION
ARG METABASE_TEST_TARBALL_VERSION
ARG TARBALL_NAME=metabase_test_${METABASE_TEST_TARBALL_VERSION}
WORKDIR /build
# Place uberjar and remaining deps in a directory named "metabase_test" and tarball it
RUN mv metabase/target/uberjar/metabase.jar metabase/ \
&& mv metabase metabase_test \
&& echo "{"\
"\"time\": \"$(date -u +"%Y-%m-%dT%T")\""\
", \"git_sha\": \"${GIT_SHA}\""\
", \"git_user_name\": \"${GIT_USER_NAME}\""\
", \"git_user_email\": \"${GIT_USER_EMAIL}\""\
", \"git_dirty\": \"${GIT_DIRTY}\""\
", \"metabase_version\": \"${METABASE_VERSION}\""\
", \"metabase_ocient_version\": \"${METABASE_OCIENT_VERSION}\""\
", \"metabase_test_tarball_version\": \"${METABASE_TEST_TARBALL_VERSION}\""\
"}" > metabase_test/build_info.json \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/build_info.json \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/metabase.jar \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/test_modules/drivers/secret-test-driver/resources/metabase-plugin.yaml \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/test_modules/drivers/driver-deprecation-test-new/resources/metabase-plugin.yaml \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/test_modules/drivers/driver-deprecation-test-legacy/resources/metabase-plugin.yaml \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/README.md \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/frontend/test/__runner__/test_db_fixture.db.mv.db \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/frontend/test/__runner__/empty.db.mv.db \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/test_resources/* \
&& tar rvf metabase_test/target/${TARBALL_NAME}.tar metabase_test/test/metabase/test/data/dataset_definitions/*.edn \
&& gzip metabase_test/target/${TARBALL_NAME}.tar
#############################
# Test Tarball Export stage #
#############################
FROM scratch as stg_test_tarball_export
ARG METABASE_TEST_TARBALL_VERSION
ARG TARBALL_NAME=metabase_test_${METABASE_TEST_TARBALL_VERSION}
COPY --from=stg_test_tarball /build/metabase_test/target/${TARBALL_NAME}.tar.gz /
################
# Run Metabase #
################
FROM metabase/metabase:${METABASE_VERSION} AS stg_runner
COPY resources/log4j2.xml /var/log/log4j2.xml
ENV LOG4J_CONFIGURATION_FILE=/var/log/log4j2.xml
# A metabase user/group is manually added in https://github.com/metabase/metabase/blob/master/bin/docker/run_metabase.sh
# Make the UID and GID match
COPY --chown=2000:2000 --from=stg_export \
/ocient.metabase-driver.jar \
/plugins/ocient.metabase-driver.jar