diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..420e1f64 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "sndev", + "hostRequirements": { + "cpus": 4, + "memory": "16gb", + "storage": "32gb" + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-containers" + ] + } + }, + "containerEnv": { + "CPU_SHARES_IMPORTANT": "1024", + "CPU_SHARES_MODERATE": "512", + "CPU_SHARES_LOW": "128" + }, + "postAttachCommand": "./scripts/setup-codespaces.sh && source .env.local && ./sndev start" +} \ No newline at end of file diff --git a/.devcontainer/minimal/devcontainer.json b/.devcontainer/minimal/devcontainer.json new file mode 100644 index 00000000..d24484d9 --- /dev/null +++ b/.devcontainer/minimal/devcontainer.json @@ -0,0 +1,22 @@ +{ + "name": "sndev MINIMAL", + "hostRequirements": { + "cpus": 4, + "memory": "16gb", + "storage": "32gb" + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-containers" + ] + } + }, + "containerEnv": { + "CPU_SHARES_IMPORTANT": "1024", + "CPU_SHARES_MODERATE": "512", + "CPU_SHARES_LOW": "128", + "COMPOSE_PROFILES": "minimal" + }, + "postAttachCommand": "./scripts/setup-codespaces.sh && source .env.local && ./sndev start" + } \ No newline at end of file diff --git a/README.md b/README.md index 6ba46641..f70f4b8a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,34 @@ Go to [localhost:3000](http://localhost:3000).
+### GitHub Codespaces + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/stackernews/stacker.news) + +You can run Stacker News on Github Codespaces + +#### Setup + +1. Open the repository on GitHub and click the **"Code"** button +2. Select the Codespaces tab and create a new codespace. + - You can also configure your codespace to run select services based on `COMPOSE_PROFILES` as well as in a different region and machine type by clicking "..." and selecting "New with options...". Check [Modifying services](#modifying-services) for more information on `COMPOSE_PROFILES` +3. Wait for the environment to set up (this may take several minutes the first time) +4. Once ready, you'll see a terminal with the environment initialized + +#### Usage + +After the codespace is created, the development environment will be automatically set up and services started. + +Access your running application at the URL shown in the forwarded ports panel (typically `https://your-codespace-name-3000.app.github.dev`). + +#### Port Configuration + +⚠️ **Important**: For various internal services and external access to work properly, you must set forwarded ports to **Public** in the Ports tab: + +1. In your codespace, look for the "PORTS" tab in the bottom panel +2. Click the lock icon to change visibility from "Private" to "Public" +
+ ## Usage Start the development environment @@ -170,6 +198,7 @@ To add/remove DNS records you can now use `./sndev domains dns`. More on this [h # Table of Contents - [Getting started](#getting-started) - [Installation](#installation) + - [GitHub Codespaces](#github-codespaces) - [Usage](#usage) - [Modifying services](#modifying-services) - [Running specific services](#running-specific-services) diff --git a/scripts/setup-codespaces.sh b/scripts/setup-codespaces.sh new file mode 100755 index 00000000..aace3965 --- /dev/null +++ b/scripts/setup-codespaces.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ -z "$CODESPACE_NAME" ]; then + echo "Not in a Codespaces environment, skipping setup" + exit 0 +fi + +echo "Setting up Codespaces environment variables..." + +[ ! -f .env.local ] && touch .env.local && echo "Created .env.local" || echo ".env.local already exists, will preserve existing content" + +declare -A env_vars=( + ["NEXTAUTH_URL"]="https://${CODESPACE_NAME}-3000.app.github.dev/api/auth" + ["NEXT_PUBLIC_MEDIA_URL"]="https://${CODESPACE_NAME}-4566.app.github.dev/uploads" + ["LNAUTH_URL"]="https://${CODESPACE_NAME}-3000.app.github.dev/api/lnauth" + ["LNWITH_URL"]="https://${CODESPACE_NAME}-3000.app.github.dev/api/lnwith" + ["PUBLIC_URL"]="https://${CODESPACE_NAME}-3000.app.github.dev" + ["NEXT_PUBLIC_URL"]="https://${CODESPACE_NAME}-3000.app.github.dev" + ["NEXT_PUBLIC_IMGPROXY_URL"]="https://${CODESPACE_NAME}-3001.app.github.dev" + ["IMGPROXY_ALLOW_ORIGIN"]="https://${CODESPACE_NAME}-3000.app.github.dev" + ["NEXT_PUBLIC_MEDIA_DOMAIN"]="${CODESPACE_NAME}-4566.app.github.dev" +) + +# Remove existing Codespaces-related entries to avoid duplicates +for var in "${!env_vars[@]}"; do + sed -i.bak "/^${var}=/d" .env.local 2>/dev/null || true +done + +# Add Codespaces environment variables +echo "# Codespaces environment variables" >> .env.local +for var in "${!env_vars[@]}"; do + echo "${var}=${env_vars[$var]}" >> .env.local + export "$var"="${env_vars[$var]}" +done + +rm -f .env.local.bak 2>/dev/null || true \ No newline at end of file diff --git a/sndev b/sndev index fa38b2a2..8807d2da 100755 --- a/sndev +++ b/sndev @@ -39,6 +39,8 @@ docker__exec() { sndev__start() { shift + + if [ $# -eq 0 ]; then docker__compose up --build exit 0 @@ -481,6 +483,14 @@ sndev__login() { salt="202c90943c313b829e65e3f29164fb5dd7ea3370d7262c4159691c2f6493bb8b" # upsert user with nym and nym@sndev.team email="$1@sndev.team" + + # Detect Codespaces and set the correct base URL + if [ -n "$CODESPACE_NAME" ]; then + BASE_URL="https://${CODESPACE_NAME}-3000.app.github.dev" + else + BASE_URL="http://localhost:3000" + fi + docker__exec db psql -U sn -d stackernews -q <