Skip to content

Commit 91c60a3

Browse files
authored
chore(docker): containerize repo (#538)
* chore(docker): containerize repo * fix: simplify `Dockerfile`
1 parent 2553719 commit 91c60a3

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

DOCKER_README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
First install Docker using [Homebrew](https://brew.sh/)
7+
8+
```
9+
$ brew install docker
10+
```
11+
12+
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.
13+
14+
## Setup your docker
15+
16+
Install `docker-machine`
17+
18+
```
19+
$ brew install docker-machine
20+
```
21+
22+
Then install [VirtualBox](https://www.virtualbox.org/) with [Homebrew Cask](https://github.com/Homebrew/homebrew-cask) to get a driver for your Docker machine
23+
24+
```
25+
$ brew cask install virtualbox
26+
```
27+
28+
You may need to enter your password and authorize the application in your `System Settings` > `Security & Privacy`.
29+
30+
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)
31+
32+
```
33+
$ docker-machine create --driver virtualbox default
34+
$ docker-machine env default
35+
$ eval "$(docker-machine env default)"
36+
```
37+
38+
Now you're all setup to use our provided Docker image!
39+
40+
## Build the image
41+
42+
```bash
43+
docker build -t algolia-python .
44+
```
45+
46+
## Run the image
47+
48+
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).
49+
You can set them up directly in the command:
50+
51+
```bash
52+
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1=XXXXXX [...] $PWD:/algoliasearch -w /algoliasearch algolia-python bash
53+
```
54+
55+
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.
56+
57+
```bash
58+
### This is needed only to run the full test suite
59+
docker run -it --rm --env ALGOLIA_ADMIN_KEY_MCM \
60+
--env ALGOLIA_APPLICATION_ID_MCM \
61+
--env ALGOLIA_ADMIN_KEY_2 \
62+
--env ALGOLIA_APPLICATION_ID_2 \
63+
--env ALGOLIA_SEARCH_KEY_1 \
64+
--env ALGOLIA_ADMIN_KEY_1 \
65+
--env ALGOLIA_APPLICATION_ID_1 \
66+
-v $PWD:/algoliasearch -w /algoliasearch algolia-python bash
67+
```
68+
69+
Once your container is running, any changes you make in your IDE are directly reflected in the container.
70+
71+
To launch the tests, you can use one of the following commands
72+
73+
```shell script
74+
# run format check
75+
tox -e format
76+
77+
# run type check
78+
tox -e types
79+
80+
# run tests for specific version
81+
tox -e py38-sync,py38-async
82+
```
83+
84+
You can find more commands in the [tox.ini](./tox.ini) file or the [circleci config](./.circleci/config.yml).
85+
86+
Feel free to contact us if you have any questions.

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dockerfile
2+
FROM python:3.8.2
3+
4+
WORKDIR /algoliasearch
5+
ADD . /algoliasearch/
6+
7+
# install dev env dependencies
8+
RUN pip install --upgrade pip && \
9+
pip install -r requirements.txt
10+
# setup dev env
11+
12+
RUN python3 setup.py install

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
## 💡 Getting Started
3232

3333
First, install Algolia Python API Client via the [pip](https://pip.pypa.io/en/stable/installing) package manager:
34+
3435
```bash
3536
pip install --upgrade 'algoliasearch>=2.0,<3.0'
3637
```
3738

3839
Then, create objects on your index:
40+
3941
```py
4042
from algoliasearch.search_client import SearchClient
4143

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

4850
Finally, you may begin searching a object using the `search` method:
51+
4952
```py
5053
objects = index.search('Fo')
5154
```
@@ -56,6 +59,10 @@ For full documentation, visit the **[Algolia Python API Client](https://www.algo
5659

5760
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.
5861

62+
## Use the Dockerfile
63+
64+
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.
65+
5966
## 📄 License
6067

6168
Algolia Python API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
setuptools
2+
tox
3+
mypy
4+
requests
5+
types-requests

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ flake8 = ==3.8.3
1818
black = ==19.10b0
1919
twine = >=1.13,<2.0
2020
wheel = >=0.34,<1.0
21+
requests = ==2.26.0
22+
types-requests = >=2.0,<3.0
2123

2224
[testenv]
2325
deps =
@@ -45,6 +47,8 @@ commands =
4547
basepython = python3.8
4648
commands = mypy --config-file mypy.ini -p algoliasearch
4749
deps =
50+
requests {[versions]requests}
51+
types-requests{[versions]types-requests}
4852
asyncio {[versions]asyncio}
4953
aiohttp {[versions]aiohttp}
5054
async_timeout {[versions]async_timeout}

0 commit comments

Comments
 (0)