Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 1 | # Build stage |
| 2 | FROM golang:latest as build |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 3 | |
| 4 | RUN apt-get update && \ |
| 5 | apt-get upgrade -y ca-certificates |
| 6 | |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 7 | WORKDIR /src |
| 8 | |
| 9 | COPY go.mod go.sum ./ |
| 10 | RUN go mod download |
| 11 | |
| 12 | COPY . /src |
| 13 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 14 | RUN CGO_ENABLED=0 go test . |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 15 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 16 | # Build static |
| 17 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ |
| 18 | go build -v \ |
| 19 | -ldflags "-extldflags '-static' -s -w" \ |
| 20 | --trimpath \ |
| 21 | -o /src/external-big . |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 22 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 23 | FROM gruebel/upx:latest as upx |
| 24 | |
| 25 | COPY --from=build /src/external-big /external-big |
| 26 | |
| 27 | # Compress the binary and copy it to final image |
| 28 | RUN upx --best --lzma -o /external /external-big |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 29 | |
| 30 | # Main stage |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 31 | FROM scratch AS final |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 32 | |
| 33 | WORKDIR / |
| 34 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 35 | EXPOSE 5722 |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 36 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 37 | COPY --from=build /etc/ssl/certs /etc/ssl/certs |
| 38 | COPY --from=build /src/templates /templates |
| 39 | COPY --from=build /src/i18n /i18n |
| 40 | COPY --from=upx /external /external |
| 41 | |
| 42 | ENTRYPOINT [ "/external" ] |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 43 | |
| 44 | LABEL maintainer="korap@ids-mannheim.de" |
| 45 | LABEL description="Docker Image for Kalamar-Plugin-ExternalResources, a frontend plugin to link texts to external resources" |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 46 | LABEL repository="https://github.com/KorAP/Kalamar-Plugin-ExternalResources" |
Akron | f09fc56 | 2023-01-11 08:47:21 +0100 | [diff] [blame] | 47 | |
Akron | 23711ef | 2024-03-15 11:26:28 +0100 | [diff] [blame] | 48 | # docker build -f Dockerfile -t korap/kalamar-plugin-externalresources:latest . |
| 49 | # docker run --rm --network host -v ${PWD}/db/:/db/:z -v ${PWD}/.env:/.env korap/kalamar-plugin-externalresources:latest |