Skip to content

Commit

Permalink
added docker + README
Browse files Browse the repository at this point in the history
  • Loading branch information
EkkoKo committed Mar 31, 2023
1 parent 183f322 commit 3588b78
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 56 deletions.
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.env

Dockerfile
./**/*/Dockerfile

.dockerignore

node_modules
./**/*/node_modules

pnpm-debug.log
./**/*/pnpm-debug.log


README.md
.next
.git

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
18.15.0
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ No, it does not. The `api` package should only be a production dependency in the

If you need to share runtime code between the client and server, such as input validation schemas, you can create a separate `shared` package for this and import on both sides.

## Docker

To get it running with docker, follow the steps below:

Option 1:

1. Build and run the images with:

```bash
docker compose up --build
# You can specify a specific service: docker compose up nextjs --build
```

2. Visit `http://localhost:3000` to see your app.

Option 2:

1. Build the images

```bash
docker compose build
# You can specify a specific service: docker compose build nextjs
```

2. Run the images

```bash
docker compose up
# You can specify a specific service: docker compose up nextjs
```

3. Visit `http://localhost:3000` to see your app.

## Quick Start

To get it running, follow the steps below:
Expand Down
52 changes: 52 additions & 0 deletions apps/nextjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
##### DEPENDENCIES

FROM --platform=linux/amd64 node:18-alpine AS builder
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update
WORKDIR /app
RUN yarn global add turbo
COPY . .
RUN turbo prune --scope=@acme/nextjs --docker

FROM --platform=linux/amd64 node:18-alpine AS installer
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update
WORKDIR /app

ENV NODE_ENV production
ENV CI true
ENV SKIP_ENV_VALIDATION true

COPY .gitignore .gitignore
COPY --from=builder /app/tsconfig.json ./tsconfig.json
COPY --from=builder /app/out/json .
COPY --from=builder /app/out/pnpm-lock.yaml\* ./

RUN yarn global add pnpm && pnpm install --frozen-lockfile

COPY --from=builder /app/out/full .

RUN pnpm turbo build --filter=nextjs

FROM --platform=linux/amd64 node:18-alpine AS runner
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update
WORKDIR /app

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
EXPOSE 3000
ENV PORT 3000

ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1 Optional

COPY --from=installer /app/apps/nextjs/next.config.mjs ./
COPY --from=installer /app/apps/nextjs/package.json ./

COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/static ./apps/nextjs/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/public ./apps/nextjs/public


CMD node apps/nextjs/server.js
4 changes: 3 additions & 1 deletion apps/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds and Linting.
*/
// !process.env.SKIP_ENV_VALIDATION && (await import("./src/env.mjs"));
!process.env.SKIP_ENV_VALIDATION && (await import("./src/env.mjs"));

/** @type {import("next").NextConfig} */
const config = {
/** For docker build, more information: https://nextjs.org/docs/advanced-features/output-file-tracing */
output: "standalone",
reactStrictMode: true,
/** Enables hot reloading for local packages without a build step */
transpilePackages: ["@acme/api", "@acme/auth", "@acme/db"],
Expand Down
11 changes: 5 additions & 6 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.9.1",
"@types/node": "^18.15.11",
"@types/react": "^18.0.31",
"tailwindcss": "^3.3.1",
"postcss": "^8.4.21",
"autoprefixer": "^10.4.14",
"zod": "^3.21.4"
},
"devDependencies": {
"@acme/eslint-config": "*",
"@types/node": "^18.15.11",
"@types/react": "^18.0.31",
"@types/react-dom": "^18.0.11",
"autoprefixer": "^10.4.14",
"dotenv-cli": "^7.1.0",
"eslint": "^8.37.0",
"postcss": "^8.4.21",
"tailwindcss": "^3.3.1",
"typescript": "^5.0.3"
}
}
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.7"

services:
nextjs:
ports:
- "3000:3000"
build:
context: .
dockerfile: ./apps/nextjs/Dockerfile
environment:
- DATABASE_URL=${DATABASE_URL}
- NEXTAUTH_URL=${NEXTAUTH_URL}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID}
- DISCORD_CLIENT_SECRET=${DISCORD_CLIENT_SECRET}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prettier": "^2.8.7",
"prettier-plugin-tailwindcss": "^0.2.6",
"turbo": "^1.8.8",
"typescript": "^5.0.3"
"typescript": "^5.0.3",
"dotenv-cli": "^7.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"with-env": "dotenv -e ../../.env --"
},
"dependencies": {
"prisma": "^4.12.0",
"@prisma/client": "^4.12.0"
},
"devDependencies": {
"dotenv-cli": "^7.1.0",
"prisma": "^4.12.0",
"typescript": "^5.0.3"
}
}
Loading

0 comments on commit 3588b78

Please sign in to comment.