Skip to content

Commit

Permalink
root: Ditch host network mode while building containers using compose
Browse files Browse the repository at this point in the history
  • Loading branch information
somnisomni committed Dec 15, 2024
1 parent ad739a2 commit 5c984a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
35 changes: 27 additions & 8 deletions compose-build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/bin/sh
# On Ubuntu 22.04, podman-compose version must be 1.0.6 due to missing of latest podman version.

export GIT_COMMIT_HASH=$(git rev-parse --short HEAD)
COMPOSE=docker-compose
OCI=podman
COMPOSE=$OCI-compose
COMPOSE_FILE=compose.local.yaml
NETWORK_NAME=myboothmanager

if ! command -v $COMPOSE > /dev/null 2>&1; then
if command -v podman-compose > /dev/null 2>&1; then
COMPOSE=podman-compose
else
echo "Error: Neither docker-compose nor podman-compose found."
exit 1
fi
echo "Error: '$COMPOSE' command not found."
exit 1
fi

if ! [ -f "$COMPOSE_FILE" ]; then
Expand All @@ -22,10 +21,30 @@ if ! [ -f "$COMPOSE_FILE" ]; then
fi
fi

if ! $OCI network exists $NETWORK_NAME > /dev/null; then
echo "'$NETWORK_NAME' network not found. Creating..."
NETWORK_CREATE_OUTPUT=$($OCI network create $NETWORK_NAME)

if [ $? -ne 0 ]; then
echo "Error: Failed to create '$NETWORK_NAME' network."
exit 1
fi

if [ -f "$NETWORK_CREATE_OUTPUT" ]; then
echo "Fixing CNI version to 0.4.0..."
sed -i 's/\(\"cniVersion\"\:\) \"\([[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\)\"/\1 \"0.4.0\"/' $NETWORK_CREATE_OUTPUT
else
echo "Warning: Can't fix CNI version because the conflist file is not found: $NETWORK_CREATE_OUTPUT"
echo "Warning: Please fix the CNI version manually. Anyway the process will continue."
fi
fi

echo
echo "=========="
echo "Using compose file: $COMPOSE_FILE"
echo "OCI: $OCI"
echo "Using compose command: $COMPOSE"
echo "Using compose file: $COMPOSE_FILE"
echo "Using network name: $NETWORK_NAME"
echo "=========="
echo

Expand Down
11 changes: 7 additions & 4 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
name: myboothmanager

networks:
default:
name: myboothmanager
external: true

services:
admin:
build:
Expand All @@ -13,8 +20,6 @@ services:
depends_on:
- backend
restart: unless-stopped
network_mode: host # Should ditch host network mode and use bridge mode instead
# But I have to find a way to get rid of errors of CNI network automatically created by podman-compose

public:
build:
Expand All @@ -33,7 +38,6 @@ services:
depends_on:
- backend
restart: unless-stopped
network_mode: host

backend:
build:
Expand All @@ -60,7 +64,6 @@ services:
FRONTEND_ADMIN_URL: "http://localhost:31112"
FRONTEND_PUBLIC_URL: "http://localhost:31113"
restart: unless-stopped
network_mode: host

volumes:
mbm-uploads:

0 comments on commit 5c984a5

Please sign in to comment.