Skip to content

Commit

Permalink
Merge pull request #2153 from nicomiguelino/update-build-scripts
Browse files Browse the repository at this point in the history
* chore: allow support for building of images from the container upgrade script
* docs: update documentation for building images in Pi or x86
* docs: remove unused how-tos
  • Loading branch information
nicomiguelino authored Dec 11, 2024
2 parents 363e07b + 2db1dc6 commit 5b2aed3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 66 deletions.
10 changes: 8 additions & 2 deletions bin/upgrade_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export MY_IP=$(ip -4 route get 8.8.8.8 | awk {'print $7'} | tr -d '\n')
TOTAL_MEMORY_KB=$(grep MemTotal /proc/meminfo | awk {'print $2'})
export VIEWER_MEMORY_LIMIT_KB=$(echo "$TOTAL_MEMORY_KB" \* 0.8 | bc)
export SHM_SIZE_KB="$(echo "$TOTAL_MEMORY_KB" \* 0.3 | bc | cut -d'.' -f1)"

export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

MODE="${MODE:-pull}"
if [[ ! "$MODE" =~ ^(pull|build)$ ]]; then
echo "Invalid mode: $MODE"
echo "Usage: MODE=(pull|build) $0"
exit 1
fi

if [ -z "$DOCKER_TAG" ]; then
export DOCKER_TAG="latest"
fi
Expand Down Expand Up @@ -52,7 +58,7 @@ fi

sudo -E docker compose \
-f /home/${USER}/screenly/docker-compose.yml \
pull
${MODE}

if [ -f /var/run/reboot-required ]; then
exit 0
Expand Down
71 changes: 7 additions & 64 deletions docs/developer-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,73 +58,16 @@ To stop the development server, run the following:
docker compose -f docker-compose.dev.yml down
```

## Building containers locally
## Building containers on the Raspberry Pi

### Dependencies

#### `buildx`

> [!IMPORTANT]
> Make sure that you have `buildx` installed and that you have run
> `docker buildx create --use` before you run the image build script.
#### Poetry

We have switched from using Bash to [Poetry](https://python-poetry.org/) for building the Docker images.
Make sure that you have Python 3.11 and Poetry installed on your machine.

> [!TIP]
> You can install Poetry by running the following script:
> ```bash
> ./bin/install_poetry.sh
> ```
>
> After running the script, you can add the following to your `~/.bashrc` or similar file:
>
> ```bash
> # Add `pyenv` to the load path.
> export PYENV_ROOT="$HOME/.pyenv"
> [[ -d $PYENV_ROOT/bin ]] && \
> export PATH="$PYENV_ROOT/bin:$PATH"
> eval "$(pyenv init -)"
>
> # Add `poetry to the load path.
> export PATH="$HOME/.local/bin:$PATH"
>
> poetry install --only=docker-image-builder
> ```
>
> You can either restart your terminal or run `source ~/.bashrc` to start using Poetry.
### Building only specific services
Say that you would only like to build the `anthias-server` and `anthias-viewer`
services. Just run the following:
```bash
$ poetry run python tools/image_builder \
--service anthias-server \
--service anthias-viewer
```
### Generating only Dockerfiles

If you'd like to just generate the Dockerfiles from the templates provided
inside the `docker/` directory, run the following:

```bash
$ poetry run python tools/image_builder \
--dockerfiles-only
```

### Disabling cache mounts

If you'd like to disable cache mounts in the generated Dockerfiles, run the
following:
> [!NOTE]
> Make sure that you have Docker installed on the device before proceeding.
```bash
$ poetry run python tools/image_builder \
--disable-cache-mounts
$ ENVIRONMENT=production \
./bin/generate_dev_mode_dockerfiles.sh
$ MODE=build \
./bin/upgrade_containers.sh
```

## Testing
Expand Down

0 comments on commit 5b2aed3

Please sign in to comment.