-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (50 loc) · 2.06 KB
/
Dockerfile
File metadata and controls
55 lines (50 loc) · 2.06 KB
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
#syntax=docker/dockerfile:1.4
ARG NODE_VERSION="18.20.8"
ARG ALPINE_VERSION="3.21"
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
RUN apk update && apk upgrade --no-cache
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