Skip to content

Commit 7c38e64

Browse files
authored
chore: dockerize development environment (#1308)
1 parent 6223bf6 commit 7c38e64

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules
2+
**/.DS_Store

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ _Note that no new features will be developed or backported for the `vX` branches
6969

7070
## Requirements
7171

72+
### Docker
73+
74+
If you don't want to install dependencies on your host machine, you can follow this [guide](https://github.com/algolia/algoliasearch-client-javascript/blob/master/DOCKER_README.MD) to run code inside a docker container but keep the source files on your favorite IDE.
75+
76+
### Host machine
77+
7278
To run this project, you will need:
7379

7480
- Node.js ≥ 12 (current stable version) – [nvm](https://github.com/creationix/nvm#install-script) is recommended

DOCKER_README.MD

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
In this page you will find our recommended way of installing Docker on your machine.
2+
This guide is made for macOS users.
3+
4+
## Install docker
5+
6+
Install [Docker Desktop](https://docs.docker.com/get-docker/).
7+
8+
## Build the image
9+
10+
```bash
11+
docker build -t algolia-js --build-arg NODE_IMAGE=node:$(cat .nvmrc)-alpine .
12+
```
13+
14+
## Run the image
15+
16+
You need to provide few environment variables at runtime to be able to run the [Common Test Suite](https://github.com/algolia/algoliasearch-client-specs/tree/master/common-test-suite).
17+
You can set them up directly in the command:
18+
19+
```bash
20+
docker run -it --rm --env ALGOLIA_APP_ID=XXXXXX [...] -v $PWD:/app -v /app/node_modules -w /app algolia-js bash
21+
```
22+
23+
However, we advise you to export them in your `.bashrc` or `.zshrc`. That way, you can use [Docker's shorten syntax](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) to set your variables.
24+
25+
```bash
26+
### This is needed only to run the full test suite
27+
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
28+
--env ALGOLIA_ADMIN_KEY_1 \
29+
--env ALGOLIA_SEARCH_KEY_1 \
30+
--env ALGOLIA_APPLICATION_ID_2 \
31+
--env ALGOLIA_ADMIN_KEY_2 \
32+
--env ALGOLIA_APPLICATION_ID_MCM \
33+
--env ALGOLIA_ADMIN_KEY_MCM \
34+
-v $PWD:/app -v /app/node_modules -w /app algolia-js bash
35+
```
36+
37+
Once your container is running, any changes you make in your IDE are directly reflected in the container, except for the `node_modules` folder.
38+
If you want to add or remove packages, you will have to rebuild the image, this is because the `node_modules` folder is installed in a different folder to improve performance.
39+
40+
To launch the tests, you can use one of the following commands
41+
```shell script
42+
# run only the unit tests
43+
yarn test:unit
44+
45+
# run a single test
46+
yarn test:unit nameOfYourTest
47+
```
48+
49+
You can find more commands in the `package.json` file.
50+
51+
Feel free to contact us if you have any questions.

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dockerfile
2+
ARG NODE_IMAGE=node:12.16.0-alpine
3+
4+
FROM $NODE_IMAGE
5+
6+
# Install the dependencies in the parent folder so they don't get overriden by the bind mount
7+
WORKDIR /
8+
9+
# We need to install some dependencies for bundlesize (https://github.com/siddharthkp/bundlesize/pull/370)
10+
RUN apk add --no-cache bash python3 make g++
11+
12+
COPY package.json yarn.lock ./
13+
14+
RUN yarn install
15+
16+
ENV NODE_PATH=/node_modules
17+
ENV PATH=/node_modules/.bin:$PATH
18+
19+
WORKDIR /app
20+
COPY . ./

0 commit comments

Comments
 (0)