diff --git a/docker-compose.local.yml b/docker-compose.local.yml new file mode 100644 index 0000000..a4d0a17 --- /dev/null +++ b/docker-compose.local.yml @@ -0,0 +1,37 @@ +version: "3.8" + +services: + frontend: + build: . + ports: + - "8080:80" + environment: + # Connect to the local SpacetimeDB instance + - SPACETIMEDB_URI=ws://localhost:3000 + - SPACETIMEDB_DB_NAME=my-chat-app + depends_on: + - module-publisher + + spacetimedb: + image: clockworklabs/spacetime:latest + ports: + - "3000:3000" + entrypoint: spacetime start + hostname: spacetimedb + volumes: + - spacetimedb-data:/root/.spacetime + + # A temporary service to publish the module to the local database + # on startup, ensuring the schema is always up-to-date. + module-publisher: + build: + context: ./spacetimedb + dockerfile: Dockerfile.publish + depends_on: + - spacetimedb + environment: + - SPACETIMEDB_URI=http://spacetimedb:3000 + - SPACETIMEDB_DB_NAME=my-chat-app + +volumes: + spacetimedb-data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..11af6fb --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -e + +# Path to the config file +CONFIG_FILE="/usr/share/nginx/html/config.js" + +# Create or overwrite the config file +echo "window.__ENV__ = {" > $CONFIG_FILE + +# Append environment variables +echo " VITE_SPACETIMEDB_HOST: \"${SPACETIMEDB_URI:-wss://maincloud.spacetimedb.com}\"," >> $CONFIG_FILE +echo " VITE_SPACETIMEDB_DB_NAME: \"${SPACETIMEDB_DB_NAME:-zep}\"," >> $CONFIG_FILE +echo " VITE_OIDC_AUTHORITY: \"${AUTH_ISSUER:-https://accounts.google.com}\"," >> $CONFIG_FILE +echo " VITE_OIDC_CLIENT_ID: \"${AUTH_CLIENT_ID:-REPLACE_ME}\"" >> $CONFIG_FILE + +echo "};" >> $CONFIG_FILE + +# Pass control to the main container command +exec "$@" \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..c8d680a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + # Cache static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, no-transform"; + } +} \ No newline at end of file diff --git a/package.json b/package.json index 371a757..803ad8f 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite --host=0.0.0.0", "ssldev": "VITE_USE_SSL=true vite --host=0.0.0.0", + "docker:local": "docker compose -f docker-compose.local.yml up --build", "build": "tsc -b && vite build", "format": "prettier . --write --ignore-path ../../.prettierignore", "lint": "eslint .", diff --git a/spacetimedb/Dockerfile.publish b/spacetimedb/Dockerfile.publish new file mode 100644 index 0000000..3faf647 --- /dev/null +++ b/spacetimedb/Dockerfile.publish @@ -0,0 +1,18 @@ +FROM node:20 + +# Install SpacetimeDB CLI +RUN apt-get update && apt-get install -y curl && \ + curl --proto '=https' --tlsv1.2 -sSf https://install.spacetimedb.com | sh -s -- -y + +# Add to path +ENV PATH="/root/.local/bin:${PATH}" + +WORKDIR /module +COPY . . + +# Run the publish command. We use a shell loop to wait for the DB to be ready. +CMD echo "Waiting for SpacetimeDB at ${SPACETIMEDB_URI}..." && \ + while ! curl -s ${SPACETIMEDB_URI}/api/v1/identity; do sleep 2; done; \ + echo "Publishing module ${SPACETIMEDB_DB_NAME} to ${SPACETIMEDB_URI}..." && \ + spacetime server add --url ${SPACETIMEDB_URI} deploy_target && \ + spacetime publish --server deploy_target --delete-data=on-conflict ${SPACETIMEDB_DB_NAME} -y