whatismyip/Dockerfile

29 lines
713 B
Docker
Raw Permalink Normal View History

FROM golang:1.23-alpine AS builder
2021-11-10 19:06:12 +00:00
ARG ARG_VERSION
ENV VERSION=$ARG_VERSION
2021-11-10 19:06:12 +00:00
WORKDIR /app
2024-04-12 17:26:48 +00:00
COPY go.mod .
COPY go.sum .
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download -x
2021-11-10 19:06:12 +00:00
COPY . .
2024-04-12 17:26:48 +00:00
FROM builder AS build-dev-app
# hadolint ignore=DL3018
RUN --mount=type=cache,target=/go/pkg/mod/ apk --no-cache add make && make build
2021-11-10 19:06:12 +00:00
2024-04-12 17:26:48 +00:00
FROM builder AS build-prod-app
# hadolint ignore=DL3018
RUN --mount=type=cache,target=/go/pkg/mod/ apk --no-cache add make upx \
&& make build \
&& upx --best --lzma whatismyip
2021-11-10 19:06:12 +00:00
2024-04-12 17:26:48 +00:00
FROM scratch AS dev
COPY --from=build-dev-app /app/whatismyip /usr/bin/
ENTRYPOINT ["whatismyip"]
2021-11-10 19:06:12 +00:00
2024-04-12 17:26:48 +00:00
FROM scratch AS prod
COPY --from=build-prod-app /app/whatismyip /usr/bin/
2021-11-10 19:06:12 +00:00
ENTRYPOINT ["whatismyip"]