forked from evroon/bracket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
FROM node:18-alpine | ||
# Install dependencies only when needed | ||
FROM node:18-alpine AS deps | ||
|
||
COPY . /app | ||
WORKDIR /app | ||
|
||
RUN cd /app \ | ||
&& yarn \ | ||
&& yarn next telemetry disable \ | ||
&& yarn next build | ||
COPY package.json yarn.lock ./ | ||
|
||
CMD yarn start | ||
RUN yarn | ||
|
||
# Rebuild the source code only when needed | ||
FROM node:18-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
COPY --from=deps /app/node_modules ./node_modules | ||
|
||
RUN NEXT_PUBLIC_API_BASE_URL="APP_PLACEHOLDER_NEXT_PUBLIC_API_BASE_URL" NEXT_PUBLIC_HCAPTCHA_SITE_KEY="APP_PLACEHOLDER_NEXT_PUBLIC_HCAPTCHA_SITE_KEY" yarn build | ||
|
||
# Production image, copy all the files and run next | ||
FROM node:18-alpine AS runner | ||
|
||
WORKDIR /app | ||
|
||
ENV NODE_ENV production | ||
|
||
COPY --from=builder /app/public ./public | ||
COPY --from=builder /app/.next ./.next | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/package.json ./package.json | ||
COPY --from=builder /app/docker-entrypoint.sh ./entrypoint.sh | ||
|
||
RUN addgroup -g 1001 -S nodejs && \ | ||
adduser -S nextjs -u 1001 -G nodejs && \ | ||
chown -R nextjs:nodejs /app/.next && \ | ||
chmod +x /app/entrypoint.sh | ||
|
||
RUN yarn next telemetry disable | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENTRYPOINT ["/app/entrypoint.sh"] | ||
|
||
CMD yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
echo "Check that we have NEXT_PUBLIC_API_BASE_URL, NEXT_PUBLIC_HCAPTCHA_SITE_KEY vars" | ||
test -n "$NEXT_PUBLIC_API_BASE_URL" | ||
test -n "$NEXT_PUBLIC_HCAPTCHA_SITE_KEY" | ||
|
||
find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_PLACEHOLDER_NEXT_PUBLIC_API_BASE_URL#$NEXT_PUBLIC_API_BASE_URL#g" # Replace NEXT_PUBLIC_API_BASE_URL | ||
|
||
find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_PLACEHOLDER_NEXT_PUBLIC_HCAPTCHA_SITE_KEY#$NEXT_PUBLIC_HCAPTCHA_SITE_KEY#g" # Replace NEXT_PUBLIC_HCAPTCHA_SITE_KEY | ||
|
||
echo "Starting Nextjs" | ||
exec "$@" |