-
-
Notifications
You must be signed in to change notification settings - Fork 133
add devcontainer config for codespaces #2248
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
Open
brymut
wants to merge
2
commits into
stackernews:master
Choose a base branch
from
brymut:feat/sndev-on-workspaces
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] | ||
email="[email protected]" | ||
|
||
# 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 <<EOF | ||
INSERT INTO users (name) VALUES ('$1') ON CONFLICT DO NOTHING; | ||
UPDATE users SET email = '$email', "emailHash" = encode(digest(LOWER('$email')||'$salt', 'sha256'), 'hex') WHERE name = '$1'; | ||
|
@@ -492,7 +502,7 @@ EOF | |
|
||
echo | ||
echo "open url in browser" | ||
echo "http://localhost:3000/api/auth/callback/email?token=SNDEV-TOKEN&email=$1%40sndev.team" | ||
echo "$BASE_URL/api/auth/callback/email?token=SNDEV-TOKEN&email=$1%40sndev.team" | ||
echo | ||
} | ||
|
||
|
@@ -507,6 +517,29 @@ USAGE | |
echo "$help" | ||
} | ||
|
||
sndev__setup_codespaces() { | ||
shift | ||
./scripts/setup-codespaces.sh | ||
} | ||
|
||
sndev__help_setup_codespaces() { | ||
help=" | ||
setup Codespaces environment variables | ||
|
||
USAGE | ||
$ sndev setup_codespaces | ||
|
||
DESCRIPTION | ||
Creates or updates .env.local with the correct URLs for GitHub Codespaces. | ||
This is automatically run when the Codespace is created. | ||
|
||
REQUIREMENTS | ||
- Set forwarded ports to 'Public' in the Ports tab for external access | ||
" | ||
|
||
echo "$help" | ||
} | ||
|
||
sndev__onion() { | ||
shift | ||
tordir=$(docker__compose ps $1 --format '{{.Label "TORDIR"}}') | ||
|
@@ -636,6 +669,9 @@ COMMANDS | |
login login as a nym | ||
set_balance set the balance of a nym | ||
|
||
codespaces: | ||
setup_codespaces setup environment for GitHub Codespaces | ||
|
||
lightning: | ||
fund pay a bolt11 for funding | ||
withdraw create a bolt11 for withdrawal | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.