Skip to content

Commit 9e8bdb7

Browse files
authored
Merge pull request #15 from SharanRP/Sharan/docker
Sharan/docker
2 parents d2fcca0 + 0e4186f commit 9e8bdb7

File tree

11 files changed

+223
-47
lines changed

11 files changed

+223
-47
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.github
3+
node_modules
4+
.next
5+
.env*
6+
npm-debug.log*
7+
README.md
8+
.gitignore
9+
.dockerignore
10+
Dockerfile
11+
docker-compose*

.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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker Image CI/CD
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
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'
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract Docker metadata
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
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}}
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: .
51+
push: ${{ github.event_name != 'pull_request' }}
52+
tags: ${{ steps.meta.outputs.tags }}
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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Stage 1: Development dependencies
2+
FROM node:18-alpine AS deps
3+
WORKDIR /app
4+
5+
# Install dependencies needed for build
6+
RUN apk add --no-cache libc6-compat
7+
8+
# Copy package files
9+
COPY package.json package-lock.json ./
10+
11+
# Install dependencies
12+
RUN npm ci
13+
14+
# Stage 2: Builder
15+
FROM node:18-alpine AS builder
16+
WORKDIR /app
17+
18+
# Copy dependencies from deps stage
19+
COPY --from=deps /app/node_modules ./node_modules
20+
COPY . .
21+
22+
# Set environment variables for build
23+
ENV NEXT_TELEMETRY_DISABLED 1
24+
ENV NODE_ENV production
25+
26+
# Build application
27+
RUN npm run build
28+
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
35+
ENV NEXT_TELEMETRY_DISABLED 1
36+
37+
# Create non-root user
38+
RUN addgroup --system --gid 1001 nodejs
39+
RUN adduser --system --uid 1001 nextjs
40+
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
47+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
48+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
49+
COPY --from=builder /app/data ./data
50+
51+
# Switch to non-root user
52+
USER nextjs
53+
54+
# Expose port
55+
EXPOSE 3000
56+
57+
# Set hostname
58+
ENV PORT 3000
59+
ENV HOSTNAME "0.0.0.0"
60+
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "3000:3000"
10+
environment:
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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
output: 'standalone',
34
images: {
45
domains: ["lh3.googleusercontent.com","images.unsplash.com", "assets.aceternity.com"],
56
},
6-
experimental: {
7-
serverActions: true,
8-
},
97
};
108

119
export default nextConfig;

0 commit comments

Comments
 (0)