Skip to content

Commit 192f520

Browse files
authored
Merge pull request #1 from Penify-dev/docker_deployment
feat():[] docker image
2 parents 37fc497 + 3ce7fb9 commit 192f520

8 files changed

Lines changed: 191 additions & 13 deletions

File tree

.dockerignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
node_modules
2+
build
3+
.cache
4+
dist
5+
6+
# Git
7+
.git
8+
.gitignore
9+
10+
# Environment
11+
.env
12+
.env.local
13+
.env.*.local
14+
15+
# IDE
16+
.vscode
17+
.idea
18+
*.sw?
19+
20+
# OS
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Logs
25+
*.log
26+
npm-debug.log*
27+
28+
# CI/CD
29+
.github
30+
31+
# Docs
32+
docs
33+
*.md
34+
!README.md
35+
36+
# Database local files
37+
*.db
38+
*.db-journal

.env.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
# APPLICATION
99
# ==================================
1010
NODE_ENV=development
11-
PORT=5173
11+
PORT=8080
1212

1313
# Public URL (accessible from client-side)
1414
# Used for: absolute URLs, redirects, social sharing, etc.
1515
# Examples:
16-
# - Development: http://localhost:5173
16+
# - Development: http://localhost:8080
1717
# - Production: https://yourdomain.com
18-
PUBLIC_URL=http://localhost:5173
18+
PUBLIC_URL=http://localhost:8080
1919

2020
# ==================================
2121
# DATABASE
@@ -59,5 +59,5 @@ SESSION_SECRET=your-secret-key-here-change-in-production
5959
# Variables with VITE_ prefix are exposed to the client
6060
# Only use for non-sensitive configuration
6161
# Example:
62-
# VITE_API_BASE_URL=http://localhost:5173
62+
# VITE_API_BASE_URL=http://localhost:8080
6363
# VITE_ENABLE_ANALYTICS=true

.github/workflows/ci.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: CI - Build & Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [main,docker_deployment]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
DOCKERHUB_REPO: sunilagwl5/template-viber
11+
12+
jobs:
13+
# lint-and-typecheck:
14+
# name: Lint & Typecheck
15+
# runs-on: ubuntu-latest
16+
# steps:
17+
# - uses: actions/checkout@v4
18+
19+
# - uses: oven-sh/setup-bun@v2
20+
# with:
21+
# bun-version: "latest"
22+
23+
# - name: Install dependencies
24+
# run: bun install --frozen-lockfile
25+
26+
# - name: Lint
27+
# run: bun run lint
28+
29+
# - name: Typecheck
30+
# run: bun run typecheck
31+
32+
# test:
33+
# name: Unit Tests
34+
# runs-on: ubuntu-latest
35+
# steps:
36+
# - uses: actions/checkout@v4
37+
38+
# - uses: oven-sh/setup-bun@v2
39+
# with:
40+
# bun-version: "latest"
41+
42+
# - name: Install dependencies
43+
# run: bun install --frozen-lockfile
44+
45+
# - name: Run tests
46+
# run: bun run test
47+
48+
docker:
49+
name: Build & Push Docker Image
50+
runs-on: ubuntu-latest
51+
# needs: [lint-and-typecheck, test]
52+
permissions:
53+
contents: read
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
60+
- name: Login to Docker Hub
61+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
62+
uses: docker/login-action@v3
63+
with:
64+
username: ${{ secrets.DOCKERHUB_USERNAME }}
65+
password: ${{ secrets.DOCKERHUB_TOKEN }}
66+
67+
- name: Extract metadata for Docker
68+
id: meta
69+
uses: docker/metadata-action@v5
70+
with:
71+
images: ${{ env.DOCKERHUB_REPO }}
72+
tags: |
73+
type=sha,prefix=
74+
type=raw,value=latest,enable={{is_default_branch}}
75+
type=ref,event=pr
76+
77+
- name: Build and push
78+
uses: docker/build-push-action@v6
79+
with:
80+
context: .
81+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
82+
tags: ${{ steps.meta.outputs.tags }}
83+
labels: ${{ steps.meta.outputs.labels }}
84+
cache-from: type=gha
85+
cache-to: type=gha,mode=max
86+
platforms: linux/amd64,linux/arm64

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ============================================================
2+
# Stage 1: Install dependencies
3+
# ============================================================
4+
FROM oven/bun:1-alpine AS deps
5+
6+
WORKDIR /app
7+
8+
COPY package.json bun.lock ./
9+
RUN bun install --frozen-lockfile
10+
11+
# ============================================================
12+
# Stage 2: Build the application
13+
# ============================================================
14+
FROM oven/bun:1-alpine AS build
15+
16+
WORKDIR /app
17+
18+
COPY --from=deps /app/node_modules ./node_modules
19+
COPY . .
20+
21+
ENV NODE_ENV=production
22+
ENV VITE_CJS_IGNORE_WARNING=true
23+
24+
RUN bun run build
25+
26+
# Prune dev dependencies after build
27+
RUN bun install --frozen-lockfile --production && \
28+
rm -rf /app/.cache
29+
30+
# ============================================================
31+
# Stage 3: Production runtime
32+
# ============================================================
33+
FROM node:20-alpine AS production
34+
35+
WORKDIR /app
36+
37+
ENV NODE_ENV=production
38+
ENV PORT=8080
39+
40+
# Add non-root user for security
41+
RUN addgroup --system --gid 1001 remix && \
42+
adduser --system --uid 1001 remix
43+
44+
# Copy only what's needed for production
45+
COPY --from=build /app/build ./build
46+
COPY --from=build /app/node_modules ./node_modules
47+
COPY --from=build /app/package.json ./package.json
48+
COPY --from=build /app/public ./public
49+
50+
USER remix
51+
52+
EXPOSE 8080
53+
54+
CMD ["sh", "-c", "PORT=${PORT_IN:-$PORT} npm run start"]

app/lib/env.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export function getRequiredEnv(key: string): string {
3838
export const env = {
3939
// Application
4040
NODE_ENV: getEnv("NODE_ENV") || "development",
41-
PORT: getEnv("PORT") || "5173",
42-
PUBLIC_URL: getEnv("PUBLIC_URL") || "http://localhost:5173",
41+
PORT: getEnv("PORT") || "8080",
42+
PUBLIC_URL: getEnv("PUBLIC_URL") || "http://localhost:8080",
4343

4444
// Database (optional - only needed if using database features)
4545
DATABASE_URL: getEnv("DATABASE_URL"),

docs/ENVIRONMENT_SETUP.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Edit `.env` and set the following:
1616
```env
1717
# Application
1818
NODE_ENV=development
19-
PORT=5173
20-
PUBLIC_URL=http://localhost:5173
19+
PORT=8080
20+
PUBLIC_URL=http://localhost:8080
2121
2222
# Database (PostgreSQL)
2323
DATABASE_URL=postgresql://user:password@localhost:5432/database_name?schema=public
@@ -44,15 +44,15 @@ node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
4444
| Variable | Description | Example |
4545
|----------|-------------|---------|
4646
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://user:pass@localhost:5432/db` |
47-
| `PUBLIC_URL` | Public-facing application URL | `http://localhost:5173` |
47+
| `PUBLIC_URL` | Public-facing application URL | `http://localhost:8080` |
4848
| `SESSION_SECRET` | Secret for session encryption | `random-32-char-string` |
4949

5050
### Optional Variables
5151

5252
| Variable | Description | Example |
5353
|----------|-------------|---------|
5454
| `NODE_ENV` | Environment mode | `development`, `production` |
55-
| `PORT` | Server port | `5173` |
55+
| `PORT` | Server port | `8080` |
5656
| `DIRECT_DATABASE_URL` | Direct DB connection (pooling) | `postgresql://...` |
5757

5858
### Adding API Keys
@@ -82,7 +82,7 @@ AWS_SECRET_ACCESS_KEY=...
8282
### Development
8383
```env
8484
NODE_ENV=development
85-
PUBLIC_URL=http://localhost:5173
85+
PUBLIC_URL=http://localhost:8080
8686
DATABASE_URL=postgresql://postgres:password@localhost:5432/app_dev
8787
```
8888

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"dev": "VITE_CJS_IGNORE_WARNING=true remix vite:dev",
99
"build": "VITE_CJS_IGNORE_WARNING=true remix vite:build",
10-
"start": "PORT=5173 remix-serve ./build/server/index.js",
10+
"start": "remix-serve ./build/server/index.js",
1111
"lint": "eslint .",
1212
"typecheck": "tsc",
1313
"test": "vitest run",

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare module "@remix-run/node" {
1111

1212
export default defineConfig({
1313
server: {
14-
port: 5173,
14+
port: 8080,
1515
},
1616
resolve: {
1717
alias: {

0 commit comments

Comments
 (0)