Skip to content

Commit 0aa7517

Browse files
authored
Merge pull request #540 from benjamin-747/main
update docker file from nextjs example, fix build err
2 parents c0cca16 + e8af676 commit 0aa7517

12 files changed

Lines changed: 71 additions & 17 deletions

File tree

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ docker network create mono-network
4040
# run postgres
4141
docker run --rm -it -d --name mono-pg --network mono-network -v /mnt/data/mono/pg-data:/var/lib/postgresql/data -p 5432:5432 mono-pg:0.1-pre-release
4242
docker run --rm -it -d --name mono-engine --network mono-network -v /mnt/data/mono/mono-data:/opt/mega -p 8000:8000 -p 22:9000 mono-engine:0.1-pre-release
43-
docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_HOST=http://mono-engine:8000 -e MOON_HOST=http://localhost:3000 -p 3000:3000 mono-ui:0.1-pre-release
43+
docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_HOST=http://git.gitmono.com -e MOON_HOST=https://console.gitmono.com -p 3000:3000 mono-ui:0.1-pre-release
4444
```

docker/mono-ui-dockerfile

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,66 @@
1-
FROM node:22-alpine
1+
## exmaple: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
2+
FROM node:20-alpine AS base
23

4+
# Install dependencies only when needed
5+
FROM base AS deps
6+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7+
RUN apk add --no-cache libc6-compat
38
WORKDIR /app
49

510
# set mirror for npm
611
# RUN npm config set registry https://registry.npmmirror.com
712

13+
# Install dependencies based on the preferred package manager
814
COPY ./moon/package*.json ./
9-
1015
RUN npm install
1116

17+
18+
# Rebuild the source code only when needed
19+
FROM base AS builder
20+
WORKDIR /app
21+
COPY --from=deps /app/node_modules ./node_modules
1222
COPY ./moon .
1323

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+
1429
RUN npm run build
1530

31+
# Production image, copy all the files and run next
32+
FROM base AS runner
33+
WORKDIR /app
34+
35+
ENV NODE_ENV=production
36+
# Uncomment the following line in case you want to disable telemetry during runtime.
37+
ENV NEXT_TELEMETRY_DISABLED=1
38+
39+
RUN addgroup --system --gid 1001 nodejs
40+
RUN adduser --system --uid 1001 nextjs
41+
42+
COPY --from=builder /app/public ./public
43+
1644
COPY ./docker/start-moon.sh /app/start-moon.sh
1745

1846
RUN chmod +x /app/start-moon.sh
1947

48+
# Set the correct permission for prerender cache
49+
RUN mkdir .next
50+
RUN chown nextjs:nodejs .next
51+
52+
# Automatically leverage output traces to reduce image size
53+
# https://nextjs.org/docs/advanced-features/output-file-tracing
54+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
55+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
56+
57+
USER nextjs
58+
2059
EXPOSE 3000
2160

61+
ENV PORT=3000
62+
63+
# server.js is created by next build from the standalone output
64+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
65+
ENV HOSTNAME="0.0.0.0"
2266
ENTRYPOINT ["/bin/sh", "/app/start-moon.sh"]

docker/start-moon.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
#!/bin/bash
22

3-
# TODO: run `npm run s start` didn't work, use `npm run dev` temporarily
4-
exec npm run start
3+
# user must set the NEXT_PUBLIC_API_URL
4+
if [ -z "$MEGA_HOST" ]; then
5+
echo "MEGA_HOST is not set"
6+
exit 1
7+
fi
8+
9+
if [ -z "$MOON_HOST" ]; then
10+
echo "MOON_HOST is not set"
11+
exit 1
12+
fi
13+
14+
exec node server.js

moon/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @type {import('next').NextConfig} */
22

33
const nextConfig = {
4+
output: "standalone",
45
images: {
56
remotePatterns: [
67
{

moon/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
"dependencies": {
1212
"@ant-design/icons": "^5.4.0",
13-
"@ant-design/nextjs-registry": "^1.0.0",
14-
"@headlessui/react": "^2.1.2",
13+
"@ant-design/nextjs-registry": "^1.0.1",
14+
"@headlessui/react": "^2.1.3",
1515
"@headlessui/tailwindcss": "^0.2.1",
1616
"@heroicons/react": "^2.1.5",
1717
"@lexical/react": "^0.17.0",
@@ -22,7 +22,7 @@
2222
"github-markdown-css": "^5.6.1",
2323
"highlight.js": "^11.10.0",
2424
"lexical": "^0.17.0",
25-
"next": "^14.2.5",
25+
"next": "^14.2.6",
2626
"prism-react-renderer": "^2.3.1",
2727
"react": "^18.3.1",
2828
"react-dom": "^18.3.1",

moon/src/app/application-layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function ApplicationLayout({
101101
fetchMessage();
102102
}
103103
async function fetchMessage() {
104-
const response = await fetch('http://localhost:3000/api/auth/github/user');
104+
const response = await fetch('/api/auth/github/user');
105105
const user = await response.json();
106106
setUser(user.data);
107107
}

moon/src/app/auth/github/callback/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function AuthPage({ searchParams }) {
1515
useEffect(() => {
1616
async function fetchData() {
1717
try {
18-
const res = await fetch(`http://localhost:3000/api/env`);
18+
const res = await fetch(`/api/env`);
1919
if (!res.ok) {
2020
throw new Error('Failed to fetch data');
2121
}

moon/src/app/blob/[...path]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function BlobPage({ params }: { params: { path: string[] } }) {
2727
}
2828

2929
async function getReadmeContent(pathname: string) {
30-
const res = await fetch(`http://localhost:3000/api/blob?path=${pathname}`);
30+
const res = await fetch(`/api/blob?path=${pathname}`);
3131
const response = await res.json();
3232
const directory = response.data.data;
3333
return directory

moon/src/app/login/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use server'
2-
31
import Image from "next/image";
2+
export const revalidate = 0
43

54
export default async function Login() {
65
const res = await fetch(`http://localhost:3000/api/env`);

moon/src/app/mr/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function MRDetailPage( { params }: { params: { id: string } }) {
88
useEffect(() => {
99
const fetchData = async () => {
1010
try {
11-
const res = await fetch(`http://localhost:3000/api/mr/${params.id}/detail`);
11+
const res = await fetch(`/api/mr/${params.id}/detail`);
1212
const response = await res.json();
1313
const data = response.data.data;
1414
setMrDetail(data);

0 commit comments

Comments
 (0)