From bfc2f928966144f46b8338c64131acd1e7b6449b Mon Sep 17 00:00:00 2001 From: John Yeo Date: Tue, 17 Jun 2025 19:05:51 +0100 Subject: [PATCH] added localtunnel to setup --- commands.sh | 4 ++-- docker-compose.dev.yml | 17 ++++++++++++++++- docker/dev.dockerfile | 6 ++++++ localtunnel-start.sh | 19 +++++++++++++++++++ server/.env.example | 5 ++--- setup.js | 23 +++++++++++++++++++---- 6 files changed, 64 insertions(+), 10 deletions(-) create mode 100755 localtunnel-start.sh diff --git a/commands.sh b/commands.sh index db2950d37..23a7329de 100644 --- a/commands.sh +++ b/commands.sh @@ -7,10 +7,10 @@ docker compose -f docker-compose.db.yml up --build # Create DB tables pnpm -# docker volume rm autumn-oss_shared-node-modules autumn-oss_root-node-modules autumn-oss_vite-node-modules +# docker volume rm main-repo_shared-node-modules main-repo_root-node-modules main-repo_vite-node-modules # Dev docker compose -f docker-compose.dev.yml down -docker volume rm main-repo_shared-node-modules main-repo_root-node-modules main-repo_vite-node-modules +docker volume rm autumn-oss_shared-node-modules autumn-oss_root-node-modules autumn-oss_vite-node-modules docker compose -f docker-compose.dev.yml build --no-cache docker compose -f docker-compose.dev.yml up --build diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 154f91282..2b4b1c6aa 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,5 +1,5 @@ services: - # Run valkey + valkey: image: docker.io/bitnami/valkey:8.0 environment: @@ -86,6 +86,21 @@ services: - shared restart: unless-stopped + + # Run localtunnel + localtunnel: + image: node:20-alpine + build: + dockerfile: docker/dev.dockerfile + context: . + target: localtunnel + volumes: + - ./server:/app/server + depends_on: + - server + restart: unless-stopped + + volumes: # Shared package dist output shared-dist: diff --git a/docker/dev.dockerfile b/docker/dev.dockerfile index a022fdf97..2e8a86025 100644 --- a/docker/dev.dockerfile +++ b/docker/dev.dockerfile @@ -15,6 +15,12 @@ COPY vite/package*.json ./vite/ RUN pnpm install RUN npm install -g nodemon tsx +# Stage 1: /localtunnel +FROM base AS localtunnel +WORKDIR /app +COPY localtunnel-start.sh ./ +CMD ["sh", "localtunnel-start.sh"] + # Stage 2: /shared FROM base AS shared COPY shared/ ./shared/ diff --git a/localtunnel-start.sh b/localtunnel-start.sh new file mode 100755 index 000000000..ced231b8e --- /dev/null +++ b/localtunnel-start.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Read LOCALTUNNEL_RESERVED_KEY from .env file +if [ -f "/app/server/.env" ]; then + export $(cat /app/server/.env | grep LOCALTUNNEL_RESERVED_KEY) +fi + +# Set default subdomain if env var not found +if [ -z "$LOCALTUNNEL_RESERVED_KEY" ]; then + LOCALTUNNEL_RESERVED_KEY="abcasdjnaslkjdnas" +fi + +echo "LOCALTUNNEL_RESERVED_KEY: ${LOCALTUNNEL_RESERVED_KEY}" + +echo "Installing localtunnel..." +npm install -g localtunnel + +echo "Starting localtunnel..." +lt --port 8080 --local-host server --subdomain ${LOCALTUNNEL_RESERVED_KEY} --print-requests \ No newline at end of file diff --git a/server/.env.example b/server/.env.example index 1ede252c1..11661b1da 100644 --- a/server/.env.example +++ b/server/.env.example @@ -6,10 +6,9 @@ CLIENT_URL=http://localhost:3000 # STRIPE REQUIRED ENCRYPTION_IV= ENCRYPTION_PASSWORD= -SERVER_URL= +STRIPE_WEBHOOK_URL= +LOCALTUNNEL_RESERVED_KEY= # DATABASE DATABASE_URL= -# IF using external redis -# REDIS_URL=redis://valkey:6379 \ No newline at end of file diff --git a/setup.js b/setup.js index b141ab92d..59e9acdcb 100644 --- a/setup.js +++ b/setup.js @@ -243,19 +243,22 @@ const handleLocalRunSetup = async () => { async function main() { // Step 1: Generate secrets console.log(chalk.magentaBright('\n================ Autumn Setup ================\n')); + const localtunnelReservedKey = genRandomSubdomain(32); const secrets = { BETTER_AUTH_SECRET: genUrlSafeBase64(64), ENCRYPTION_IV: genUrlSafeBase64(16), ENCRYPTION_PASSWORD: genUrlSafeBase64(64), BETTER_AUTH_URL: 'http://localhost:8080', CLIENT_URL: 'http://localhost:3000', + LOCALTUNNEL_RESERVED_KEY: localtunnelReservedKey, + STRIPE_WEBHOOK_URL: `https://${localtunnelReservedKey}.loca.lt`, }; let databaseUrl = ""; let stripeWebhookVars = []; databaseUrl = await handleDatabaseSetup(); - stripeWebhookVars = await handleLocalRunSetup(); + // stripeWebhookVars = await handleLocalRunSetup(); // Step 11: Write to server/.env console.log(chalk.magentaBright('\n================ Writing .env ================\n')); @@ -263,15 +266,23 @@ async function main() { // Autumn Auth section envSections.push( - '# Autumn Auth', + '# Auth', `BETTER_AUTH_SECRET=${secrets.BETTER_AUTH_SECRET}`, - `ENCRYPTION_IV=${secrets.ENCRYPTION_IV}`, - `ENCRYPTION_PASSWORD=${secrets.ENCRYPTION_PASSWORD}`, `BETTER_AUTH_URL=${secrets.BETTER_AUTH_URL}`, `CLIENT_URL=${secrets.CLIENT_URL}`, '' ); + // Stripe required section + envSections.push( + '# Stripe', + `LOCALTUNNEL_RESERVED_KEY=${secrets.LOCALTUNNEL_RESERVED_KEY}`, + `ENCRYPTION_IV=${secrets.ENCRYPTION_IV}`, + `ENCRYPTION_PASSWORD=${secrets.ENCRYPTION_PASSWORD}`, + `STRIPE_WEBHOOK_URL=${secrets.STRIPE_WEBHOOK_URL}`, + '' + ); + // Database section if (databaseUrl) { envSections.push( @@ -322,6 +333,10 @@ async function main() { } console.log(chalk.greenBright('✅ Successfully ran "pnpm run db:push".')); } + + console.log(chalk.cyan('\nNext steps:')); + console.log(chalk.cyan('Run the following command to start Autumn:')); + console.log(chalk.cyan(' docker compose -f docker-compose.dev.yml up')); } main(); \ No newline at end of file