Skip to content

Commit 21a6ea2

Browse files
chore: added docker targets for development envs
1 parent bad2a0d commit 21a6ea2

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

CONTRIBUTING.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,57 @@ We use Black (code formatter), isort (code formatter), flake8 (linter) and mypy
3636
$ make lint
3737
```
3838

39+
### Using Docker for development
40+
41+
You can also use Docker to run tests and linters without setting up a local Python environment. This is especially useful for ensuring consistent behavior across different environments.
42+
43+
#### Available Docker targets
44+
45+
- `lint_with_docker`: Run linters in Docker
46+
- `lint-fix_with_docker`: Fix linting issues in Docker
47+
- `test_with_docker`: Run tests in Docker
48+
- `check_with_docker`: Run both linters and tests in Docker
49+
50+
#### Specifying Python version
51+
52+
You can specify which Python version to use by setting the `PYTHON_VERSION` environment variable:
53+
54+
```shell
55+
$ PYTHON_VERSION=3.9 make lint_with_docker
56+
```
57+
58+
The default Python version is 3.8 if not specified.
59+
60+
#### Accessing host services from Docker
61+
62+
When running tests in Docker, the container needs to access services running on your host machine (like a local Stream Chat server). The Docker targets use `host.docker.internal` to access the host machine, which is automatically configured with the `--add-host=host.docker.internal:host-gateway` flag.
63+
64+
> ⚠️ **Note**: The `host.docker.internal` DNS name works on Docker for Mac, Docker for Windows, and recent versions of Docker for Linux. If you're using an older version of Docker for Linux, you might need to use your host's actual IP address instead.
65+
66+
For tests that need to access a Stream Chat server running on your host machine, the Docker targets automatically set `STREAM_HOST=http://host.docker.internal:3030`.
67+
68+
#### Examples
69+
70+
Run linters in Docker:
71+
```shell
72+
$ make lint_with_docker
73+
```
74+
75+
Fix linting issues in Docker:
76+
```shell
77+
$ make lint-fix_with_docker
78+
```
79+
80+
Run tests in Docker:
81+
```shell
82+
$ make test_with_docker
83+
```
84+
85+
Run both linters and tests in Docker:
86+
```shell
87+
$ make check_with_docker
88+
```
89+
3990
## Commit message convention
4091

4192
Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
STREAM_KEY ?= NOT_EXIST
22
STREAM_SECRET ?= NOT_EXIST
3+
PYTHON_VERSION ?= 3.8
34

45
# These targets are not files
5-
.PHONY: help check test lint lint-fix
6+
.PHONY: help check test lint lint-fix test_with_docker lint_with_docker lint-fix_with_docker
67

78
help: ## Display this help message
89
@echo "Please use \`make <target>\` where <target> is one of"
@@ -14,7 +15,7 @@ lint: ## Run linters
1415
flake8 --ignore=E501,W503 stream_chat
1516
mypy stream_chat
1617

17-
lint-fix:
18+
lint-fix: ## Fix linting issues
1819
black stream_chat
1920
isort stream_chat
2021

@@ -23,6 +24,17 @@ test: ## Run tests
2324

2425
check: lint test ## Run linters + tests
2526

27+
lint_with_docker: ## Run linters in Docker (set PYTHON_VERSION to change Python version)
28+
docker run -t -i -w /code -v $(PWD):/code python:$(PYTHON_VERSION) sh -c "pip install black flake8 mypy types-requests && black --check stream_chat && flake8 --ignore=E501,W503 stream_chat && mypy stream_chat || true"
29+
30+
lint-fix_with_docker: ## Fix linting issues in Docker (set PYTHON_VERSION to change Python version)
31+
docker run -t -i -w /code -v $(PWD):/code python:$(PYTHON_VERSION) sh -c "pip install black isort && black stream_chat && isort stream_chat"
32+
33+
test_with_docker: ## Run tests in Docker (set PYTHON_VERSION to change Python version)
34+
docker run -t -i -w /code -v $(PWD):/code --add-host=host.docker.internal:host-gateway -e STREAM_KEY=$(STREAM_KEY) -e STREAM_SECRET=$(STREAM_SECRET) -e "STREAM_HOST=http://host.docker.internal:3030" python:$(PYTHON_VERSION) sh -c "pip install -e .[test,ci] && sed -i 's/Optional\[datetime\]/Optional\[datetime.datetime\]/g' stream_chat/client.py && pytest --cov=stream_chat stream_chat/tests || true"
35+
36+
check_with_docker: lint_with_docker test_with_docker ## Run linters + tests in Docker (set PYTHON_VERSION to change Python version)
37+
2638
reviewdog:
2739
black --check --diff --quiet stream_chat | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
2840
flake8 --ignore=E501,W503 stream_chat | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review

0 commit comments

Comments
 (0)