Skip to content

Commit 7dd6d49

Browse files
chore: update development mode scripts to containerize Poetry and other relevant dependencies (#2144)
1 parent 08a79e6 commit 7dd6d49

6 files changed

+53
-93
lines changed

bin/deploy_to_balena.sh

+3-20
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,6 @@ function prepare_balena_file() {
8888
envsubst > balena-deploy/docker-compose.yml
8989
}
9090

91-
function initialize_python_environment() {
92-
./bin/install_poetry.sh
93-
94-
# Add `pyenv` to the load path.
95-
export PYENV_ROOT="$HOME/.pyenv"
96-
[[ -d $PYENV_ROOT/bin ]] && \
97-
export PATH="$PYENV_ROOT/bin:$PATH"
98-
eval "$(pyenv init -)"
99-
100-
# Add `poetry to the load path.
101-
export PATH="$HOME/.local/bin:$PATH"
102-
103-
poetry install --only=docker-image-builder
104-
}
105-
10691
if ! balena whoami; then
10792
echo "Please login to Balena with `balena login` command, then run this script again."
10893
exit 0
@@ -117,11 +102,9 @@ if [[ -z "${DEV_MODE+x}" ]]; then
117102
else
118103
echo "Running in dev mode..."
119104

120-
initialize_python_environment
121-
poetry run python tools/image_builder \
122-
--dockerfiles-only \
123-
--disable-cache-mounts \
124-
--build-target=${BOARD}
105+
ENVIRONMENT="production" \
106+
BUILD_TARGET="$BOARD" \
107+
bin/generate_dev_mode_dockerfiles.sh
125108

126109
cat docker-compose.balena.dev.yml.tmpl | \
127110
envsubst > docker-compose.yml

bin/generate_dev_mode_dockerfiles.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
BUILDER_DOCKERFILE='docker/Dockerfile.dev'
6+
BUILDER_IMAGE_NAME='anthias-dockerfile-image-builder'
7+
BUILDER_CONTAINER_NAME="${BUILDER_IMAGE_NAME}-instance"
8+
BUILD_TARGET="${BUILD_TARGET:-x86}"
9+
ENVIRONMENT="${ENVIRONMENT:-development}"
10+
11+
docker build \
12+
--pull \
13+
-f "$BUILDER_DOCKERFILE" \
14+
-t "$BUILDER_IMAGE_NAME" .
15+
16+
docker rm -f "$BUILDER_CONTAINER_NAME" || true
17+
docker run \
18+
--rm \
19+
--name="$BUILDER_CONTAINER_NAME" \
20+
-v "$(pwd):/app" \
21+
"$BUILDER_IMAGE_NAME" \
22+
poetry run python -m tools.image_builder \
23+
--environment="$ENVIRONMENT" \
24+
--dockerfiles-only \
25+
--disable-cache-mounts \
26+
--build-target="$BUILD_TARGET"

bin/install_poetry.sh

-48
This file was deleted.

bin/start_development_server.sh

+1-23
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,7 @@ COMPOSE_ARGS=(
66
'-f' 'docker-compose.dev.yml'
77
)
88

9-
function initialize_python_environment() {
10-
./bin/install_poetry.sh
9+
bin/generate_dev_mode_dockerfiles.sh
1110

12-
# Add `pyenv` to the load path.
13-
export PYENV_ROOT="$HOME/.pyenv"
14-
[[ -d $PYENV_ROOT/bin ]] && \
15-
export PATH="$PYENV_ROOT/bin:$PATH"
16-
eval "$(pyenv init -)"
17-
18-
# Add `poetry to the load path.
19-
export PATH="$HOME/.local/bin:$PATH"
20-
21-
poetry install --only=docker-image-builder
22-
}
23-
24-
function generate_dockerfiles() {
25-
poetry run python tools/image_builder \
26-
--environment=development \
27-
--dockerfiles-only \
28-
--disable-cache-mounts
29-
}
30-
31-
initialize_python_environment
32-
generate_dockerfiles
3311
docker compose "${COMPOSE_ARGS[@]}" down
3412
docker compose "${COMPOSE_ARGS[@]}" up -d --build

docker/Dockerfile.dev

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.11-bookworm
2+
3+
RUN apt-get update -y && \
4+
curl -sSL https://install.python-poetry.org | python3 - && \
5+
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
6+
7+
WORKDIR /app
8+
9+
COPY pyproject.toml poetry.lock /app/
10+
11+
RUN poetry install --only=docker-image-builder
12+
RUN git config --global --add safe.directory /app

docs/developer-documentation.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ These components and their dependencies are mostly installed and handled with An
2121
To simplify development of the server module of Anthias, we've created a Docker container. This is intended to run on your local machine with the Anthias repository mounted as a volume.
2222

2323
> [!IMPORTANT]
24-
> Anthias is using Docker's [buildx](https://docs.docker.com/engine/reference/commandline/buildx/) for the image builds. This is used both for cross compilation as well as for local caching. You might need to run `docker buildx create --use` first.
24+
> * Make sure that you have [installed Docker](https://docs.docker.com/engine/install/) on your machine before proceeding.
25+
> * Anthias is using Docker's [buildx](https://docs.docker.com/engine/reference/commandline/buildx/) for the image builds. This is used both for cross compilation as well as for local caching. You might need to run `docker buildx create --use` first.
2526
2627
Assuming you're in the source code repository, simply run:
2728

@@ -40,7 +41,15 @@ $ ./bin/start_development_server.sh
4041
✔ Container anthias-anthias-nginx-1 Started 0.5s
4142
```
4243

43-
Running the command above will start the development server and you should be able to
44+
> [!NOTE]
45+
> Running the script will install Python 3.11, [pyenv](https://github.com/pyenv/pyenv),
46+
> and [Poetry](https://python-poetry.org/) inside a Docker container on your machine.
47+
> This is to ensure that the development environment is consistent across different
48+
> machines.
49+
>
50+
> The script currently supports Debian-based systems and macOS.
51+
52+
unning the command above will start the development server and you should be able to
4453
access the web interface at `http://localhost:8000`.
4554

4655
To stop the development server, run the following:

0 commit comments

Comments
 (0)