2023-08-30 10:54:46 -03:00
|
|
|
# Load nodego image
|
|
|
|
FROM maronato/nodego:1.0 as builder
|
2023-08-21 22:48:33 -03:00
|
|
|
|
2023-09-06 13:30:45 -03:00
|
|
|
RUN apk add --no-cache make
|
|
|
|
|
|
|
|
ARG VERSION=undefined
|
|
|
|
|
2023-08-21 22:48:33 -03:00
|
|
|
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
|
2023-08-24 22:44:03 -03:00
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN --mount=type=cache,target=/tmp/.go-build-cache \
|
2023-08-21 22:48:33 -03:00
|
|
|
go mod download -x
|
|
|
|
|
|
|
|
# Install node deps
|
|
|
|
COPY frontend/package.json frontend/package-lock.json frontend/
|
|
|
|
RUN npm config set cache /tmp/.npm-cache --global
|
|
|
|
RUN --mount=type=cache,target=/tmp/.npm-cache \
|
2023-08-30 10:54:46 -03:00
|
|
|
npm ci --prefix frontend
|
2023-08-21 22:48:33 -03:00
|
|
|
|
2023-09-06 13:30:45 -03:00
|
|
|
COPY Makefile ./
|
|
|
|
|
2023-08-21 22:48:33 -03:00
|
|
|
# Build the frontend
|
|
|
|
COPY frontend frontend
|
2023-08-30 10:54:46 -03:00
|
|
|
RUN VITE_API_URL=/api npm run --prefix frontend build
|
2023-08-21 22:48:33 -03:00
|
|
|
|
2023-08-24 22:44:03 -03:00
|
|
|
# Build backend
|
|
|
|
COPY goshort.go ./
|
|
|
|
COPY cmd cmd
|
|
|
|
COPY internal internal
|
2023-08-30 22:30:42 -03:00
|
|
|
COPY docs docs
|
2023-08-24 22:44:03 -03:00
|
|
|
|
2023-08-21 22:48:33 -03:00
|
|
|
# Build the backend
|
|
|
|
RUN --mount=type=cache,target=/tmp/.go-build-cache \
|
2023-09-06 13:30:45 -03:00
|
|
|
make backend VERSION=$VERSION
|
2023-08-21 22:48:33 -03:00
|
|
|
|
|
|
|
# Now create a new image with just the binary
|
|
|
|
FROM gcr.io/distroless/static-debian11:nonroot
|
|
|
|
|
2023-08-22 01:53:05 -03:00
|
|
|
WORKDIR /app
|
|
|
|
|
2023-08-21 22:48:33 -03:00
|
|
|
# Set our runtime environment
|
|
|
|
ENV ENV_DOCKER=true
|
2023-08-24 22:03:58 -03:00
|
|
|
ENV GOSHORT_PROD=true
|
2023-08-21 22:48:33 -03:00
|
|
|
|
|
|
|
COPY --from=builder /go/src/app/goshort /usr/local/bin/goshort
|
|
|
|
|
|
|
|
HEALTHCHECK CMD [ "goshort", "healthcheck" ]
|
|
|
|
|
2023-08-24 22:03:58 -03:00
|
|
|
EXPOSE 8080
|
|
|
|
|
2023-08-21 22:48:33 -03:00
|
|
|
ENTRYPOINT [ "goshort" ]
|
|
|
|
CMD [ "serve" ]
|