FROM node:16.11.1-alpine3.13

WORKDIR /usr/src/app

ENV PORT=3000
EXPOSE 3000

# hadolint ignore=DL3018
RUN apk add --no-cache \
	#  Needed for healthchecks
	curl \
	# Needed to use Google Cloud Profiler
	ca-certificates \
	# Needed to use compile Prisma on arm64
	openssl libc6-compat \
	# Needed to compile pprof
	python3 make g++

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD curl -X GET --fail http://localhost:3000/health || exit 1

COPY package.json yarn.lock .yarnrc.yml tsconfig.json ./
COPY prisma ./prisma
COPY .yarn ./.yarn

# hadolint ignore=DL3060
RUN yarn install --immutable \
	&& yarn prisma generate

COPY src ./src
COPY types ./types

RUN yarn build

RUN yarn workspaces focus --all --production \
	&& yarn cache clean \
	&& rm -r src types tsconfig.json

# Remove these since they are only needed to compile dependencies
RUN apk del openssl libc6-compat python3 make g++

CMD ["yarn", "start"]
