Skip to content

Commit

Permalink
chore(docker): containerize repo (#538)
Browse files Browse the repository at this point in the history
* chore(docker): containerize repo

* fix: simplify `Dockerfile`
  • Loading branch information
shortcuts authored Sep 28, 2021
1 parent 2553719 commit 91c60a3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
86 changes: 86 additions & 0 deletions DOCKER_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
In this page you will find our recommended way of installing Docker on your machine.
This guide is made for OSX users.

## Install docker

First install Docker using [Homebrew](https://brew.sh/)

```
$ brew install docker
```

You can then install [Docker Desktop](https://docs.docker.com/get-docker/) if you wish, or use `docker-machine`. As we prefer the second option, we will only document this one.

## Setup your docker

Install `docker-machine`

```
$ brew install docker-machine
```

Then install [VirtualBox](https://www.virtualbox.org/) with [Homebrew Cask](https://github.com/Homebrew/homebrew-cask) to get a driver for your Docker machine

```
$ brew cask install virtualbox
```

You may need to enter your password and authorize the application in your `System Settings` > `Security & Privacy`.

Create now a new machine, set it up as default and connect your shell to it (here we use zsh. The commands should anyway be displayed in each steps' output)

```
$ docker-machine create --driver virtualbox default
$ docker-machine env default
$ eval "$(docker-machine env default)"
```

Now you're all setup to use our provided Docker image!

## Build the image

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

## 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_APPLICATION_ID_1=XXXXXX [...] $PWD:/algoliasearch -w /algoliasearch algolia-python 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_ADMIN_KEY_MCM \
--env ALGOLIA_APPLICATION_ID_MCM \
--env ALGOLIA_ADMIN_KEY_2 \
--env ALGOLIA_APPLICATION_ID_2 \
--env ALGOLIA_SEARCH_KEY_1 \
--env ALGOLIA_ADMIN_KEY_1 \
--env ALGOLIA_APPLICATION_ID_1 \
-v $PWD:/algoliasearch -w /algoliasearch algolia-python bash
```

Once your container is running, any changes you make in your IDE are directly reflected in the container.

To launch the tests, you can use one of the following commands

```shell script
# run format check
tox -e format

# run type check
tox -e types

# run tests for specific version
tox -e py38-sync,py38-async
```

You can find more commands in the [tox.ini](./tox.ini) file or the [circleci config](./.circleci/config.yml).

Feel free to contact us if you have any questions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dockerfile
FROM python:3.8.2

WORKDIR /algoliasearch
ADD . /algoliasearch/

# install dev env dependencies
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# setup dev env

RUN python3 setup.py install
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
## 💡 Getting Started

First, install Algolia Python API Client via the [pip](https://pip.pypa.io/en/stable/installing) package manager:

```bash
pip install --upgrade 'algoliasearch>=2.0,<3.0'
```

Then, create objects on your index:

```py
from algoliasearch.search_client import SearchClient

Expand All @@ -46,6 +48,7 @@ index.save_objects([{'objectID': 1, 'name': 'Foo'}])
```

Finally, you may begin searching a object using the `search` method:

```py
objects = index.search('Fo')
```
Expand All @@ -56,6 +59,10 @@ For full documentation, visit the **[Algolia Python API Client](https://www.algo

Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/python/) where you will find answers for the most common issues and gotchas with the client.

## Use the Dockerfile

If you want to contribute to this project without installing all its dependencies, you can use our Docker image. Please check our [dedicated guide](DOCKER_README.MD) to learn more.

## 📄 License

Algolia Python API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setuptools
tox
mypy
requests
types-requests
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ flake8 = ==3.8.3
black = ==19.10b0
twine = >=1.13,<2.0
wheel = >=0.34,<1.0
requests = ==2.26.0
types-requests = >=2.0,<3.0

[testenv]
deps =
Expand Down Expand Up @@ -45,6 +47,8 @@ commands =
basepython = python3.8
commands = mypy --config-file mypy.ini -p algoliasearch
deps =
requests {[versions]requests}
types-requests{[versions]types-requests}
asyncio {[versions]asyncio}
aiohttp {[versions]aiohttp}
async_timeout {[versions]async_timeout}
Expand Down

0 comments on commit 91c60a3

Please sign in to comment.