Skip to content

Commit 6017be3

Browse files
committed
feat():[] docker image
1 parent 37fc497 commit 6017be3

3 files changed

Lines changed: 178 additions & 0 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

.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=5173
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 5173
53+
54+
CMD ["npm", "run", "start"]

0 commit comments

Comments
 (0)