Fix Dockerfile
Change-Id: Ia9b5d3739f6a95a1e633a433cf4bedc4948a7619
diff --git a/Dockerfile b/Dockerfile
index 888f40e..7b2d1d1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,9 @@
# Build stage
FROM golang:latest as build
+
+RUN apt-get update && \
+ apt-get upgrade -y ca-certificates
+
WORKDIR /src
COPY go.mod go.sum ./
@@ -7,31 +11,39 @@
COPY . /src
-RUN apt-get update && \
- apt-get upgrade -y ca-certificates
+RUN CGO_ENABLED=0 go test .
-RUN go test .
+# Build static
+RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
+ go build -v \
+ -ldflags "-extldflags '-static' -s -w" \
+ --trimpath \
+ -o /src/external-big .
-RUN STATIC="-extldflags '-static'" \
- STATICENV="CGO_ENABLED=0 GOOS=linux GOARCH=amd64" \
- go build -o /src/kalamar-plugin-externalresources .
+FROM gruebel/upx:latest as upx
+
+COPY --from=build /src/external-big /external-big
+
+# Compress the binary and copy it to final image
+RUN upx --best --lzma -o /external /external-big
# Main stage
-FROM busybox:glibc
-
-EXPOSE 5722
+FROM scratch AS final
WORKDIR /
-COPY --from=build /etc/ssl/certs /etc/ssl/certs
-COPY --from=build /src/kalamar-plugin-externalresources /kalamar-plugin-externalresources
-COPY --from=build /src/templates /templates
+EXPOSE 5722
-ENTRYPOINT [ "./kalamar-plugin-externalresources" ]
+COPY --from=build /etc/ssl/certs /etc/ssl/certs
+COPY --from=build /src/templates /templates
+COPY --from=build /src/i18n /i18n
+COPY --from=upx /external /external
+
+ENTRYPOINT [ "/external" ]
LABEL maintainer="korap@ids-mannheim.de"
LABEL description="Docker Image for Kalamar-Plugin-ExternalResources, a frontend plugin to link texts to external resources"
-LABEL repository="https://github.com/KorAP/..."
+LABEL repository="https://github.com/KorAP/Kalamar-Plugin-ExternalResources"
-# docker build -f Dockerfile -t korap/kalamar-plugin-externalresources .
-# docker run --rm --network host -v ${PWD}/db/:/db/:z -v ${PWD}/.env:/.env korap/kalamar-plugin-externalresources
\ No newline at end of file
+# docker build -f Dockerfile -t korap/kalamar-plugin-externalresources:latest .
+# docker run --rm --network host -v ${PWD}/db/:/db/:z -v ${PWD}/.env:/.env korap/kalamar-plugin-externalresources:latest
\ No newline at end of file