Skip to content

Commit 36b0453

Browse files
author
Pau Tena
committed
Boilerplate and dockerize a NextJS app
1 parent 1999108 commit 36b0453

26 files changed

+6373
-4
lines changed

.env

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# This would be set to the production domain with an env var on deployment
33
# used by Traefik to transmit traffic and aqcuire TLS certificates
44
DOMAIN="op://Environments/My Full-Stack Template/$ENVIRONMENT/DOMAIN"
5-
# To test the local Traefik config
6-
# DOMAIN=localhost.tiangolo.com
75

86
# Used by the backend to generate links in emails to the frontend
97
FRONTEND_HOST="op://Environments/My Full-Stack Template/$ENVIRONMENT/FRONTEND_HOST"

docker-compose.override.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ services:
103103
args:
104104
- VITE_API_URL=http://localhost:8000
105105
- NODE_ENV=development
106-
106+
next:
107+
build:
108+
context: ./next
109+
dockerfile: Dockerfile.dev
107110
playwright:
108111
build:
109112
context: ./frontend

docker-compose.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
services:
2-
32
db:
43
image: postgres:12
54
restart: always
@@ -158,6 +157,36 @@ services:
158157

159158
# Enable redirection for HTTP and HTTPS
160159
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect
160+
next:
161+
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}-next:${TAG-latest}'
162+
restart: always
163+
networks:
164+
- traefik-public
165+
- default
166+
build:
167+
context: ./next
168+
args:
169+
- VITE_API_URL=https://api.${DOMAIN?Variable not set}
170+
- NODE_ENV=production
171+
ports:
172+
- "3000:3000"
173+
labels:
174+
- traefik.enable=true
175+
- traefik.docker.network=traefik-public
176+
- traefik.constraint-label=traefik-public
177+
178+
- traefik.http.services.${STACK_NAME?Variable not set}-next-frontend.loadbalancer.server.port=3000
179+
180+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-http.rule=Host(`${DOMAIN?Variable not set}`)
181+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-http.entrypoints=http
182+
183+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-https.rule=Host(`${DOMAIN?Variable not set}`)
184+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-https.entrypoints=https
185+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-https.tls=true
186+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-https.tls.certresolver=le
187+
188+
# Enable redirection for HTTP and HTTPS
189+
- traefik.http.routers.${STACK_NAME?Variable not set}-next-frontend-http.middlewares=https-redirect
161190
volumes:
162191
app-db-data:
163192

next/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
npm-debug.log
3+
dist
4+
.next
5+
.DS_Store
6+
.env
7+
.git

next/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

next/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Use the official Node.js image as the base image
2+
FROM node:20-alpine
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json to the container
8+
COPY package*.json /app/
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application files
14+
COPY ./ /app/
15+
16+
# Build the Next.js application
17+
RUN npm run build
18+
19+
# Expose the application on port 4000
20+
EXPOSE 3000
21+
22+
# Start the application
23+
CMD ["npm", "start"]

next/Dockerfile.dev

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use the official Node.js image as the base image
2+
FROM node:20-alpine
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json to the container
8+
COPY package*.json /app/
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application files
14+
COPY ./ /app/
15+
16+
# Expose the application on port 4000
17+
EXPOSE 3000
18+
19+
# Start the application
20+
CMD ["npm", "run", "dev"]

next/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

next/app/favicon.ico

25.3 KB
Binary file not shown.

next/app/globals.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
--background: #ffffff;
7+
--foreground: #171717;
8+
}
9+
10+
@media (prefers-color-scheme: dark) {
11+
:root {
12+
--background: #0a0a0a;
13+
--foreground: #ededed;
14+
}
15+
}
16+
17+
body {
18+
color: var(--foreground);
19+
background: var(--background);
20+
font-family: Arial, Helvetica, sans-serif;
21+
}

0 commit comments

Comments
 (0)