blob: 4012f44cf161ae20c206c15e65dc78db859e2367 [file] [log] [blame]
Akron50d5f832025-06-06 15:08:04 +02001# Build stage
2FROM golang:latest AS build
3
4RUN apt-get update && \
5 apt-get upgrade -y ca-certificates
6
7WORKDIR /src
8
9COPY go.mod go.sum ./
10RUN go mod download
11
12COPY . /src
13
14RUN CGO_ENABLED=0 go test ./...
15
Akronf22317d2026-02-25 11:37:59 +010016ARG BUILDDATE="[unset]"
17ARG BUILDCOMMIT="[unset]"
18ARG BUILDVERSION="EARLY"
19
Akron50d5f832025-06-06 15:08:04 +020020# Build static
21RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
22 go build -v \
Akronf22317d2026-02-25 11:37:59 +010023 -ldflags "-X github.com/KorAP/Koral-Mapper/config.Buildtime=${BUILDDATE} -X github.com/KorAP/Koral-Mapper/config.Buildhash=${BUILDCOMMIT} -X github.com/KorAP/Koral-Mapper/config.Version=${BUILDVERSION} -extldflags '-static' -s -w" \
Akron50d5f832025-06-06 15:08:04 +020024 --trimpath \
Akron2ef703c2025-07-03 15:57:42 +020025 -o /src/koralmapper ./cmd/koralmapper/
Akron50d5f832025-06-06 15:08:04 +020026
27FROM gruebel/upx:latest AS upx
28
Akron2ef703c2025-07-03 15:57:42 +020029COPY --from=build /src/koralmapper /koralmapper-big
Akron50d5f832025-06-06 15:08:04 +020030
31# Compress the binary and copy it to final image
Akron2ef703c2025-07-03 15:57:42 +020032RUN upx --best --lzma -o /koralmapper /koralmapper-big
Akron50d5f832025-06-06 15:08:04 +020033
34# Main stage
35FROM scratch AS final
36
37WORKDIR /
38
39EXPOSE 5725
40
Akronf22317d2026-02-25 11:37:59 +010041ARG BUILDVERSION="EARLY"
42ARG BUILDCOMMIT="[unset]"
43ARG BUILDDATE="1970-01-01T00:00:00Z"
44
Akron50d5f832025-06-06 15:08:04 +020045COPY --from=build /etc/ssl/certs /etc/ssl/certs
46COPY --from=build /src/mappings /mappings
Akron2ef703c2025-07-03 15:57:42 +020047COPY --from=upx /koralmapper /koralmapper
Akron50d5f832025-06-06 15:08:04 +020048
Akron8f1bef92025-07-04 14:54:02 +020049ENTRYPOINT [ "/koralmapper" ]
Akron50d5f832025-06-06 15:08:04 +020050
51LABEL maintainer="korap@ids-mannheim.de"
Akron2ef703c2025-07-03 15:57:42 +020052LABEL description="Docker Image for Koral-Mapper"
53LABEL repository="https://github.com/KorAP/Koral-Mapper"
Akronf22317d2026-02-25 11:37:59 +010054LABEL org.opencontainers.image.title="Koral-Mapper"
55LABEL org.opencontainers.image.description="Docker Image for Koral-Mapper"
56LABEL org.opencontainers.image.url="https://github.com/KorAP/Koral-Mapper"
57LABEL org.opencontainers.image.source="https://github.com/KorAP/Koral-Mapper"
58LABEL org.opencontainers.image.created="${BUILDDATE}"
59LABEL org.opencontainers.image.revision="${BUILDCOMMIT}"
60LABEL org.opencontainers.image.version="${BUILDVERSION}"
Akron50d5f832025-06-06 15:08:04 +020061
Akron2ef703c2025-07-03 15:57:42 +020062# docker build -f Dockerfile -t korap/koral-mapper:latest .
63# docker run --rm --network host korap/koral-mapper:latest -m /mappings/*.yaml
64# docker save -o korap-koral-mapper-latest.tar korap/koral-mapper:latest