Skip to content

Commit

Permalink
chore: dockerize development environment (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Oct 12, 2021
1 parent 6223bf6 commit 7c38e64
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
**/.DS_Store
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ _Note that no new features will be developed or backported for the `vX` branches

## Requirements

### Docker

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.

### Host machine

To run this project, you will need:

- Node.js ≥ 12 (current stable version) – [nvm](https://github.com/creationix/nvm#install-script) is recommended
Expand Down
51 changes: 51 additions & 0 deletions DOCKER_README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
In this page you will find our recommended way of installing Docker on your machine.
This guide is made for macOS users.

## Install docker

Install [Docker Desktop](https://docs.docker.com/get-docker/).

## Build the image

```bash
docker build -t algolia-js --build-arg NODE_IMAGE=node:$(cat .nvmrc)-alpine .
```

## Run the image

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).
You can set them up directly in the command:

```bash
docker run -it --rm --env ALGOLIA_APP_ID=XXXXXX [...] -v $PWD:/app -v /app/node_modules -w /app algolia-js bash
```

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.

```bash
### This is needed only to run the full test suite
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
--env ALGOLIA_ADMIN_KEY_1 \
--env ALGOLIA_SEARCH_KEY_1 \
--env ALGOLIA_APPLICATION_ID_2 \
--env ALGOLIA_ADMIN_KEY_2 \
--env ALGOLIA_APPLICATION_ID_MCM \
--env ALGOLIA_ADMIN_KEY_MCM \
-v $PWD:/app -v /app/node_modules -w /app algolia-js bash
```

Once your container is running, any changes you make in your IDE are directly reflected in the container, except for the `node_modules` folder.
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.

To launch the tests, you can use one of the following commands
```shell script
# run only the unit tests
yarn test:unit

# run a single test
yarn test:unit nameOfYourTest
```

You can find more commands in the `package.json` file.

Feel free to contact us if you have any questions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dockerfile
ARG NODE_IMAGE=node:12.16.0-alpine

FROM $NODE_IMAGE

# Install the dependencies in the parent folder so they don't get overriden by the bind mount
WORKDIR /

# We need to install some dependencies for bundlesize (https://github.com/siddharthkp/bundlesize/pull/370)
RUN apk add --no-cache bash python3 make g++

COPY package.json yarn.lock ./

RUN yarn install

ENV NODE_PATH=/node_modules
ENV PATH=/node_modules/.bin:$PATH

WORKDIR /app
COPY . ./

0 comments on commit 7c38e64

Please sign in to comment.