goshort/Dockerfile
Gustavo Maronato 949ea57dd9
Some checks failed
Build / build (push) Has been cancelled
I'm done
2023-08-24 22:03:58 -03:00

63 lines
1.4 KiB
Docker

# Load the golang image
FROM golang:1.21.0 as go-builder
# Then the node image
FROM node:20.5.0 as builder
# Copy golang into the node image
COPY --from=go-builder /usr/local/go /usr/local/go
# Now our base image is ready.
# Continue as normal
WORKDIR /go/src/app
# Set our build environment
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
ENV GOCACHE=/tmp/.go-build-cache
# This variable communicates to the service that it's running inside
# a docker container.
ENV ENV_DOCKER=true
# Copy dockerignore files
COPY .dockerignore ./
# Install go deps using the cache
COPY go.mod go.sum Makefile ./
RUN --mount=type=cache,target=/go/pkg/mod/ \
go mod download -x
# Install node deps
COPY frontend/package.json frontend/package-lock.json frontend/
# Set npm cache to /tmp/.npm-cache
RUN npm config set cache /tmp/.npm-cache --global
RUN --mount=type=cache,target=/tmp/.npm-cache \
make install
# Build the frontend
COPY frontend frontend
RUN make frontend
# Build the backend
COPY . .
RUN --mount=type=cache,target=/tmp/.go-build-cache \
make backend
# Now create a new image with just the binary
FROM gcr.io/distroless/static-debian11:nonroot
WORKDIR /app
# Set our runtime environment
ENV ENV_DOCKER=true
ENV GOSHORT_PROD=true
COPY --from=builder /go/src/app/goshort /usr/local/bin/goshort
HEALTHCHECK CMD [ "goshort", "healthcheck" ]
EXPOSE 8080
ENTRYPOINT [ "goshort" ]
CMD [ "serve" ]