Skip to content

Commit

Permalink
Add docker compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Jul 11, 2024
1 parent fc2bf19 commit 43018fd
Show file tree
Hide file tree
Showing 10 changed files with 11,459 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ y-sweet is MIT-licensed, and was created by [Jamsocket](https://jamsocket.com).
- [React hooks](https://docs.y-sweet.dev/modules/_y_sweet_react.html)
- [Document management SDK](https://docs.y-sweet.dev/modules/_y_sweet_sdk.html)
- [Y-Sweet Cloud (managed service) docs](https://y-sweet.cloud/quickstart)
- [Self Hosting](/docs/running.md)
- [Self Hosting](https://github.com/jamsocket/y-sweet/blob/main/docs/running.md)

## Examples

Expand Down
1 change: 1 addition & 0 deletions crates/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
2 changes: 1 addition & 1 deletion crates/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ FROM debian:buster-slim

COPY --from=builder /build/target/release/y-sweet /usr/local/bin/y-sweet

CMD ["y-sweet"]
CMD ["y-sweet", "--host=0.0.0.0"]
13 changes: 13 additions & 0 deletions deploy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
http://localhost {
reverse_proxy /doc/ws/* y-sweet:8080
reverse_proxy /* demos:3000
}

# To use a real domain with HTTPS, replace "http://localhost" with the domain
# (omit http://). You will also need to change --url-prefix in docker-compose.yml
# to reflect the domain.
#
# example.com {
# reverse_proxy /doc/ws/* y-sweet:8080
# reverse_proxy /* demos:3000
# }
6 changes: 6 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This shows an example deployment using Docker Compose. This is suitable for setups where one y-sweet server is
sufficient to handle the scale of requests.

To run locally, run `docker compose up`.

To use a custom domain with HTTPS, follow the commented instructions in `Caddyfile`.
34 changes: 34 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
y-sweet:
restart: unless-stopped
image: ghcr.io/jamsocket/y-sweet:latest
build:
dockerfile: Dockerfile
context: ../crates
command:
"y-sweet serve ./data --host 0.0.0.0 --auth AXO33rILFt0ZOP7v9NM8e2u6m1pVWvCS5HI9mYMK --url-prefix=http://localhost/"
volumes:
- ./data:/data
ports:
- "8080:8080"

demos:
restart: unless-stopped
build:
dockerfile: Dockerfile
context: ../examples/nextjs
environment:
- CONNECTION_STRING=ys://AAAg1s4QOZVQsRWT4p-CUrk3ory1a21SksuWR6hzqy-vFJM@y-sweet:8080
ports:
- "3000:3000"

caddy:
image: caddy:2.8.4
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
4 changes: 2 additions & 2 deletions docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ npm run deploy

See `y-sweet/crates/y-sweet-worker/wrangler.toml` for the Cloudflare resources it references. You will either need to create these resources or change the configuration to point to your own resources.

## Self-hosting in production
## Docker Image

Docker images coming soon. If you're interested, [let us know](mailto:hi@driftingin.space).
The latest Docker image is available as `ghcr.io/jamsocket/y-sweet:latest`. You can find a [list of images here](https://github.com/jamsocket/y-sweet/pkgs/container/y-sweet).
61 changes: 61 additions & 0 deletions examples/nextjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Source: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile

FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json docker-package-lock.json ./
RUN mv docker-package-lock.json package-lock.json
RUN npm ci

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN mv docker-package-lock.json package-lock.json

RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
Loading

0 comments on commit 43018fd

Please sign in to comment.