Skip to content

Commit d950902

Browse files
committed
feat: add docker prebuild and GitHub Actions workflow
- Add multi-stage Dockerfile for optimized builds - Configure GitHub Actions for automated image builds - Update docker-compose.yaml for prebuild support
1 parent f71ff56 commit d950902

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

.github/workflows/docker-build.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Login to GitHub Container Registry
24+
if: github.event_name != 'pull_request'
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Build and push Docker image
32+
uses: docker/build-push-action@v5
33+
with:
34+
context: .
35+
push: ${{ github.event_name != 'pull_request' }}
36+
tags: |
37+
ghcr.io/${{ github.repository }}:latest
38+
ghcr.io/${{ github.repository }}:${{ github.sha }}
39+
cache-from: type=gha
40+
cache-to: type=gha,mode=max
41+
42+
- name: Build Redis image
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: .
46+
file: Dockerfile.redis
47+
push: ${{ github.event_name != 'pull_request' }}
48+
tags: |
49+
ghcr.io/${{ github.repository }}-redis:latest
50+
ghcr.io/${{ github.repository }}-redis:${{ github.sha }}

Dockerfile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11

2-
FROM oven/bun:1.1.3-alpine
2+
# Base image
3+
FROM oven/bun:1.1.3-alpine AS builder
34

5+
# Install build tools
46
RUN apk add --no-cache nodejs npm git
57

68
WORKDIR /app
79

10+
# Install dependencies (separated for better cache utilization)
811
COPY package.json bun.lockb ./
912
RUN bun install
1013

14+
# Copy source code and build
1115
COPY . .
12-
1316
RUN bun next telemetry disable
17+
RUN bun run build
18+
19+
# Runtime stage
20+
FROM oven/bun:1.1.3-alpine AS runner
21+
WORKDIR /app
22+
23+
# Copy only necessary files from builder
24+
COPY --from=builder /app/.next ./.next
25+
COPY --from=builder /app/public ./public
26+
COPY --from=builder /app/package.json ./package.json
27+
COPY --from=builder /app/bun.lockb ./bun.lockb
28+
COPY --from=builder /app/node_modules ./node_modules
1429

30+
# Start development server
1531
CMD ["bun", "dev", "-H", "0.0.0.0"]

docker-compose.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
# This is a Docker Compose file for setting up the morphic-stack environment.
1+
# Docker Compose configuration for the morphic-stack development environment
22

33
name: morphic-stack
44
services:
55
morphic:
6+
image: ghcr.io/${GITHUB_REPOSITORY:-your-username/morphic}:latest
67
build:
7-
context: . # The build context is the current directory
8+
context: .
89
dockerfile: Dockerfile
9-
command: bun dev # Use `bun dev -H 0.0.0.0` to listen on all interfaces
10+
cache_from:
11+
- morphic:builder
12+
- morphic:latest
13+
command: bun dev -H 0.0.0.0
1014
env_file: .env.local # Load environment variables
1115
ports:
1216
- '3000:3000' # Maps port 3000 on the host to port 3000 in the container.

0 commit comments

Comments
 (0)