forked from PDOK/gokoala
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (56 loc) · 2.74 KB
/
Copy pathDockerfile
File metadata and controls
71 lines (56 loc) · 2.74 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
ARG REGISTRY="docker.io"
####### Node.js build
FROM ${REGISTRY}/node:lts-alpine3.17 AS build-component
RUN mkdir -p /usr/src/app
COPY ./webcomponents/vectortile-view-component /usr/src/app
WORKDIR /usr/src/app
RUN npm install
RUN npm run build
####### Go build
FROM --platform=${BUILDPLATFORM:-linux/amd64} ${REGISTRY}/golang:1.21-bookworm AS build-env
WORKDIR /go/src/service
ADD . /go/src/service
ARG TARGETARCH
# enable cgo in order to interface with sqlite
ENV CGO_ENABLED=1
ENV GOOS=linux
# install sqlite-related compile-time dependencies
RUN set -eux && \
apt-get update && \
apt-get install -y libcurl4-openssl-dev libssl-dev libsqlite3-mod-spatialite gcc-aarch64-linux-gnu && \
rm -rf /var/lib/apt/lists/*
RUN GOARCH=${TARGETARCH} go mod download all
ENV CC=aarch64-linux-gnu-gcc
# build & test the binary with debug information removed.
RUN GOARCH=${TARGETARCH} go test -short
RUN GOARCH=${TARGETARCH} go build -v -ldflags '-w -s' -a -installsuffix cgo -o /gokoala github.com/PDOK/gokoala
# delete all go files (and testdata dirs) so only assets/templates/etc remain, since in a later
# stage we need to copy these remaining files including their subdirectories to the final docker image.
RUN find . -type f -name "*.go" -delete && find . -type d -name "testdata" -prune -exec rm -rf {} \;
####### Final image (use debian tag since we rely on C-libs)
FROM --platform=${BUILDPLATFORM:-linux/amd64} ${REGISTRY}/debian:bookworm-slim
# install sqlite-related runtime dependencies
RUN set -eux && \
apt-get update && \
apt-get install -y libcurl4 openssl libsqlite3-mod-spatialite && \
rm -rf /var/lib/apt/lists/*
EXPOSE 8080
# use the WORKDIR to create a /tmp folder
WORKDIR /tmp
WORKDIR /
ENV PATH=/
# include executable
COPY --from=build-env /gokoala /
# include assets/templates/etc (be specific here to only include required dirs)
COPY --from=build-env /go/src/service/assets/ /assets/
# include vectortile-view-component webcomponent as asset
COPY --from=build-component /usr/src/app/dist/vectortile-view-component/styles.css /assets/vectortile-view-component/styles.css
COPY --from=build-component /usr/src/app/dist/vectortile-view-component/main.js /assets/vectortile-view-component/main.js
COPY --from=build-component /usr/src/app/dist/vectortile-view-component/polyfills.js /assets/vectortile-view-component/polyfills.js
COPY --from=build-component /usr/src/app/dist/vectortile-view-component/runtime.js /assets/vectortile-view-component/runtime.js
COPY --from=build-component /usr/src/app/dist/vectortile-view-component/3rdpartylicenses.txt /assets/vectortile-view-component/3rdpartylicenses.txt
COPY --from=build-env /go/src/service/engine/ /engine/
COPY --from=build-env /go/src/service/ogc/ /ogc/
# run as non-root
USER 1001
ENTRYPOINT ["gokoala"]