Skip to content

Commit b1601ce

Browse files
committed
dockerrr'
1 parent 65be49a commit b1601ce

6 files changed

Lines changed: 168 additions & 41 deletions

File tree

.dockerignore

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,90 @@
1-
# Node/Bun dependency folders
1+
# Dependencies
22
node_modules
33
.bun
44
.pnpm-store
5-
npm-debug.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
package-lock.json
69
yarn.lock
710

811
# Next.js build outputs
912
.next
1013
out
14+
dist
15+
build
1116

12-
# Logs
17+
# Logs and cache
1318
logs
1419
*.log
20+
.cache
21+
.turbo
22+
.swc
1523

1624
# OS / Editor files
1725
.DS_Store
26+
.DS_Store?
27+
._*
28+
.Spotlight-V100
29+
.Trashes
30+
ehthumbs.db
1831
Thumbs.db
1932
.vscode
2033
.idea
34+
*.swp
35+
*.swo
36+
*~
2137

2238
# Git files
2339
.git
2440
.gitignore
41+
.gitattributes
2542

26-
# Docker-related
27-
Dockerfile
28-
docker-compose.yml
43+
# Docker-related files
44+
Dockerfile*
45+
docker-compose*.yml
46+
.dockerignore
2947

30-
# Env files (keep local only!)
31-
.env
32-
.env.local
33-
.env.development.local
34-
.env.test.local
35-
.env.production.local
48+
# Environment files (keep local only!)
49+
.env*
50+
!.env.example
51+
52+
# Development and documentation
53+
README.md
54+
*.md
55+
.github/
56+
coverage/
57+
.nyc_output/
58+
59+
# Rust backend (not needed for Next.js app)
60+
rust-backend/
61+
62+
# Test files
63+
__tests__/
64+
*.test.*
65+
*.spec.*
66+
cypress/
67+
.coverage
68+
jest.config.*
69+
vitest.config.*
70+
71+
# Linting and formatting
72+
.eslintrc*
73+
.prettierrc*
74+
.stylelintrc*
75+
76+
# IDE and editor configs
77+
.vscode/
78+
.idea/
79+
*.sublime-*
80+
81+
# Temporary files
82+
*.tmp
83+
*.temp
84+
.tmp/
85+
.temp/
86+
87+
# Build tools config (keep only essential ones)
88+
webpack.config.js
89+
rollup.config.js
90+
vite.config.js

.github/workflows/docker-build.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@ name: Build and Push Docker Image
33
on:
44
push:
55
branches:
6-
- main
6+
- main
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
1211
steps:
13-
# Checkout your repo
1412
- name: Checkout repository
15-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v3
1617

17-
# Log in to Docker Hub
1818
- name: Log in to Docker Hub
19-
uses: docker/login-action@v2
19+
uses: docker/login-action@v3
2020
with:
2121
username: ${{ secrets.DOCKER_USERNAME }}
2222
password: ${{ secrets.DOCKER_PASSWORD }}
2323

24-
# Build and push
2524
- name: Build and push Docker image
26-
uses: docker/build-push-action@v4
25+
uses: docker/build-push-action@v5
2726
with:
2827
context: .
28+
file: ./dockerfile
29+
target: runner
2930
push: true
3031
tags: |
3132
ansh7845/aims:latest
3233
ansh7845/aims:${{ github.sha }}
34+
cache-from: type=gha
35+
cache-to: type=gha,mode=max
36+
platforms: linux/amd64,linux/arm64

build.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Simple AIMS Docker Build Script
4+
# Usage: ./build.sh
5+
6+
set -e
7+
8+
echo "🚀 Building AIMS Docker image..."
9+
echo ""
10+
11+
# Build the Docker image
12+
echo "📦 Building Docker image..."
13+
docker build -t ansh7845/aims:latest -f dockerfile .
14+
15+
echo ""
16+
echo "✅ Build complete!"
17+
18+
# Show image size
19+
echo ""
20+
echo "📊 Image size:"
21+
docker images ansh7845/aims:latest
22+
23+
echo ""
24+
echo "🔧 To run locally:"
25+
echo " docker run -p 3000:3000 ansh7845/aims:latest"
26+
echo ""
27+
echo "🚀 To push to registry:"
28+
echo " docker push ansh7845/aims:latest"

dockerfile

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
1-
# 1. Base: install dependencies
2-
FROM oven/bun:1 as base
1+
# ===== DEPENDENCIES STAGE =====
2+
FROM oven/bun:1-alpine AS deps
33
WORKDIR /app
4-
COPY package.json bun.lock ./
4+
5+
# Copy dependency files
6+
COPY package.json bun.lock* ./
7+
8+
# Install all dependencies (including dev dependencies for build)
59
RUN bun install --frozen-lockfile
610

7-
# 2. Builder: copy source + build
8-
FROM base as builder
11+
# ===== BUILDER STAGE =====
12+
FROM oven/bun:1-alpine AS builder
913
WORKDIR /app
10-
COPY . .
11-
RUN bun run build
1214

13-
# 3. Runner: production image
14-
FROM oven/bun:1-slim as runner
15+
# Copy dependencies from deps stage
16+
COPY --from=deps /app/node_modules ./node_modules
17+
COPY package.json bun.lock* ./
18+
19+
# Copy source code (excluding unnecessary files via .dockerignore)
20+
COPY app ./app
21+
COPY components ./components
22+
COPY contexts ./contexts
23+
COPY hooks ./hooks
24+
COPY lib ./lib
25+
COPY public ./public
26+
COPY next.config.ts ./
27+
COPY tsconfig.json ./
28+
COPY postcss.config.mjs ./
29+
COPY components.json ./
30+
31+
# Build application with optimizations
32+
RUN NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 bun run build
33+
34+
# ===== PRODUCTION STAGE =====
35+
FROM oven/bun:1-alpine AS runner
1536
WORKDIR /app
1637

17-
ENV NODE_ENV=production
18-
ENV PORT=3000
38+
# Install runtime dependencies and security updates
39+
RUN apk add --no-cache \
40+
curl \
41+
ca-certificates \
42+
&& apk upgrade --no-cache \
43+
&& rm -rf /var/cache/apk/*
1944

20-
# Copy built app
21-
COPY --from=builder /app/.next ./.next
22-
COPY --from=builder /app/public ./public
23-
COPY --from=builder /app/package.json ./package.json
24-
COPY --from=builder /app/bun.lock ./bun.lock
45+
# Create non-root user for security
46+
RUN addgroup --system --gid 1001 nodejs && \
47+
adduser --system --uid 1001 nextjs
2548

26-
# Install only production deps
27-
RUN bun install --frozen-lockfile --production
49+
# No environment variables - all hardcoded for consistency
2850

51+
# Copy built application with proper ownership
52+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
53+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
54+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
55+
56+
# Switch to non-root user
57+
USER nextjs
58+
59+
# Expose port
2960
EXPOSE 3000
30-
CMD ["bun", "run", "start"]
61+
62+
# Add health check using one of your API endpoints
63+
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
64+
CMD curl -f http://localhost:3000/api/login || exit 1
65+
66+
# Start application with hardcoded settings
67+
CMD ["sh", "-c", "NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0 node server.js"]

next.config.ts

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

33
const nextConfig: NextConfig = {
4+
// Enable standalone output for Docker optimization
5+
output: 'standalone',
6+
47
// Compress responses
58
compress: true,
69

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "next dev --turbopack",
77
"build": "next build",
8-
"start": "next start",
8+
"start": "next start -p ${PORT:-3000}",
99
"lint": "next lint"
1010
},
1111
"dependencies": {
@@ -38,4 +38,4 @@
3838
"tw-animate-css": "^1.3.0",
3939
"typescript": "^5"
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)