Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dockerize development environment #1308

Merged
merged 6 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
millotp marked this conversation as resolved.
Show resolved Hide resolved
This guide is made for OSX users.
millotp marked this conversation as resolved.
Show resolved Hide resolved

## Install docker

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

## Build the image

```bash
docker build -t algolia-js .
```

## 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--env ALGOLIA_ADMIN_KEY_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.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Dockerfile
FROM node:10-alpine
millotp marked this conversation as resolved.
Show resolved Hide resolved

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

# Needed to compile some npm packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Needed to compile some npm packages
# 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 link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which packages is this needed for? could we avoid them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python3, make, and g++ are required for iltorb, a dependency of bundlesize and rollup-plugin-filesize, so it's dev only but the docker environment is meant for dev.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, could we maybe have a look at updating those versions of bundlesize & rollup-plugin-filesize? if I remember it correctly in their later versions they rely on the node builtin brotli support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking deeper into it only bundlesize is requiring iltorb, but it doesn't seem to be maintained anymore, there is a PR opened for 6 months, and another package that solves that and doesn't require any node-gyp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave it as-is then for now @millotp :)


COPY package.json yarn.lock ./

RUN yarn install

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

WORKDIR /app
COPY . ./