Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker prebuild and GitHub Actions workflow #431

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Build and Push

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
20 changes: 18 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@

FROM oven/bun:1.1.3-alpine
# Base image
FROM oven/bun:1.1.3-alpine AS builder

# Install build tools
RUN apk add --no-cache nodejs npm git

WORKDIR /app

# Install dependencies (separated for better cache utilization)
COPY package.json bun.lockb ./
RUN bun install

# Copy source code and build
COPY . .

RUN bun next telemetry disable
RUN bun run build

# Runtime stage
FROM oven/bun:1.1.3-alpine AS runner
WORKDIR /app

# Copy only necessary files from builder
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/bun.lockb ./bun.lockb
COPY --from=builder /app/node_modules ./node_modules

# Start development server
CMD ["bun", "dev", "-H", "0.0.0.0"]
10 changes: 7 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# This is a Docker Compose file for setting up the morphic-stack environment.
# Docker Compose configuration for the morphic-stack development environment

name: morphic-stack
services:
morphic:
image: ghcr.io/${GITHUB_REPOSITORY:-your-username/morphic}:latest
build:
context: . # The build context is the current directory
context: .
dockerfile: Dockerfile
command: bun dev # Use `bun dev -H 0.0.0.0` to listen on all interfaces
cache_from:
- morphic:builder
- morphic:latest
command: bun dev -H 0.0.0.0
env_file: .env.local # Load environment variables
ports:
- '3000:3000' # Maps port 3000 on the host to port 3000 in the container.
Expand Down