Skip to content

Commit 0e4186f

Browse files
committed
feat(docker): add environment configuration and enhance Docker setup
1 parent 639dc57 commit 0e4186f

File tree

10 files changed

+146
-70
lines changed

10 files changed

+146
-70
lines changed

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Authentication
2+
GOOGLE_CLIENT_ID=your_google_client_id
3+
GOOGLE_CLIENT_SECRET=your_google_client_secret
4+
NEXTAUTH_URL=http://localhost:3000
5+
NEXTAUTH_SECRET=your_nextauth_secret
6+
7+
# Analytics
8+
POSTHOG_KEY=your_posthog_key
9+
POSTHOG_HOST=your_posthog_host
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
1-
name: Docker Publish
1+
name: Docker Image CI/CD
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ "main" ]
66
tags: [ 'v*.*.*' ]
77
pull_request:
8-
branches: [ main ]
8+
branches: [ "main" ]
99

1010
env:
1111
REGISTRY: ghcr.io
1212
IMAGE_NAME: ${{ github.repository }}
1313

1414
jobs:
15-
build-and-push:
15+
build:
1616
runs-on: ubuntu-latest
1717
permissions:
1818
contents: read
1919
packages: write
2020

2121
steps:
22-
- name: Checkout
22+
- name: Checkout repository
2323
uses: actions/checkout@v4
2424

25-
- name: Log in to GitHub Container Registry
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log into registry ${{ env.REGISTRY }}
29+
if: github.event_name != 'pull_request'
2630
uses: docker/login-action@v3
2731
with:
2832
registry: ${{ env.REGISTRY }}
2933
username: ${{ github.actor }}
3034
password: ${{ secrets.GITHUB_TOKEN }}
3135

32-
- name: Extract metadata
36+
- name: Extract Docker metadata
3337
id: meta
3438
uses: docker/metadata-action@v5
3539
with:
3640
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
type=ref,event=branch
43+
type=ref,event=pr
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
3746
38-
- name: Build and push
47+
- name: Build and push Docker image
3948
uses: docker/build-push-action@v5
4049
with:
4150
context: .
42-
push: true
51+
push: ${{ github.event_name != 'pull_request' }}
4352
tags: ${{ steps.meta.outputs.tags }}
44-
labels: ${{ steps.meta.outputs.labels }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

.github/workflows/release.yml

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1-
name: Release
2-
3-
on:
4-
push:
5-
tags:
6-
- 'v*'
7-
8-
jobs:
9-
release:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v3
13-
with:
14-
fetch-depth: 0
15-
16-
- name: Setup Node.js
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: '18'
20-
cache: 'npm'
21-
22-
- name: Install dependencies
23-
run: npm ci
24-
25-
- name: Generate changelog
26-
run: |
27-
npm run changelog
28-
git config --local user.email "action@github.com"
29-
git config --local user.name "GitHub Action"
30-
git add CHANGELOG.md
31-
git commit -m "docs: update changelog for ${{ github.ref_name }}" || echo "No changes to commit"
32-
33-
- name: Create Release
34-
uses: actions/create-release@v1
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
with:
38-
tag_name: ${{ github.ref }}
39-
release_name: Release ${{ github.ref }}
40-
body_path: .github/RELEASE_BODY.md
41-
draft: false
42-
prerelease: false
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
release:
13+
name: Release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: "lts/*"
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Create Release
31+
id: changesets
32+
uses: changesets/action@v1
33+
with:
34+
version: npm run version
35+
commit: "chore: version packages"
36+
title: "chore: version packages"
37+
publish: npm run changelog
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ yarn-error.log*
2727

2828
# local env files
2929
.env*.local
30+
.env.production
31+
.env.development
3032

3133
# vercel
3234
.vercel

Dockerfile

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,62 @@
1-
# Base image
2-
FROM node:18-alpine AS base
1+
# Stage 1: Development dependencies
2+
FROM node:18-alpine AS deps
33
WORKDIR /app
44

5-
# Dependencies
6-
FROM base AS deps
5+
# Install dependencies needed for build
6+
RUN apk add --no-cache libc6-compat
7+
8+
# Copy package files
79
COPY package.json package-lock.json ./
10+
11+
# Install dependencies
812
RUN npm ci
913

10-
# Builder
11-
FROM base AS builder
14+
# Stage 2: Builder
15+
FROM node:18-alpine AS builder
16+
WORKDIR /app
17+
18+
# Copy dependencies from deps stage
1219
COPY --from=deps /app/node_modules ./node_modules
1320
COPY . .
21+
22+
# Set environment variables for build
23+
ENV NEXT_TELEMETRY_DISABLED 1
24+
ENV NODE_ENV production
25+
26+
# Build application
1427
RUN npm run build
1528

16-
# Runner
17-
FROM base AS runner
18-
ENV NODE_ENV=production
29+
# Stage 3: Production image
30+
FROM node:18-alpine AS runner
31+
WORKDIR /app
32+
33+
# Set environment variables
34+
ENV NODE_ENV production
1935
ENV NEXT_TELEMETRY_DISABLED 1
2036

37+
# Create non-root user
2138
RUN addgroup --system --gid 1001 nodejs
2239
RUN adduser --system --uid 1001 nextjs
2340

24-
COPY --from=builder /app/public ./public
41+
# Set proper permissions
42+
RUN mkdir .next
43+
RUN chown nextjs:nodejs .next
44+
45+
# Copy only necessary files
46+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
2547
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
2648
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
49+
COPY --from=builder /app/data ./data
2750

51+
# Switch to non-root user
2852
USER nextjs
2953

54+
# Expose port
3055
EXPOSE 3000
56+
57+
# Set hostname
3158
ENV PORT 3000
3259
ENV HOSTNAME "0.0.0.0"
3360

34-
CMD ["node", "server.js"]
61+
# Start the application
62+
CMD ["node", "server.js"]

app/auth/signin/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
// import { signIn } from "next-auth/react";
4-
import SignInButton from "@/components/Sign-in";
4+
import SignInButton from "@/components/SignIn";
55

66
export default function SignIn() {
77
return (

docker-compose.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
version: '3.8'
2+
23
services:
34
app:
45
build:
56
context: .
6-
target: runner
7+
dockerfile: Dockerfile
78
ports:
89
- "3000:3000"
910
environment:
10-
- NODE_ENV=production
11+
- NODE_ENV=production
12+
- NEXT_TELEMETRY_DISABLED=1
13+
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
14+
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
15+
- NEXTAUTH_URL=${NEXTAUTH_URL}
16+
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
17+
- POSTHOG_KEY=${POSTHOG_KEY}
18+
- POSTHOG_HOST=${POSTHOG_HOST}
19+
volumes:
20+
- ./data:/app/data:ro
21+
restart: unless-stopped
22+
healthcheck:
23+
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1"]
24+
interval: 30s
25+
timeout: 10s
26+
retries: 3
27+
start_period: 20s
28+
deploy:
29+
resources:
30+
limits:
31+
cpus: '1'
32+
memory: 1G
33+
reservations:
34+
cpus: '0.25'
35+
memory: 512M
36+
logging:
37+
driver: "json-file"
38+
options:
39+
max-size: "10m"
40+
max-file: "3"

next.config.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const nextConfig = {
44
images: {
55
domains: ["lh3.googleusercontent.com","images.unsplash.com", "assets.aceternity.com"],
66
},
7-
experimental: {
8-
serverActions: true,
9-
},
107
};
118

129
export default nextConfig;

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
],
2121
"paths": {
2222
"@/*": ["./*"]
23-
}
23+
},
24+
"forceConsistentCasingInFileNames": true,
25+
"baseUrl": "."
2426
},
2527
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2628
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)