Skip to content

Commit b760fb1

Browse files
committed
feat: add devcontainer.json
1 parent f6b9e55 commit b760fb1

3 files changed

Lines changed: 168 additions & 25 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"name": "Search-a-licious Development",
3+
"dockerComposeFile": [
4+
"../docker-compose.yml",
5+
"../docker/dev.yml"
6+
],
7+
"service": "api",
8+
"workspaceFolder": "/opt/search",
9+
"shutdownAction": "stopCompose",
10+
"overrideCommand": true,
11+
12+
// Use docker-outside-of-docker feature to allow running docker commands inside the container
13+
"features": {
14+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
15+
"moby": true,
16+
"installDockerBuildx": true,
17+
"version": "latest",
18+
"dockerDashComposeVersion": "v2"
19+
},
20+
"ghcr.io/devcontainers/features/node:1": {
21+
"version": "lts"
22+
}
23+
},
24+
25+
// Configure tool-specific properties
26+
"customizations": {
27+
"vscode": {
28+
"extensions": [
29+
"ms-python.python",
30+
"ms-python.vscode-pylance",
31+
"charliermarsh.ruff",
32+
"ms-azuretools.vscode-docker",
33+
"esbenp.prettier-vscode",
34+
"dbaeumer.vscode-eslint"
35+
],
36+
"settings": {
37+
"python.defaultInterpreterPath": "/opt/pysetup/.venv/bin/python",
38+
"python.testing.pytestEnabled": true,
39+
"python.testing.unittestEnabled": false,
40+
"[python]": {
41+
"editor.defaultFormatter": "charliermarsh.ruff",
42+
"editor.formatOnSave": true,
43+
"editor.codeActionsOnSave": {
44+
"source.organizeImports": "explicit"
45+
}
46+
},
47+
"[typescript]": {
48+
"editor.defaultFormatter": "esbenp.prettier-vscode",
49+
"editor.formatOnSave": true
50+
},
51+
"[javascript]": {
52+
"editor.defaultFormatter": "esbenp.prettier-vscode",
53+
"editor.formatOnSave": true
54+
},
55+
"files.watcherExclude": {
56+
"**/node_modules/**": true,
57+
"**/.venv/**": true,
58+
"**/data/**": true
59+
}
60+
}
61+
}
62+
},
63+
64+
// Forward ports for local development
65+
"forwardPorts": [
66+
8000,
67+
9200,
68+
8080
69+
],
70+
71+
"portsAttributes": {
72+
"8000": {
73+
"label": "FastAPI Backend",
74+
"onAutoForward": "notify"
75+
},
76+
"9200": {
77+
"label": "Elasticsearch",
78+
"onAutoForward": "silent"
79+
},
80+
"8080": {
81+
"label": "ElasticVue",
82+
"onAutoForward": "silent"
83+
}
84+
},
85+
86+
// Lifecycle scripts
87+
"postCreateCommand": "pip install pre-commit && pre-commit install && cd frontend && npm install",
88+
"postStartCommand": "echo '✅ Dev container ready! All services running. Use make commands for development.'",
89+
90+
// Set environment variables
91+
"remoteEnv": {
92+
"ELASTICSEARCH_URL": "http://es01:9200",
93+
"CONFIG_PATH": "/opt/search/data/config/openfoodfacts.yml",
94+
"USER_UID": "${localEnv:USER_UID}",
95+
"USER_GID": "${localEnv:USER_GID}"
96+
},
97+
98+
// Mount the workspace
99+
"mounts": [
100+
"source=${localWorkspaceFolder},target=/opt/search,type=bind,consistency=cached"
101+
],
102+
103+
// Run as the same user that runs the container
104+
"remoteUser": "off",
105+
106+
// Specify which services to start
107+
"runServices": ["es01", "es02", "elasticvue", "api", "search_nodejs"]
108+
}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ Ready to use it ? Jump to the [documentation](https://openfoodfacts.github.io/se
1414

1515
This is an Open Source project and [contributions are very welcome](https://openfoodfacts.github.io/search-a-licious/#contributing) !
1616

17+
## 🚀 Quick Start for Developers
18+
19+
Want to contribute? Get started in minutes with our [Developer Installation Guide](https://openfoodfacts.github.io/search-a-licious/devs/how-to-install/)
1720

1821
## 🎨 Design
1922

2023
- [![Figma](https://img.shields.io/badge/figma-%23F24E1E.svg?logo=figma&logoColor=white) Search-a-Licious logo](https://www.figma.com/design/gNnI56OF91Ugdd4fBaq5F8/Search-A-Licious-Logo?m=auto&t=bEHMawF1eequkY9w-6)
2124
- [![Figma](https://img.shields.io/badge/figma-%23F24E1E.svg?logo=figma&logoColor=white) Wireframes & Mood board](https://www.figma.com/design/d1tuhFa0qQLqqJP2xbwBqZ/Website-%E2%80%93%3E-Search?node-id=1-2&t=bEHMawF1eequkY9w-0)
2225

23-
24-
## Thank you to our sponsors !
26+
## Thank you to our sponsors!
2527

2628
This project has received financial support from the NGI Search (New Generation Internet) program, funded by the 🇪🇺 European Commission. Thank you for supporting Open-Souce, Open Data, and the Commons.
2729

docs/devs/how-to-install.md

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11
# How to install for local development
22

3-
## Pre-requisites
3+
## Option 1: Dev Containers (Recommended)
4+
5+
The easiest way to get started is using Dev Containers, which provides a fully-configured development environment.
6+
7+
### Prerequisites
8+
9+
- [Docker](https://www.docker.com/products/docker-desktop) installed and running
10+
- [VS Code](https://code.visualstudio.com/) with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
11+
- Or use [GitHub Codespaces](https://github.com/features/codespaces) for browser-based development
12+
13+
### Getting Started
14+
15+
1. Clone the repository
16+
2. Open the folder in VS Code
17+
3. When prompted, click "Reopen in Container" (or use the command palette: `Dev Containers: Reopen in Container`)
18+
4. Wait for the container to build (first time takes a few minutes)
19+
5. You're ready to develop! All dependencies are pre-installed.
20+
21+
The dev container automatically:
22+
23+
- Sets up Python 3.11 with Poetry and all backend dependencies
24+
- Installs Node.js LTS with npm and all frontend dependencies
25+
- Configures Docker-in-Docker for running compose commands
26+
- Installs helpful VS Code extensions
27+
- Starts Elasticsearch, Redis, and other services
28+
- Sets up pre-commit hooks
29+
30+
You can now use all `make` commands and start developing immediately. Skip to the [Importing data](#importing-data-into-your-development-environment) section to load sample data.
31+
32+
## Option 2: Manual Installation
33+
34+
### Pre-requisites
435

536
First, follow same [prerequisite as for normal installation](../users/how-to-install.md#prerequisites):
6-
* configuring mmap count
7-
* installing docker and docker compose
837

38+
- configuring mmap count
39+
- installing docker and docker compose
940

1041
## Installing Pre-commit
1142

@@ -16,10 +47,9 @@ to install pre-commit on your machine.
1647

1748
### Auto-fixing linting issues in Pull Requests
1849

19-
For Pull Requests, you can automatically fix linting issues by commenting `/fix-linting` on the PR.
50+
For Pull Requests, you can automatically fix linting issues by commenting `/fix-linting` on the PR.
2051
This will trigger a GitHub Action that runs the linting tools and commits any fixes directly to the PR branch.
2152

22-
2353
## Installing Direnv
2454

2555
Direnv is a tool to automatically set environment variables depending on the current directory.
@@ -30,6 +60,7 @@ For Linux and macOS users, You can follow our tutorial to install [direnv](https
3060
## Setting up your environment
3161

3262
You have several options to set up your environment:
63+
3364
1. use direnv, and thus use the `.envrc` file to set up your environment
3465
2. add a .envrc that you source in your terminal.
3566
3. modify the .env file directly, in which case you should be careful to not commit your changes
@@ -51,10 +82,10 @@ export OFF_API_URL=https://world.openfoodfacts.org
5182

5283
[^winEnvrc]: For Windows users, the .envrc is only taken into account by the `make` commands.
5384

54-
5585
## Building containers
5686

5787
To build the containers, you can run the following command:
88+
5889
```bash
5990
make build
6091
```
@@ -69,38 +100,40 @@ After that run the following command on another shell to compile the project: `m
69100

70101
Do this for next installation steps and to run the project.
71102

72-
73103
> [!NOTE]
74-
> * You may encounter a permission error if your user is not part of the `docker` group, in which case you should either [add it](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) or modify the Makefile to prefix `sudo` to all docker and docker compose commands.
75-
> * Update container crash because we are not connected to any Redis, this is not a problem
104+
>
105+
> - You may encounter a permission error if your user is not part of the `docker` group, in which case you should either [add it](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) or modify the Makefile to prefix `sudo` to all docker and docker compose commands.
106+
> - Update container crash because we are not connected to any Redis, this is not a problem
76107
77108
Docker spins up:
109+
78110
- Two elasticsearch nodes, one being exposed on port 9200 [^localhost_expose]
79-
* test it going to http://127.0.0.1:9200
111+
- test it going to http://127.0.0.1:9200
80112
- [Elasticvue](https://elasticvue.com/) on port 8080
81-
* test it going to http://127.0.0.1:8080
113+
- test it going to http://127.0.0.1:8080
82114
- The search service on port 8000
83-
* test the API going to http://search.localhost:8000/docs
84-
* test the UI going to http://search.localhost:8000/
115+
- test the API going to http://search.localhost:8000/docs
116+
- test the UI going to http://search.localhost:8000/
85117

86-
[^localhost_expose]: by default we only expose on the localhost interface.
87-
This is driven by the `*_EXPOSE` variables in `.env`.
118+
[^localhost_expose]:
119+
by default we only expose on the localhost interface.
120+
This is driven by the `*_EXPOSE` variables in `.env`.
88121

89-
Congratulations, you have successfully installed the project !
122+
Congratulations, you have successfully installed the project !
90123

91124
You will then need to import from a JSONL dump (see instructions below).
92125

93126
## Importing data into your development environment
94127

95128
- Import Taxonomies: `make import-taxonomies`
96129
- Import products :
97-
```bash
98-
# get some sample data
99-
curl https://world.openfoodfacts.org/data/exports/products.random-modulo-10000.jsonl.gz --output data/products.random-modulo-10000.jsonl.gz
100-
gzip -d data/products.random-modulo-10000.jsonl.gz
101-
# we skip updates because we are not connected to any redis
102-
make import-dataset filepath='products.random-modulo-10000.jsonl' args='--skip-updates'
103-
```
130+
```bash
131+
# get some sample data
132+
curl https://world.openfoodfacts.org/data/exports/products.random-modulo-10000.jsonl.gz --output data/products.random-modulo-10000.jsonl.gz
133+
gzip -d data/products.random-modulo-10000.jsonl.gz
134+
# we skip updates because we are not connected to any redis
135+
make import-dataset filepath='products.random-modulo-10000.jsonl' args='--skip-updates'
136+
```
104137

105138
Verify you have data by going to http://search.localhost:8000/
106139

0 commit comments

Comments
 (0)