Skip to content

Commit 8c194af

Browse files
committed
add devcontainer config for codespaces
1 parent 0436bf6 commit 8c194af

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

.devcontainer/devcontainer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "sndev",
3+
"hostRequirements": {
4+
"cpus": 4,
5+
"memory": "16gb",
6+
"storage": "32gb"
7+
},
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"ms-azuretools.vscode-containers"
12+
]
13+
}
14+
},
15+
"containerEnv": {
16+
"CPU_SHARES_IMPORTANT": "1024",
17+
"CPU_SHARES_MODERATE": "512",
18+
"CPU_SHARES_LOW": "128"
19+
},
20+
"postAttachCommand": "./sndev start"
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "sndev MINIMAL",
3+
"hostRequirements": {
4+
"cpus": 4,
5+
"memory": "16gb",
6+
"storage": "32gb"
7+
},
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"ms-azuretools.vscode-containers"
12+
]
13+
}
14+
},
15+
"containerEnv": {
16+
"CPU_SHARES_IMPORTANT": "1024",
17+
"CPU_SHARES_MODERATE": "512",
18+
"CPU_SHARES_LOW": "128",
19+
"COMPOSE_PROFILES": "minimal"
20+
},
21+
"postAttachCommand": "./sndev start"
22+
}

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,30 @@ To add/remove DNS records you can now use `./sndev domains dns`. More on this [h
167167

168168
<br>
169169

170+
## GitHub Codespaces
171+
172+
<a href='https://codespaces.new/stackernews/stacker.news/tree/master'><img src='https://github.com/codespaces/badge.svg' alt='Open in GitHub Codespaces' style='max-width: 100%;'></a>
173+
174+
You can also develop Stacker News in GitHub Codespaces.
175+
176+
1. **Open in Codespaces**: On the GitHub repository page, either click on the "Open in Github Codespaces" Badge or click on `Code` -> `Codespaces` in the Github UI and select the branch you would like to run the `DEFAULT` sndev Dev container configuration on.
177+
2. **Wait for Setup**: The Codespace will automatically build the dev container and run the `./sndev start` command. This will take a several minutes before the services are ready
178+
4. **Accessing Services**:
179+
* Web application (app): The `app` service runs on port 3000. GitHub Codespaces should automatically forward this port. You can open it from the "Ports" tab in VS Code.
180+
* Other services (database, MailHog, lnbits, etc.): will also be accessible in the ports tab, through their configured ports.
181+
5. **Minimal Profile for Faster Startup**: For a quicker start and less resource usage in Codespaces is available as a separate `MINIMAL` Dev container configuration, that can be selected in step 1.
182+
6. **Using `sndev`**: All other `sndev` commands (`./sndev logs <service>`, `./sndev psql`, `./sndev login <nym>`, etc.) should work as described in this README.
183+
184+
<br/>
185+
170186
# Table of Contents
171187
- [Getting started](#getting-started)
172188
- [Installation](#installation)
173189
- [Usage](#usage)
174190
- [Modifying services](#modifying-services)
175191
- [Running specific services](#running-specific-services)
176192
- [Merging compose files](#merging-compose-files)
193+
- [Github Codespaces](#Github-Codespaces)
177194
- [Contributing](#contributing)
178195
- [We pay bitcoin for contributions](#we-pay-bitcoin-for-contributions)
179196
- [Pull request awards](#pull-request-awards)

sndev

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ sndev__login() {
481481
salt="202c90943c313b829e65e3f29164fb5dd7ea3370d7262c4159691c2f6493bb8b"
482482
# upsert user with nym and nym@sndev.team
483483
email="$1@sndev.team"
484+
485+
# Detect Codespaces and set the correct base URL
486+
if [ -n "$CODESPACE_NAME" ]; then
487+
BASE_URL="https://${CODESPACE_NAME}-3000.app.github.dev"
488+
else
489+
BASE_URL="http://localhost:3000"
490+
fi
491+
484492
docker__exec db psql -U sn -d stackernews -q <<EOF
485493
INSERT INTO users (name) VALUES ('$1') ON CONFLICT DO NOTHING;
486494
UPDATE users SET email = '$email', "emailHash" = encode(digest(LOWER('$email')||'$salt', 'sha256'), 'hex') WHERE name = '$1';
@@ -492,7 +500,7 @@ EOF
492500

493501
echo
494502
echo "open url in browser"
495-
echo "http://localhost:3000/api/auth/callback/email?token=SNDEV-TOKEN&email=$1%40sndev.team"
503+
echo "$BASE_URL/api/auth/callback/email?token=SNDEV-TOKEN&email=$1%40sndev.team"
496504
echo
497505
}
498506

0 commit comments

Comments
 (0)