Skip to content

Commit 4dbc7c2

Browse files
committed
add runner
1 parent 7c22c4f commit 4dbc7c2

7 files changed

Lines changed: 65 additions & 47 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy Docker
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
deploy:
9+
runs-on: self-hosted
10+
11+
steps:
12+
- name: Deploy on server
13+
run: |
14+
set -e
15+
16+
echo "Go to app folder"
17+
cd /opt/apps/contact
18+
19+
echo "Pull latest code"
20+
git pull origin main
21+
22+
echo "Build & restart containers"
23+
docker compose down || true
24+
docker compose build
25+
docker compose up -d
26+
27+
echo "Deploy finished"

AGENTS.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

CLAUDE.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
FROM node:22-alpine AS base
1+
# ===== BUILD =====
2+
FROM node:20-alpine AS builder
3+
24
WORKDIR /app
3-
ENV NEXT_TELEMETRY_DISABLED=1
45

5-
FROM base AS deps
6-
COPY package.json package-lock.json ./
6+
COPY package*.json ./
77
RUN npm ci
88

9-
FROM deps AS dev
109
COPY . .
11-
EXPOSE 3000
12-
CMD ["npm", "run", "dev", "--", "--hostname", "0.0.0.0", "--port", "3000"]
1310

14-
FROM deps AS builder
15-
COPY . .
1611
RUN npm run build
1712

18-
FROM base AS runner
13+
14+
# ===== RUN =====
15+
FROM node:20-alpine AS runner
16+
17+
WORKDIR /app
18+
1919
ENV NODE_ENV=production
20-
ENV HOSTNAME=0.0.0.0
21-
ENV PORT=3000
20+
21+
# Standalone output
22+
COPY --from=builder /app/public ./public
2223
COPY --from=builder /app/.next/standalone ./
2324
COPY --from=builder /app/.next/static ./.next/static
24-
COPY --from=builder /app/public ./public
25+
2526
EXPOSE 3000
26-
CMD ["node", "server.js"]
27+
28+
CMD ["node", "server.js"]

docker-compose.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ services:
33
image: postgres:16-alpine
44
container_name: contact-postgres
55
restart: unless-stopped
6+
env_file:
7+
- .env
68
environment:
79
POSTGRES_DB: ${POSTGRES_DB:-contact}
810
POSTGRES_USER: ${POSTGRES_USER:-contact}
@@ -12,43 +14,33 @@ services:
1214
volumes:
1315
- postgres-data:/var/lib/postgresql/data
1416

15-
contact-dev:
16-
profiles: ["dev"]
17+
contact:
1718
build:
1819
context: .
19-
target: dev
20-
container_name: contact-dev
21-
ports:
22-
- "3000:3000"
23-
volumes:
24-
- .:/app
25-
- /app/node_modules
26-
- /app/.next
27-
environment:
28-
NEXT_TELEMETRY_DISABLED: "1"
29-
DATABASE_URL: ${DATABASE_URL_DOCKER:-postgresql://contact:change-this-db-password@postgres:5432/contact}
30-
ADMIN_USERNAME: ${ADMIN_USERNAME:-admin}
31-
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-change-this-admin-password}
32-
ADMIN_SESSION_SECRET: ${ADMIN_SESSION_SECRET:-change-this-session-secret}
33-
depends_on:
34-
- postgres
20+
dockerfile: Dockerfile
21+
22+
container_name: contact
3523

36-
contact-prod:
37-
profiles: ["prod"]
38-
build:
39-
context: .
40-
target: runner
41-
container_name: contact-prod
42-
restart: unless-stopped
4324
ports:
44-
- "3018:3000"
25+
- "${APP_PORT}:3000"
26+
4527
env_file:
4628
- .env
4729
environment:
4830
NEXT_TELEMETRY_DISABLED: "1"
4931
DATABASE_URL: ${DATABASE_URL_DOCKER:-postgresql://contact:change-this-db-password@postgres:5432/contact}
32+
33+
restart: unless-stopped
34+
5035
depends_on:
5136
- postgres
5237

38+
healthcheck:
39+
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/"]
40+
interval: 30s
41+
timeout: 10s
42+
retries: 3
43+
start_period: 20s
44+
5345
volumes:
5446
postgres-data:

next.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
44
output: "standalone",
5+
compress: true,
6+
poweredByHeader: false,
57
};
68

79
export default nextConfig;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"dev": "next dev",
77
"build": "next build",
8-
"start": "next start",
8+
"start": "node .next/standalone/server.js",
9+
"docker": "docker compose up --build",
910
"lint": "eslint"
1011
},
1112
"dependencies": {

0 commit comments

Comments
 (0)