Skip to content

Commit 9288391

Browse files
committed
Introduce DevContainers
Development containers allow to develop projects in a virtualised environment, e.g. with Docker on desktop, or remotely with providers like GitHub Codespaces. This makes it extremely easy for people to contribute to the project, since the environment is already set up for them. The following development containers are introduced with this commit: - `app` - for remote app development in the cloud. It includes a lightweight desktop environment and a VNC client to connect to the desktop remotely and interact with the running app. - `app-local` - for local app development on Linux desktops. Unlike `app`, it does not include desktop environment and relies on desktop forwarding provided by Visual Studio Code. This is only suitable for Linux hosts. - `backend` - for backend development. Features pre-configured database and other components required by Labrinth. - `frontend` - for frontend development. Everything you need to work with Modrinth frontend - Vue, Nuxt and other niceties included. Some Visual Studio Code settings were also revised to remove unmaintained or broken extension recommendations, recommend different useful extensions, as well as declutter the explorer.
1 parent b9d90aa commit 9288391

File tree

13 files changed

+345
-3
lines changed

13 files changed

+345
-3
lines changed

.devcontainer/app-local/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/devcontainers/base:1-bookworm
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev \
5+
build-essential \
6+
curl \
7+
wget \
8+
file \
9+
libxdo-dev \
10+
libssl-dev \
11+
libayatana-appindicator3-dev \
12+
librsvg2-dev \
13+
luakit \
14+
xdg-utils
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "Modrinth (app, local)",
3+
4+
"build": {
5+
"dockerfile": "Dockerfile"
6+
},
7+
8+
"hostRequirements": {
9+
"memory": "12gb"
10+
},
11+
12+
"features": {
13+
"ghcr.io/devcontainers/features/node": {
14+
"version": "20",
15+
"installYarnUsingApt": false,
16+
"pnpmVersion": "none"
17+
},
18+
"ghcr.io/devcontainers/features/rust:1": {}
19+
},
20+
21+
"containerEnv": {
22+
"BROWSER_BASE_URL": "https://api.modrinth.com/v2/",
23+
"DATABASE_URL": "sqlite://${containerWorkspaceFolder}/apps/app/.data/database.db"
24+
},
25+
26+
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/app-shared/setup.sh",
27+
"updateContentCommand": "pnpm install --ignore-scripts && (cd apps/app && cargo fetch) && (cd apps/app-playground && cargo fetch)",
28+
29+
"customizations": {
30+
"vscode": {
31+
"extensions": [
32+
"Vue.volar",
33+
"dbaeumer.vscode-eslint",
34+
"esbenp.prettier-vscode",
35+
"EditorConfig.EditorConfig",
36+
"tauri-apps.tauri-vscode",
37+
"-tamasfe.even-better-toml",
38+
"tombi-toml.tombi"
39+
],
40+
"settings": {
41+
"extensions.ignoreRecommendations": true,
42+
"rust-analyzer.files.exclude": ["apps/daedalus_client", "apps/labrinth"]
43+
}
44+
}
45+
},
46+
47+
"mounts": [
48+
{
49+
"source": "devcontainer-cargo-cache-modrinth",
50+
"target": "/usr/local/cargo",
51+
"type": "volume"
52+
}
53+
]
54+
}

.devcontainer/app-shared/setup.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
npm i -g corepack
5+
6+
corepack enable
7+
8+
COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack install
9+
10+
cargo install --git https://github.com/launchbadge/sqlx sqlx-cli \
11+
--no-default-features --features sqlite,rustls
12+
13+
mkdir -p "$(dirname "${DATABASE_URL#sqlite://}")"
14+
15+
(cd packages/app-lib && cargo sqlx database setup)

.devcontainer/app/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/devcontainers/base:1-bookworm
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev \
5+
build-essential \
6+
curl \
7+
wget \
8+
file \
9+
libxdo-dev \
10+
libssl-dev \
11+
libayatana-appindicator3-dev \
12+
librsvg2-dev \
13+
luakit \
14+
xdg-utils

.devcontainer/app/devcontainer.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "Modrinth (app, remote)",
3+
4+
"build": {
5+
"dockerfile": "Dockerfile"
6+
},
7+
8+
"hostRequirements": {
9+
"memory": "12gb"
10+
},
11+
12+
"features": {
13+
"ghcr.io/devcontainers/features/desktop-lite:1": {},
14+
"ghcr.io/devcontainers/features/node": {
15+
"version": "20",
16+
"installYarnUsingApt": false,
17+
"pnpmVersion": "none"
18+
},
19+
"ghcr.io/devcontainers/features/rust:1": {}
20+
},
21+
22+
"containerEnv": {
23+
"VNC_RESOLUTION": "1600x1000",
24+
"BROWSER_BASE_URL": "https://api.modrinth.com/v2/",
25+
"DATABASE_URL": "sqlite://${containerWorkspaceFolder}/apps/app/.data/database.db"
26+
},
27+
28+
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/app-shared/setup.sh",
29+
"updateContentCommand": "pnpm install --ignore-scripts && (cd apps/app && cargo fetch) && (cd apps/app-playground && cargo fetch)",
30+
31+
"forwardPorts": [6080, 5901],
32+
"portsAttributes": {
33+
"6080": {
34+
"label": "desktop"
35+
},
36+
"5901": {
37+
"label": "vnc"
38+
}
39+
},
40+
41+
"customizations": {
42+
"vscode": {
43+
"extensions": [
44+
"Vue.volar",
45+
"dbaeumer.vscode-eslint",
46+
"esbenp.prettier-vscode",
47+
"EditorConfig.EditorConfig",
48+
"tauri-apps.tauri-vscode",
49+
"-tamasfe.even-better-toml",
50+
"tombi-toml.tombi"
51+
],
52+
"settings": {
53+
"extensions.ignoreRecommendations": true,
54+
"rust-analyzer.files.exclude": ["apps/daedalus_client", "apps/labrinth"]
55+
}
56+
}
57+
},
58+
59+
"mounts": [
60+
{
61+
"source": "devcontainer-cargo-cache-modrinth",
62+
"target": "/usr/local/cargo",
63+
"type": "volume"
64+
}
65+
]
66+
}

.devcontainer/backend/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/devcontainers/base:1-bookworm
2+
3+
RUN apt-get update && \
4+
apt-get install --no-install-recommends -y \
5+
postgresql-client \
6+
libssl-dev \
7+
pkg-config \
8+
liblzma-dev
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "Modrinth (backend)",
3+
4+
"dockerComposeFile": ["../../docker-compose.yml", "docker-compose.yml"],
5+
"service": "labrinth",
6+
"workspaceFolder": "/workspace",
7+
8+
"hostRequirements": {
9+
"memory": "12gb"
10+
},
11+
12+
"features": {
13+
"ghcr.io/devcontainers/features/rust:1": {}
14+
},
15+
16+
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/backend/setup.sh",
17+
"updateContentCommand": "(cd apps/labrinth && cargo fetch)",
18+
19+
"customizations": {
20+
"vscode": {
21+
"extensions": ["EditorConfig.EditorConfig", "-tamasfe.even-better-toml", "tombi-toml.tombi"],
22+
"settings": {
23+
"extensions.ignoreRecommendations": true,
24+
"rust-analyzer.files.exclude": ["apps/app", "apps/app-playground", "packages/app-lib"]
25+
}
26+
}
27+
},
28+
29+
"mounts": [
30+
{
31+
"source": "devcontainer-cargo-cache-modrinth",
32+
"target": "/usr/local/cargo",
33+
"type": "volume"
34+
}
35+
]
36+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
labrinth:
3+
build:
4+
dockerfile: ./.devcontainer/backend/Dockerfile
5+
command: sleep infinity
6+
volumes:
7+
- .:/workspace:cached
8+
depends_on:
9+
- postgres_db
10+
- meilisearch
11+
- redis
12+
- clickhouse
13+
environment:
14+
DATABASE_URL: postgresql://labrinth:labrinth@postgres_db/labrinth
15+
MEILISEARCH_ADDR: http://meilisearch:7700
16+
REDIS_URL: redis://redis
17+
CLICKHOUSE_URL: http://clickhouse:8123
18+
clickhouse:
19+
environment:
20+
- CLICKHOUSE_SKIP_USER_SETUP=1

.devcontainer/backend/setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
cargo install --git https://github.com/launchbadge/sqlx sqlx-cli \
5+
--no-default-features --features postgres,rustls
6+
7+
(cd apps/labrinth && sqlx database setup)
8+
9+
psql "$DATABASE_URL" <<EOF
10+
INSERT INTO loaders VALUES (0, 'placeholder_loader');
11+
INSERT INTO loaders_project_types VALUES (0, 1); -- modloader id, supported type id
12+
INSERT INTO categories VALUES (0, 'placeholder_category', 1); -- category id, category, project type id
13+
EOF
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "Modrinth (frontend)",
3+
4+
"image": "mcr.microsoft.com/devcontainers/base:1-bookworm",
5+
6+
"features": {
7+
"ghcr.io/devcontainers/features/node": {
8+
"version": "20",
9+
"installYarnUsingApt": false,
10+
"pnpmVersion": "none"
11+
}
12+
},
13+
14+
"containerEnv": {
15+
"BROWSER_BASE_URL": "https://api.modrinth.com/v2/"
16+
},
17+
18+
"onCreateCommand": "npm i -g corepack && corepack enable && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack install",
19+
"updateContentCommand": "pnpm install --ignore-scripts && pnpm --filter=@modrinth/frontend postinstall",
20+
21+
"customizations": {
22+
"vscode": {
23+
"extensions": [
24+
"Vue.volar",
25+
"dbaeumer.vscode-eslint",
26+
"esbenp.prettier-vscode",
27+
"EditorConfig.EditorConfig",
28+
"Nuxtr.nuxtr-vscode",
29+
"antfu.goto-alias"
30+
],
31+
"settings": {
32+
"extensions.ignoreRecommendations": true
33+
}
34+
}
35+
},
36+
37+
"appPort": [3000]
38+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ app-playground-data/*
6161
apps/frontend/.env
6262

6363
.astro
64+
65+
.pnpm-store

.vscode/extensions.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
{
2-
"recommendations": ["esbenp.prettier-vscode", "Vue.volar", "rust-lang.rust-analyzer"]
2+
"recommendations": [
3+
// Code style enforcers
4+
"EditorConfig.EditorConfig",
5+
"esbenp.prettier-vscode",
6+
"dbaeumer.vscode-eslint",
7+
// Vue + Nuxt development
8+
"Vue.volar",
9+
"Nuxtr.nuxtr-vscode",
10+
"antfu.goto-alias",
11+
// Rust development
12+
"rust-lang.rust-analyzer",
13+
"tombi-toml.tombi",
14+
"tauri-apps.tauri-vscode"
15+
],
16+
"unwantedRecommendations": [
17+
// Even Better TOML has a memory leak and is unmaintained.
18+
// It is replaced by Tombi.
19+
"tamasfe.even-better-toml"
20+
]
321
}

.vscode/settings.json

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
11
{
2-
"prettier.endOfLine": "lf",
32
"editor.formatOnSave": true,
4-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
53
"editor.codeActionsOnSave": {
64
"source.fixAll.eslint": "explicit"
5+
},
6+
7+
"files.exclude": {
8+
"**/.git": true,
9+
"**/.svn": true,
10+
"**/.hg": true,
11+
"**/.DS_Store": true,
12+
"**/Thumbs.db": true,
13+
"**/.idea": true,
14+
"**/.pnpm-store": true,
15+
"**/.turbo": true,
16+
"**/node_modules": true,
17+
"**/target": true
18+
},
19+
20+
"explorer.fileNesting.enabled": true,
21+
"explorer.fileNesting.patterns": {
22+
"*.ts": "${capture}.js",
23+
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
24+
"*.jsx": "${capture}.js",
25+
"*.tsx": "${capture}.ts",
26+
"tsconfig.json": "tsconfig.*.json",
27+
"package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb, bun.lock, pnpm-workspace.yaml",
28+
"Cargo.toml": "Cargo.lock",
29+
"README.md": "COPYING.md, LICENSE"
30+
},
31+
32+
"prettier.endOfLine": "lf",
33+
34+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
35+
"eslint.run": "onSave",
36+
37+
"[json]": {
38+
"editor.defaultFormatter": "esbenp.prettier-vscode"
39+
},
40+
"[jsonc]": {
41+
"editor.defaultFormatter": "esbenp.prettier-vscode"
42+
},
43+
"[typescript]": {
44+
"editor.defaultFormatter": "esbenp.prettier-vscode"
45+
},
46+
"[javascript]": {
47+
"editor.defaultFormatter": "esbenp.prettier-vscode"
48+
},
49+
"[vue]": {
50+
"editor.defaultFormatter": "esbenp.prettier-vscode"
751
}
852
}

0 commit comments

Comments
 (0)