Skip to content

Commit 4670006

Browse files
Update default Dockerfile and Services docs (#1265)
1 parent 6697a5f commit 4670006

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

docs/5.advanced/1.docker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ docker-compose up -d --build
105105

106106
## Docker Swarm
107107

108+
Unlike ready-to-use Compose manifest provided by DipDup, Swarm one requires some additional setup.
109+
108110
Scaffolded projects contain a compose file for Docker Swarm. Before spawning this stack create external networks `traefik-public` and `prometheus-private`. Optionally, deploy Traefik and Prometheus and attach them to these networks to get a fully functional stack.
109111

110112
```yaml [deploy/compose.swarm.yaml]

docs/5.advanced/5.services.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,38 @@ async def heavy_stuff(ctx, key: str) -> None:
6565
):
6666
...
6767
68+
```
69+
70+
Note that `ctx` argument is `click.Context` object, not a `dipdup.context.DipDupContext`! If you need deeper integration with DipDup, use the following code:
71+
72+
```python[cli.py]
73+
from dipdup.dipdup import DipDup
74+
from dipdup.context import DipDupContext
75+
76+
77+
dipdup: DipDup = DipDup(ctx.obj.config)
78+
dipdup_ctx: DipDupContext = dipdup._ctx
79+
```
80+
81+
Then create a `__main__.py` file to make the module executable:
82+
83+
```python[__main__.py
84+
from {{ project.package }}.cli import cli
6885
6986
if __name__ == '__main__':
7087
cli(prog_name='dipdup', standalone_mode=True)
7188
```
7289

73-
Then use `python -m {{ project.package }}.cli` instead of `dipdup` as an entrypoint. Now you can call `heavy-stuff` like one of DipDup commands. `dipdup.cli:cli` group handles arguments and config parsing, graceful shutdown, and other boilerplate.
90+
Then use `python -m {{ project.package }}` instead of `dipdup` as an entrypoint. Now you can call `heavy-stuff` like one of DipDup commands. `dipdup.cli:cli` group handles arguments and config parsing, graceful shutdown, and other boilerplate.
7491

7592
```shell [Terminal]
76-
python -m {{ project.package }}.cli heavy-stuff --key value
93+
python -m {{ project.package }} heavy-stuff --key value
7794
```
7895

79-
If your service is long-running, you need to update Dockerfile and Compose manifests. Copy `deploy/Dockerfile` to `deploy/Dockerfile.service` and add the following lines to the end of the file:
96+
If your new command is a long long-running service, you need to update Dockerfile and Compose manifests. Update the `deploy/Dockerfile` to use the new entrypoint:
8097

8198
```dockerfile [deploy/Dockerfile.service]
82-
ENTRYPOINT ["python", "-m", "{{ project.package }}.cli"]
83-
CMD ["heavy-stuff", "--key", "value"]
99+
ENTRYPOINT ["python", "-m", "{{ project.package }}"]
84100
```
85101

86102
For Docker Compose, add a new service to `deploy/compose.yaml`:
@@ -90,7 +106,8 @@ services:
90106
dipdup_service:
91107
build:
92108
context: .
93-
dockerfile: deploy/Dockerfile.service
109+
dockerfile: deploy/Dockerfile
110+
command: ["heavy-stuff", "--key", "value"]
94111
...
95112
```
96113

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{{ header }}
22

3+
#### Uncomment another FROM line to use a different base image
34
FROM dipdup/dipdup:{{ project.dipdup_version }}
45
# FROM ghcr.io/dipdup-io/dipdup:{{ project.dipdup_version }}
56
# FROM ghcr.io/dipdup-io/dipdup:next
67

8+
#### Uncomment lines below if your project requires additional dependencies
79
# COPY --chown=dipdup pyproject.toml README.md .
810
# RUN pip install .
911

12+
#### Uncomment if you have implemented a custom CLI command (see Services in docs)
13+
# ENTRYPOINT ["python", "-m", "{{ project.package }}"]
14+
1015
COPY --chown=dipdup . {{ project.package }}
1116
WORKDIR /home/dipdup/{{ project.package }}

0 commit comments

Comments
 (0)