Skip to content

Commit 9c76052

Browse files
committed
Add devenv based Code Spaces support
1 parent c3676f6 commit 9c76052

File tree

11 files changed

+314
-0
lines changed

11 files changed

+314
-0
lines changed

.devcontainer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"customizations": {
3+
"vscode": {
4+
"extensions": [
5+
"charliermarsh.ruff",
6+
"ms-vscode.makefile-tools",
7+
"bbenoist.Nix"
8+
]
9+
}
10+
},
11+
"image": "ghcr.io/cachix/devenv:v1.3.1",
12+
"overrideCommand": false,
13+
"updateContentCommand": "make codespace-install",
14+
"portsAttributes": {
15+
"3000": {
16+
"label": "frontend"
17+
},
18+
"3001": {
19+
"label": "webpack"
20+
},
21+
"8000": {
22+
"label": "proxy"
23+
},
24+
"8080": {
25+
"label": "backend"
26+
}
27+
}
28+
}

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CODESPACE_NAME=
2+
GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ node_modules
33
/core
44
/public
55
*.mo
6+
.env
67
.pytest_cache
8+
.devenv*
9+
devenv.local.nix

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,15 @@ ci-acceptance-test:
232232
pnpm dlx wait-on --httpTimeout 20000 http-get://localhost:55001/plone http://localhost:3000
233233
$(MAKE) -C "./frontend/" ci-acceptance-test
234234
$(MAKE) acceptance-containers-stop
235+
236+
.env:
237+
@echo CODESPACE_NAME=$$CODESPACE_NAME >.env
238+
@echo GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=$$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN >>.env
239+
240+
.PHONY:
241+
codespace-install: .env
242+
@devenv shell -- echo "Ok."
243+
244+
.PHONY:
245+
codespace-start: .env ## Start services at GitHub Codespaces
246+
@devenv up

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ Generate translation files for Plone and Volto with ease:
142142
make i18n
143143
```
144144
145+
## GitHub Codespaces
146+
147+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/collective/tech-event)
148+
149+
This repository has experimental support for developing with GitHub Codespaces. Its [Devenv](https://devenv.sh) based setup requires a few minutes to build and start up for the first time. First the space is ready, developed site could be started with:
150+
151+
```shell
152+
make codespace-start
153+
```
154+
155+
This will eventually start a proxied site at Codespaces port 8000, with its backend proxied at path /api. If your browser keeps reloading the proxied site, please, stop your local Volto or other Webpack development server first.
156+
145157
## Credits and Acknowledgements 🙏
146158
147159
Generated using [Cookieplone (0.9.7)](https://github.com/plone/cookieplone) and [cookieplone-templates (27a6b7b)](https://github.com/plone/cookieplone-templates/commit/27a6b7bd7b0ba9a77b04109d73c4ee975ab95cc3) on 2025-05-13 21:27:39.934395. A special thanks to all contributors and supporters!

backend/devenv.nix

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{ pkgs, ... }:
2+
{
3+
tasks = {
4+
"bash:backend:install" = {
5+
exec = ''
6+
UV_PROJECT_ENVIRONMENT=$(pwd)/backend/.venv
7+
UV_PYTHON_DOWNLOADS=never
8+
UV_PYTHON_PREFERENCE=system
9+
if [[ ! -e backend/instance ]]; then
10+
make -C backend install
11+
make -C backend create-site
12+
fi
13+
'';
14+
before = [
15+
"devenv:enterShell"
16+
];
17+
};
18+
};
19+
20+
languages.python = {
21+
enable = true;
22+
package = pkgs.python312;
23+
uv = {
24+
enable = true;
25+
package = pkgs.uv;
26+
};
27+
};
28+
29+
packages = [ pkgs.ruff ];
30+
31+
enterShell = ''
32+
export UV_PROJECT_ENVIRONMENT=$(pwd)/backend/.venv
33+
export UV_PYTHON_DOWNLOADS=never
34+
export UV_PYTHON_PREFERENCE=system
35+
'';
36+
}

devenv.local.nix.example

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ lib, ... }:
2+
{
3+
services.caddy = {
4+
config = lib.mkForce ''
5+
{
6+
admin off
7+
}
8+
:8000 {
9+
reverse_proxy /ws* localhost:3001
10+
handle_path "/++razzle++*" {
11+
rewrite * /++razzle++{uri}
12+
reverse_proxy localhost:3001
13+
}
14+
handle_path "/++api++*" {
15+
rewrite * /VirtualHostBase/http/localhost:8000/Plone/++api++/VirtualHostRoot{uri}
16+
reverse_proxy localhost:8080
17+
}
18+
handle_path "/api*" {
19+
rewrite * /VirtualHostBase/http/localhost:8000/Plone/VirtualHostRoot/_vh_api{uri}
20+
reverse_proxy localhost:8080
21+
}
22+
reverse_proxy http://localhost:3000
23+
}
24+
'';
25+
};
26+
27+
process.managers.process-compose.settings.environment = lib.mkForce [
28+
"RAZZLE_INTERNAL_API_PATH=http://localhost:8080/VirtualHostBase/http/localhost:8000/Plone/VirtualHostRoot"
29+
"RAZZLE_API_PATH=http://localhost:8000"
30+
"CLIENT_PUBLIC_PATH=http://localhost:8000/++razzle++"
31+
];
32+
33+
# See full reference at https://devenv.sh/reference/options/
34+
}

devenv.lock

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1754404745,
7+
"owner": "cachix",
8+
"repo": "devenv",
9+
"rev": "6563b21105168f90394dfaf58284b078af2d7275",
10+
"type": "github"
11+
},
12+
"original": {
13+
"dir": "src/modules",
14+
"owner": "cachix",
15+
"repo": "devenv",
16+
"type": "github"
17+
}
18+
},
19+
"flake-compat": {
20+
"flake": false,
21+
"locked": {
22+
"lastModified": 1747046372,
23+
"owner": "edolstra",
24+
"repo": "flake-compat",
25+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
26+
"type": "github"
27+
},
28+
"original": {
29+
"owner": "edolstra",
30+
"repo": "flake-compat",
31+
"type": "github"
32+
}
33+
},
34+
"git-hooks": {
35+
"inputs": {
36+
"flake-compat": "flake-compat",
37+
"gitignore": "gitignore",
38+
"nixpkgs": [
39+
"nixpkgs"
40+
]
41+
},
42+
"locked": {
43+
"lastModified": 1750779888,
44+
"owner": "cachix",
45+
"repo": "git-hooks.nix",
46+
"rev": "16ec914f6fb6f599ce988427d9d94efddf25fe6d",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "cachix",
51+
"repo": "git-hooks.nix",
52+
"type": "github"
53+
}
54+
},
55+
"gitignore": {
56+
"inputs": {
57+
"nixpkgs": [
58+
"git-hooks",
59+
"nixpkgs"
60+
]
61+
},
62+
"locked": {
63+
"lastModified": 1709087332,
64+
"owner": "hercules-ci",
65+
"repo": "gitignore.nix",
66+
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
67+
"type": "github"
68+
},
69+
"original": {
70+
"owner": "hercules-ci",
71+
"repo": "gitignore.nix",
72+
"type": "github"
73+
}
74+
},
75+
"nixpkgs": {
76+
"locked": {
77+
"lastModified": 1754407206,
78+
"owner": "nixos",
79+
"repo": "nixpkgs",
80+
"rev": "be2b8ea3d483604d3cd874aded945807a2594338",
81+
"type": "github"
82+
},
83+
"original": {
84+
"owner": "nixos",
85+
"ref": "master",
86+
"repo": "nixpkgs",
87+
"type": "github"
88+
}
89+
},
90+
"root": {
91+
"inputs": {
92+
"devenv": "devenv",
93+
"git-hooks": "git-hooks",
94+
"nixpkgs": "nixpkgs",
95+
"pre-commit-hooks": [
96+
"git-hooks"
97+
]
98+
}
99+
}
100+
},
101+
"root": "root",
102+
"version": 7
103+
}

devenv.nix

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{ pkgs, config, ... }:
2+
{
3+
dotenv.enable = true;
4+
5+
services.caddy = {
6+
enable = true;
7+
config = ''
8+
{
9+
admin off
10+
}
11+
:8000 {
12+
reverse_proxy /ws* localhost:3001
13+
handle_path "/++razzle++*" {
14+
rewrite * /++razzle++{uri}
15+
reverse_proxy localhost:3001
16+
}
17+
handle_path "/++api++*" {
18+
rewrite * /VirtualHostBase/https/${config.env.CODESPACE_NAME}-8000.${config.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}:443/Plone/++api++/VirtualHostRoot{uri}
19+
reverse_proxy localhost:8080
20+
}
21+
handle_path "/api*" {
22+
rewrite * /VirtualHostBase/https/${config.env.CODESPACE_NAME}-8000.${config.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}:443/Plone/VirtualHostRoot/_vh_api{uri}
23+
reverse_proxy localhost:8080
24+
}
25+
reverse_proxy http://localhost:3000
26+
}
27+
'';
28+
};
29+
30+
processes = {
31+
backend.exec = "make -C backend start";
32+
frontend.exec = "make -C frontend start";
33+
};
34+
35+
process.managers.process-compose.settings.environment = [
36+
"RAZZLE_INTERNAL_API_PATH=http://localhost:8080/VirtualHostBase/https/${config.env.CODESPACE_NAME}-8000.${config.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}:443/Plone/VirtualHostRoot"
37+
"RAZZLE_API_PATH=https://${config.env.CODESPACE_NAME}-8000.${config.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
38+
"CLIENT_PUBLIC_PATH=https://${config.env.CODESPACE_NAME}-8000.${config.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/++razzle++"
39+
];
40+
41+
# See full reference at https://devenv.sh/reference/options/
42+
}

devenv.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
2+
inputs:
3+
nixpkgs:
4+
url: github:nixos/nixpkgs/master
5+
imports:
6+
- ./backend
7+
- ./frontend

0 commit comments

Comments
 (0)