-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile
58 lines (53 loc) · 2.19 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#syntax=docker/dockerfile:1.4
ARG NODE_VERSION="18.15.0"
ARG ALPINE_VERSION="3.17"
FROM --platform=linux/amd64 node:${NODE_VERSION}-alpine${ALPINE_VERSION} as base
ENV CI=true
# for turbo - https://turbo.build/repo/docs/handbook/deploying-with-docker#example
RUN apk add --no-cache libc6-compat curl
# @todo - remove this after upgrading prisma to ~4.8.0
# https://github.com/prisma/prisma/issues/16553#issuecomment-1353302617
RUN apk add --no-cache openssl1.1-compat
RUN apk update
WORKDIR /workspace
# enable corepack for pnpm
RUN corepack enable
FROM base as fetcher
# pnpm fetch only requires lockfile, but we'll need to build workspaces
COPY pnpm*.yaml ./
# mount pnpm store as cache & fetch dependencies
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm-store \
pnpm fetch --ignore-scripts
FROM fetcher as builder
ARG APP_NAME="@aws-amplify/discord-bot-frontend"
ENV APP_NAME=${APP_NAME}
# expose arguments for VITE environment variables
ARG VITE_HOST=http://localhost:3000
ARG VITE_NEXTAUTH_URL=http://localhost:3000
ARG VITE_DISCORD_GUILD_ID=976838371383083068
WORKDIR /workspace
COPY . .
RUN --mount=type=secret,id=env,required=false,target=/workspace/.env \
pnpm install --frozen-lockfile --offline --loglevel=error
# build workspace
RUN --mount=type=secret,id=env,required=false,target=/workspace/.env \
--mount=type=cache,target=/workspace/node_modules/.cache \
pnpm run build
FROM builder as deployer
WORKDIR /workspace
# deploy app
RUN pnpm --filter ${APP_NAME} deploy --prod --ignore-scripts ./out
FROM base as runner
WORKDIR /workspace
# Don't run production as root
RUN addgroup --system --gid 1001 amplifygroup
RUN adduser --system --uid 1001 amplifyuser
USER amplifyuser
# copy files needed to run the app
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/package.json .
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/scripts/start.sh ./scripts/start.sh
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/prisma ./prisma
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/node_modules/ ./node_modules
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/build/ ./build
# start the app
CMD pnpm run start