Skip to content

Commit e600b36

Browse files
committed
chore: dockerize development environment
1 parent 00ad924 commit e600b36

File tree

3 files changed

+71
-0
lines changed

3 files changed

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

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 OSX 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 .
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Dockerfile
2+
FROM node:10-alpine
3+
4+
# Install the dependencies in the parent folder so they don't get overriden by the bind mount
5+
WORKDIR /
6+
7+
# Needed to compile some npm packages
8+
RUN apk add --no-cache bash python3 make g++
9+
10+
COPY package.json yarn.lock ./
11+
12+
RUN yarn install
13+
14+
ENV NODE_PATH=/node_modules
15+
ENV PATH=/node_modules/.bin:$PATH
16+
17+
WORKDIR /app
18+
COPY . ./

0 commit comments

Comments
 (0)