docker file setup
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
# App Configuration
|
# App Configuration
|
||||||
DATABASE_URL=postgres://portfolio:portfolio@127.0.0.1:5432/portfolio
|
|
||||||
PAYLOAD_SECRET=123ABC
|
PAYLOAD_SECRET=123ABC
|
||||||
|
|
||||||
# S3 Configuration
|
# S3 Configuration
|
||||||
|
|||||||
3
.env.template
Normal file
3
.env.template
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# App Configuration
|
||||||
|
DATABASE_URL=postgres://<user>:<password>@<host>:5432/<database>
|
||||||
|
PAYLOAD_SECRET=123ABC
|
||||||
66
Dockerfile
66
Dockerfile
@@ -1,29 +1,65 @@
|
|||||||
FROM node:24-alpine AS base
|
FROM node:24-alpine AS base
|
||||||
ENV NODE_ENV=production
|
|
||||||
|
|
||||||
|
# Install curl for health checks
|
||||||
|
RUN apk add --no-cache curl
|
||||||
|
|
||||||
|
# Install dependencies only when needed
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json pnpm-lock.yaml* .npmrc* ./
|
|
||||||
RUN corepack enable pnpm && pnpm i --frozen-lockfile;
|
|
||||||
|
|
||||||
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN corepack enable pnpm && pnpm build
|
|
||||||
|
|
||||||
|
# Set build args and environment variables
|
||||||
|
ARG NODE_ENV=production
|
||||||
|
ENV NODE_ENV=$NODE_ENV
|
||||||
|
ARG DATABASE_URL
|
||||||
|
ENV DATABASE_URL=$DATABASE_URL
|
||||||
|
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||||||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Production image, copy all the files and run next
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN corepack enable pnpm
|
|
||||||
RUN mkdir -p /app/portfolio-data && chown node:node /app/portfolio-data
|
ENV NODE_ENV=production
|
||||||
COPY --chown=node --from=deps /app/node_modules ./node_modules
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
COPY --chown=node --from=builder /app/public ./public
|
|
||||||
COPY --chown=node --from=builder /app/next.config.ts ./next.config.ts
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
COPY --chown=node --from=builder /app/.next ./.next
|
RUN adduser --system --uid 1001 nextjs
|
||||||
COPY --chown=node --from=builder /app/package.json ./package.json
|
|
||||||
COPY --chown=node --from=builder /app/tsconfig.json ./tsconfig.json
|
COPY --from=builder /app/public ./public
|
||||||
COPY --chown=node --from=builder /app/src ./src
|
|
||||||
USER node
|
RUN mkdir .next
|
||||||
|
RUN chown nextjs:nodejs .next
|
||||||
|
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["pnpm", "start"]
|
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
@@ -35,9 +35,11 @@ pnpm run payload:migrate:create
|
|||||||
Deploying the portfolio is done as a docker container. It can be built with the following command:
|
Deploying the portfolio is done as a docker container. It can be built with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t liam-portfolio .
|
docker build --add-host=host.docker.internal:host-gateway --build-arg HOST_GATEWAY=host.docker.internal -t liam-portfolio .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: Ensure a .env exists with the correct environment variables, including the DATABASE_URL and PAYLOAD_SECRET.
|
||||||
|
|
||||||
### Running the Container
|
### Running the Container
|
||||||
|
|
||||||
Once the container is built, you can run it with the following command:
|
Once the container is built, you can run it with the following command:
|
||||||
|
|||||||
13
compose.yml
13
compose.yml
@@ -1,17 +1,5 @@
|
|||||||
services:
|
services:
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:17
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: portfolio
|
|
||||||
POSTGRES_PASSWORD: portfolio
|
|
||||||
POSTGRES_DB: portfolio
|
|
||||||
volumes:
|
|
||||||
- portfolio_db_data:/var/lib/postgresql/data
|
|
||||||
|
|
||||||
s3:
|
s3:
|
||||||
image: ghcr.io/achtungsoftware/alarik:latest
|
image: ghcr.io/achtungsoftware/alarik:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -58,5 +46,4 @@ services:
|
|||||||
"
|
"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
portfolio_db_data:
|
|
||||||
portfolio_s3_data:
|
portfolio_s3_data:
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liam-portfolio",
|
"name": "liam-portfolio",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user