Skip to content

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
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": "./sndev start"
}
22 changes: 22 additions & 0 deletions .devcontainer/minimal/devcontainer.json
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": "./sndev start"
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,30 @@ To add/remove DNS records you can now use `./sndev domains dns`. More on this [h

<br>

## GitHub Codespaces

<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>

You can also develop Stacker News in GitHub Codespaces.

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.
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
4. **Accessing Services**:
* 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.
* Other services (database, MailHog, lnbits, etc.): will also be accessible in the ports tab, through their configured ports.
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.
6. **Using `sndev`**: All other `sndev` commands (`./sndev logs <service>`, `./sndev psql`, `./sndev login <nym>`, etc.) should work as described in this README.

<br/>

# Table of Contents
- [Getting started](#getting-started)
- [Installation](#installation)
- [Usage](#usage)
- [Modifying services](#modifying-services)
- [Running specific services](#running-specific-services)
- [Merging compose files](#merging-compose-files)
- [Github Codespaces](#Github-Codespaces)
- [Contributing](#contributing)
- [We pay bitcoin for contributions](#we-pay-bitcoin-for-contributions)
- [Pull request awards](#pull-request-awards)
Expand Down
10 changes: 9 additions & 1 deletion sndev
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,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 <<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';
Expand All @@ -492,7 +500,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
}

Expand Down