Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,48 @@ services:
CLOUDFLARE_DNS_ZONE: product-os.io
ROBOT_API: https://robot-ws.your-server.de

zram:
image: docker:27.3.1-cli-alpine3.20
restart: no
labels:
io.balena.features.balena-socket: '1'
entrypoint:
- /bin/sh
- -c
environment:
ENABLED: true
ZRAM_PCT: 50
ZRAM_ALGO: lz4
command:
- |
set -e
[[ $ENABLED == 'true' ]] || exit
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bash-specific syntax [[ ]] in a shell script that starts with /bin/sh. Use POSIX-compliant [ ] instead: [ "$ENABLED" = 'true' ] || exit

Suggested change
[[ $ENABLED == 'true' ]] || exit
[ "$ENABLED" = 'true' ] || exit

Copilot uses AI. Check for mistakes.

HOST_CONTAINER_NAME=host-chroot
stop_container() { docker stop "$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")"; }
trap stop_container EXIT

host_cmd() {
if [ -z "$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")" ]; then
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker filter syntax is incorrect. The NAME filter should use name instead of NAME: docker ps -qf "name=$HOST_CONTAINER_NAME"

Suggested change
if [ -z "$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")" ]; then
stop_container() { docker stop "$(docker ps -qf "name=$HOST_CONTAINER_NAME")"; }
trap stop_container EXIT
host_cmd() {
if [ -z "$(docker ps -qf "name=$HOST_CONTAINER_NAME")" ]; then

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker filter syntax is incorrect. The NAME filter should use name instead of NAME: docker ps -qf "name=$HOST_CONTAINER_NAME"

Suggested change
if [ -z "$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")" ]; then
stop_container() { docker stop "$(docker ps -qf "name=$HOST_CONTAINER_NAME")"; }
trap stop_container EXIT
host_cmd() {
if [ -z "$(docker ps -qf "name=$HOST_CONTAINER_NAME")" ]; then

Copilot uses AI. Check for mistakes.
docker run \
--interactive \
--tty=true \
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The --tty=true flag is unnecessary for a detached container that will only receive exec commands. Remove this flag to simplify the configuration.

Suggested change
--tty=true \

Copilot uses AI. Check for mistakes.
--detach \
--rm \
--name="$HOST_CONTAINER_NAME" \
--volume=/:/host \
--privileged \
alpine:3.20.3
fi

HOST_CONTAINER_ID="$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")"
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker filter syntax is incorrect. The NAME filter should use name instead of NAME: docker ps -qf "name=$HOST_CONTAINER_NAME"

Suggested change
HOST_CONTAINER_ID="$(docker ps -qf "NAME=$HOST_CONTAINER_NAME")"
HOST_CONTAINER_ID="$(docker ps -qf "name=$HOST_CONTAINER_NAME")"

Copilot uses AI. Check for mistakes.
docker exec "$HOST_CONTAINER_ID" chroot /host bash -c "$*"
}

host_cmd "swaps=\$(awk 'NR>1 { print \$1 }' /proc/swaps); if [ -n \"\$swaps\" ]; then swapoff \$swaps; fi"
host_cmd "zrams=\$(find /dev -name \"zram*\"); if [ -n \"\$zrams\" ]; then for d in \$zrams; do zramctl -r \$d; done; fi"
zram_dev=$(host_cmd "memtotal=\$(grep MemTotal /proc/meminfo | awk '{ print \$2 }'); zramctl --find --size \$((memtotal * $ZRAM_PCT / 100))K --algorithm $ZRAM_ALGO")
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables $ZRAM_PCT and $ZRAM_ALGO are not validated before use in shell commands, which could lead to command injection. Add validation to ensure they contain only expected values.

Copilot uses AI. Check for mistakes.
host_cmd "mkswap $zram_dev && swapon $zram_dev"
# https://github.com/balenablocks/cert-manager
# https://certbot.eff.org/docs/using.html
# https://certbot-dns-cloudflare.readthedocs.io/
Expand Down
Loading