Skip to content

Commit ee9cc3b

Browse files
authored
chore: create dockerfile (#6)
* chore: create dockerfile * leftover * chore: use pinned pnpm version * chore: node version 22 * chore: add makefile * leftover * chore: add docker image tag to makefile
1 parent 3664131 commit ee9cc3b

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
README.md
6+
.next
7+
.git
8+
.gitignore
9+
.vscode
10+
.idea
11+
*.md
12+
.DS_Store
13+
.env*.local
14+
coverage
15+
.vercel
16+

Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM node:22-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+
8+
# Install pnpm
9+
RUN corepack enable && corepack prepare [email protected] --activate
10+
11+
WORKDIR /app
12+
13+
# Install dependencies based on the preferred package manager
14+
COPY package.json pnpm-lock.yaml* ./
15+
RUN pnpm install --frozen-lockfile
16+
17+
# Rebuild the source code only when needed
18+
FROM base AS builder
19+
20+
# Install pnpm
21+
RUN corepack enable && corepack prepare [email protected] --activate
22+
23+
WORKDIR /app
24+
COPY --from=deps /app/node_modules ./node_modules
25+
COPY . .
26+
27+
# Next.js collects completely anonymous telemetry data about general usage.
28+
# Learn more here: https://nextjs.org/telemetry
29+
# Uncomment the following line in case you want to disable telemetry during the build.
30+
# ENV NEXT_TELEMETRY_DISABLED=1
31+
32+
RUN pnpm build
33+
34+
# Production image, copy all the files and run next
35+
FROM base AS runner
36+
WORKDIR /app
37+
38+
ENV NODE_ENV=production
39+
# Uncomment the following line in case you want to disable telemetry during runtime.
40+
# ENV NEXT_TELEMETRY_DISABLED=1
41+
42+
RUN addgroup --system --gid 1001 nodejs
43+
RUN adduser --system --uid 1001 nextjs
44+
45+
COPY --from=builder /app/public ./public
46+
47+
# Set the correct permission for prerender cache
48+
RUN mkdir .next
49+
RUN chown nextjs:nodejs .next
50+
51+
# Automatically leverage output traces to reduce image size
52+
# https://nextjs.org/docs/advanced-features/output-file-tracing
53+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
54+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
55+
56+
USER nextjs
57+
58+
EXPOSE 3000
59+
60+
ENV PORT=3000
61+
62+
# server.js is created by next build from the standalone output
63+
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
64+
ENV HOSTNAME="0.0.0.0"
65+
CMD ["node", "server.js"]

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.PHONY: help build start stop restart logs clean dev shell rebuild
2+
3+
# Variables
4+
IMAGE_NAME := toolhive-cloud-ui
5+
IMAGE_TAG := latest
6+
CONTAINER_NAME := toolhive-cloud-ui
7+
PORT := 3000
8+
9+
## Show this help message
10+
help:
11+
@echo "Available commands:"
12+
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## //' | awk 'NR%2==1{printf "\033[36m%-15s\033[0m ",$$1} NR%2==0{print}'
13+
14+
## Build the production docker image
15+
build:
16+
@echo "Building ${IMAGE_NAME}:${IMAGE_TAG} Docker image..."
17+
@docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
18+
19+
## Start the production docker container
20+
start:
21+
@docker run -d -p $(PORT):$(PORT) --name $(CONTAINER_NAME) $(IMAGE_NAME):$(IMAGE_TAG)
22+
@echo "Container $(CONTAINER_NAME) running at http://localhost:$(PORT)"
23+
24+
## Stop the production docker container
25+
stop:
26+
@docker stop $(CONTAINER_NAME) > /dev/null 2>&1 || true
27+
@docker rm $(CONTAINER_NAME) > /dev/null 2>&1 || true
28+
@echo "Container $(CONTAINER_NAME) stopped"
29+
30+
## Restart the production docker container
31+
restart: stop start
32+
33+
## Show container logs (follow mode)
34+
logs:
35+
docker logs -f $(CONTAINER_NAME)
36+
37+
## Remove container and image
38+
clean: stop
39+
@docker rmi $(IMAGE_NAME):$(IMAGE_TAG) > /dev/null 2>&1 || true
40+
@echo "Cleanup complete"
41+
42+
## Run development server locally
43+
dev:
44+
pnpm dev
45+
46+
## Open shell in running container
47+
shell:
48+
docker exec -it $(CONTAINER_NAME) /bin/sh
49+
50+
## Clean and rebuild image
51+
rebuild: clean build
52+
@echo "Rebuild complete"
53+

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
2020

2121
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.
2222

23+
## Docker
24+
25+
This project includes Docker support for containerized deployments.
26+
27+
### Using Makefile (Recommended)
28+
29+
```bash
30+
# Show all available commands
31+
make help
32+
33+
# Build Docker image
34+
make build
35+
36+
# Start container
37+
make start
38+
39+
# View logs
40+
make logs
41+
42+
# Stop container
43+
make stop
44+
45+
# Clean up (remove container and image)
46+
make clean
47+
48+
# Rebuild from scratch
49+
make rebuild
50+
51+
The application will be available at [http://localhost:3000](http://localhost:3000).
52+
2353
## Learn More
2454

2555
To learn more about Next.js, take a look at the following resources:

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { NextConfig } from "next";
33
const nextConfig: NextConfig = {
44
/* config options here */
55
reactCompiler: true,
6+
output: "standalone",
67
};
78

89
export default nextConfig;

0 commit comments

Comments
 (0)