Skip to content

Commit 5dfa78d

Browse files
committed
initial commit
0 parents commit 5dfa78d

File tree

14 files changed

+726
-0
lines changed

14 files changed

+726
-0
lines changed

.dockerignore

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

.gitattributes

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
*.7z filter=lfs diff=lfs merge=lfs -text
2+
*.arrow filter=lfs diff=lfs merge=lfs -text
3+
*.bin filter=lfs diff=lfs merge=lfs -text
4+
*.bz2 filter=lfs diff=lfs merge=lfs -text
5+
*.ckpt filter=lfs diff=lfs merge=lfs -text
6+
*.ftz filter=lfs diff=lfs merge=lfs -text
7+
*.gz filter=lfs diff=lfs merge=lfs -text
8+
*.h5 filter=lfs diff=lfs merge=lfs -text
9+
*.joblib filter=lfs diff=lfs merge=lfs -text
10+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
11+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
12+
*.model filter=lfs diff=lfs merge=lfs -text
13+
*.msgpack filter=lfs diff=lfs merge=lfs -text
14+
*.npy filter=lfs diff=lfs merge=lfs -text
15+
*.npz filter=lfs diff=lfs merge=lfs -text
16+
*.onnx filter=lfs diff=lfs merge=lfs -text
17+
*.ot filter=lfs diff=lfs merge=lfs -text
18+
*.parquet filter=lfs diff=lfs merge=lfs -text
19+
*.pb filter=lfs diff=lfs merge=lfs -text
20+
*.pickle filter=lfs diff=lfs merge=lfs -text
21+
*.pkl filter=lfs diff=lfs merge=lfs -text
22+
*.pt filter=lfs diff=lfs merge=lfs -text
23+
*.pth filter=lfs diff=lfs merge=lfs -text
24+
*.rar filter=lfs diff=lfs merge=lfs -text
25+
*.safetensors filter=lfs diff=lfs merge=lfs -text
26+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27+
*.tar.* filter=lfs diff=lfs merge=lfs -text
28+
*.tflite filter=lfs diff=lfs merge=lfs -text
29+
*.tgz filter=lfs diff=lfs merge=lfs -text
30+
*.wasm filter=lfs diff=lfs merge=lfs -text
31+
*.xz filter=lfs diff=lfs merge=lfs -text
32+
*.zip filter=lfs diff=lfs merge=lfs -text
33+
*.zst filter=lfs diff=lfs merge=lfs -text
34+
*tfevents* filter=lfs diff=lfs merge=lfs -text

.gitignore

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

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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
7+
WORKDIR /app
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+
19+
# Rebuild the source code only when needed
20+
FROM base AS builder
21+
WORKDIR /app
22+
COPY --from=deps /app/node_modules ./node_modules
23+
COPY . .
24+
25+
# Next.js collects completely anonymous telemetry data about general usage.
26+
# Learn more here: https://nextjs.org/telemetry
27+
# Uncomment the following line in case you want to disable telemetry during the build.
28+
# ENV NEXT_TELEMETRY_DISABLED 1
29+
30+
# RUN yarn build
31+
32+
# If you use yarn, comment out this line and use the line above
33+
RUN npm run build
34+
35+
# Production image, copy all the files and run next
36+
FROM base AS runner
37+
WORKDIR /app
38+
39+
ENV NODE_ENV production
40+
# Uncomment the following line in case you want to disable telemetry during runtime.
41+
# ENV NEXT_TELEMETRY_DISABLED 1
42+
43+
RUN addgroup --system --gid 1001 nodejs
44+
RUN adduser --system --uid 1001 nextjs
45+
46+
COPY --from=builder /app/public ./public
47+
48+
# Automatically leverage output traces to reduce image size
49+
# https://nextjs.org/docs/advanced-features/output-file-tracing
50+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
51+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
52+
53+
USER nextjs
54+
55+
EXPOSE 3000
56+
57+
ENV PORT 3000
58+
59+
CMD ["node", "server.js"]

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Next.js Docker Starter
3+
emoji: 🐳🤘
4+
colorFrom: purple
5+
colorTo: blue
6+
sdk: docker
7+
pinned: false
8+
license: agpl-3.0
9+
app_port: 3000
10+
---
11+
12+
# nextjs-docker-starter
13+
14+
This example can be used to run [Next.js](https://nextjs.org/) using [Docker](https://huggingface.co/docs/hub/spaces-sdks-docker) in 🤗 [Spaces](https://huggingface.co/spaces).
15+
16+
## Development
17+
18+
1. Install the dependencies: `npm i`
19+
2. Start the local dev-server: `npm run dev`
20+
3. Open the app via [localhost:3000](http://localhost:3000)
21+
22+
## Use the Docker container locally
23+
24+
To make sure that everything is working out, you can run your container locally:
25+
26+
1. [Install Docker](https://docs.docker.com/get-docker/) on your machine
27+
2. Go into the `nextjs-docker-starter` folder
28+
3. Build your Docker image: `docker build -t nextjs-docker-starter .`.
29+
4. Run your Docker container: `docker run -p 3000:3000 nextjs-docker-starter`.
30+
5. Open the app via [localhost:3000](http://localhost:3000)
31+
32+
## Dockerize an existing project
33+
34+
To add support for Docker to an existing project, just copy the `Dockerfile` into the root of the project and add the following to the `next.config.js` file:
35+
36+
```js
37+
// next.config.js
38+
module.exports = {
39+
// ... rest of the configuration.
40+
output: "standalone",
41+
};
42+
```
43+
44+
This will build the project as a standalone app inside the Docker image.
45+
46+
## Manage your Space via GitHub
47+
48+
If you want to use all the features for collaborative development on GitHub, but keep your demo on Spaces, then you can setup a GitHub action that will automatically push changes from GitHub into Spaces.
49+
50+
https://huggingface.co/docs/hub/spaces-github-actions

next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
module.exports = {
3+
output: 'standalone',
4+
}

0 commit comments

Comments
 (0)