Skip to content

Commit 652e1c4

Browse files
committed
Working frontend with docker
1 parent 5718a35 commit 652e1c4

File tree

8 files changed

+69
-62
lines changed

8 files changed

+69
-62
lines changed

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"_copy_without_render": [
4848
"frontend/**/*.html",
4949
"frontend/**/*.tsx",
50+
"frontend/**/*.ico",
5051
"frontend/.next/*",
5152
"frontend/node_modules/*",
5253
"backend/app/app/email-templates/**"

{{cookiecutter.project_slug}}/docker-compose.override.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ services:
7171

7272
frontend:
7373
ports:
74-
- "24678:24678"
75-
volumes:
76-
# https://stackoverflow.com/a/32785014
77-
- ./frontend:/frontend
78-
- node_modules:/frontend/node_modules
74+
- "3000:3000"
7975
build:
8076
context: ./frontend
81-
target: run-dev
77+
target: runner
8278
labels:
8379
- traefik.enable=true
8480
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}

{{cookiecutter.project_slug}}/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ services:
170170
image: "${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}"
171171
env_file:
172172
- .env
173-
- ./frontend/.env
173+
- ./frontend/.env.local
174174
build:
175175
context: ./frontend
176176
deploy:
Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,62 @@
1-
FROM node:18.17 AS build
2-
ENV NODE_ENV=development APP_ENV=development
3-
# ENV PATH /frontend/node_modules/.bin:$PATH
4-
COPY . /frontend
1+
FROM node:18-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
57
WORKDIR /frontend
6-
RUN yarn install --frozen-lockfile --network-timeout 100000 --non-interactive
7-
RUN yarn build --standalone
8-
EXPOSE ${NUXT_PORT}
9-
10-
FROM build AS run-dev
11-
# ENTRYPOINT ["yarn"]
12-
CMD ["yarn", "dev"]
13-
14-
FROM build AS run-start
15-
ENV NODE_ENV=production APP_ENV=production
16-
ENTRYPOINT ["yarn"]
17-
CMD ["start"]
18-
19-
FROM node:18.17-alpine AS run-minimal
20-
# ARG NEXT_VERSION=^13.5.4
21-
# ARG TAILWINDCSS_VERSION=^4.0.0
22-
# ARG AUTOPREFIXER_VERSION=^10.4.13
23-
# ARG POSTCSS_VERSION=^8.4.18
24-
# ARG ASPECT_RATIO_VERSION=^0.4.2
25-
# ARG FORMS_VERSION=^0.5.3
26-
# ARG TYPOGRAPHY_VERSION=^0.5.7
27-
# ARG HEADLESSUI_VERSION=^1.7.3
28-
# ARG HEROICONS_VERSION=^2.0.12
29-
# ENV NODE_ENV=production APP_ENV=production
30-
# WORKDIR /frontend
31-
RUN yarn install
32-
# nuxt@${NUXT_VERSION} @nuxt/content@${NUXT_CONTENT_VERSION} tailwindcss@${TAILWINDCSS_VERSION} autoprefixer@${AUTOPREFIXER_VERSION} postcss@${POSTCSS_VERSION} @tailwindcss/aspect-ratio@${ASPECT_RATIO_VERSION} @tailwindcss/forms@${FORMS_VERSION} @tailwindcss/typography@${TYPOGRAPHY_VERSION} @headlessui/vue@${HEADLESSUI_VERSION} @heroicons/vue@${HEROICONS_VERSION} @pinia/nuxt@${PINIA_VERSION} @pinia-plugin-persistedstate/nuxt${PINIA_PERSISTED_VERSION} vee-validate@${VEE_VERSION} @vee-validate/i18n${VEE_INT_VERSION} @vee-validate/rules${VEE_RULES_VERSION} qrcode.vue${QR_CODE_VERSION} @nuxtjs/i18n${I18N_VERSION} @nuxtjs/robots${NUXT_ROBOTS_VERSION} @vite-pwa/nuxt${VITE_PWA_NUXT_VERSION}
33-
# COPY --from=build /app/.next ./.next
34-
# COPY --from=build /app/app/api ./api
35-
# COPY --from=build /app/app/assets ./assets
36-
# COPY --from=build /app/app/components ./components
37-
# COPY --from=build /app/app/config ./config
38-
# COPY --from=build /app/app/content ./content
39-
# COPY --from=build /app/app/interfaces ./interfaces
40-
# COPY --from=build /app/app/layouts ./layouts
41-
# COPY --from=build /app/app/locales ./locales
42-
# COPY --from=build /app/app/middleware ./middleware
43-
# COPY --from=build /app/app/pages ./pages
44-
# COPY --from=build /app/app/plugins ./plugins
45-
# COPY --from=build /app/public ./public
46-
# COPY --from=build /app/app/static ./static
47-
# COPY --from=build /app/app/stores ./stores
48-
# COPY --from=build /app/app/utilities ./utilities
49-
# COPY --from=build /app/.env.local ./
50-
# COPY --from=build /app/next.config* ./
51-
# COPY --from=build /app/tailwind.config* ./
52-
# COPY --from=build /app/tsconfig.json ./
53-
ENTRYPOINT [ "yarn" ]
54-
CMD [ "start" ]
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11+
RUN \
12+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13+
elif [ -f package-lock.json ]; then npm ci; \
14+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
15+
else echo "Lockfile not found." && exit 1; \
16+
fi
17+
18+
# Rebuild the source code only when needed
19+
FROM base AS builder
20+
WORKDIR /frontend
21+
COPY --from=deps /frontend/node_modules ./node_modules
22+
COPY . .
23+
24+
# Next.js collects completely anonymous telemetry data about general usage.
25+
# Learn more here: https://nextjs.org/telemetry
26+
# Uncomment the following line in case you want to disable telemetry during the build.
27+
ENV NEXT_TELEMETRY_DISABLED 1
28+
29+
# If using npm comment out above and use below instead
30+
RUN npm run build
31+
32+
# Production image, copy all the files and run next
33+
FROM base AS runner
34+
WORKDIR /frontend
35+
36+
ENV NODE_ENV production
37+
# Uncomment the following line in case you want to disable telemetry during runtime.
38+
ENV NEXT_TELEMETRY_DISABLED 1
39+
40+
RUN addgroup --system --gid 1001 nodejs
41+
RUN adduser --system --uid 1001 nextjs
42+
43+
COPY --from=builder /frontend/public ./public
44+
45+
# Set the correct permission for prerender cache
46+
RUN mkdir .next
47+
RUN chown nextjs:nodejs .next
48+
49+
# Automatically leverage output traces to reduce image size
50+
# https://nextjs.org/docs/advanced-features/output-file-tracing
51+
COPY --from=builder --chown=nextjs:nodejs /frontend/.next/standalone ./
52+
COPY --from=builder --chown=nextjs:nodejs /frontend/.next/static ./.next/static
53+
54+
USER nextjs
55+
56+
EXPOSE 3000
57+
ENV PORT 3000
58+
59+
# set hostname to localhost
60+
ENV HOSTNAME "0.0.0.0"
61+
62+
CMD [ "node", "server.js" ]

{{cookiecutter.project_slug}}/frontend/app/lib/interfaces/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IKeyable {
2020
[key: string]: any | any[]
2121
}
2222

23-
export {
23+
export type {
2424
IKeyable,
2525
IUserProfile,
2626
IUserProfileUpdate,

{{cookiecutter.project_slug}}/frontend/app/lib/slices/authSlice.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
validateTOTPClaim,
2626
} from "./tokensSlice"
2727
import { PURGE, purgeStoredState } from "redux-persist"
28-
import { perstistor } from "../reduxProvider"
2928

3029
interface AuthState {
3130
id: string

{{cookiecutter.project_slug}}/frontend/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ module.exports = {
88
},
99
],
1010
},
11+
output: 'standalone'
1112
}

{{cookiecutter.project_slug}}/frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"dependencies": {
1212
"@headlessui/react": "^1.7.17",
1313
"@heroicons/react": "^2.0.18",
14+
"webpack": "latest",
15+
"redux": "latest",
1416
"@mdx-js/loader": "^2.3.0",
1517
"@mdx-js/react": "^2.3.0",
1618
"@next/mdx": "^13.5.3",

0 commit comments

Comments
 (0)