Migration to podman. Dev is OK, certificate problem with test

This commit is contained in:
Josako
2025-08-12 06:33:17 +02:00
parent 866cc2a60d
commit 7e35549262
5 changed files with 426 additions and 360 deletions

View File

@@ -3,19 +3,29 @@
# Exit on any error
set -e
source ./docker_env_switch.sh dev
source ./podman_env_switch.sh dev
# Load environment variables
source .env
# Docker registry
REGISTRY="josakola"
# Check if podman is available
if ! command -v podman &> /dev/null; then
echo "Error: podman not found"
exit 1
fi
echo "Using container runtime: podman"
# Local registry
REGISTRY="registry.ask-eve-ai-local.com"
# Account prefix voor consistency met Docker Hub
ACCOUNT="josakola"
# Tag (you might want to use a version or git commit hash)
TAG="latest"
# Platforms to build for
PLATFORMS="linux/amd64,linux/arm64"
# Single platform - AMD64 only for simplicity
PLATFORM="linux/amd64"
# Default action
ACTION="both"
@@ -28,13 +38,14 @@ DEBUG=""
# Function to display usage information
usage() {
echo "Usage: $0 [-b|-p] [--no-cache] [--progress=plain] [--debug] [service1 service2 ...]"
echo " -b: Build only (for current platform)"
echo " -p: Push only (multi-platform)"
echo " -b: Build only"
echo " -p: Push only"
echo " --no-cache: Perform a clean build without using cache"
echo " --progress=plain: Show detailed progress of the build"
echo " --debug: Enable debug mode for the build"
echo " If no option is provided, both build and push will be performed."
echo " If no services are specified, all eveai_ services and nginx will be processed."
echo " All images are built for AMD64 platform (compatible with both x86_64 and Apple Silicon via emulation)."
}
# Parse command-line options
@@ -92,47 +103,57 @@ process_service() {
return 1
fi
# Construct image names
LOCAL_IMAGE_NAME="$ACCOUNT/$SERVICE:$TAG"
REGISTRY_IMAGE_NAME="$REGISTRY/$ACCOUNT/$SERVICE:$TAG"
echo "Building for platform: $PLATFORM"
echo "Local tag: $LOCAL_IMAGE_NAME"
echo "Registry tag: $REGISTRY_IMAGE_NAME"
# Build and/or push based on ACTION
if [ "$ACTION" = "build" ]; then
echo "Building $SERVICE for current platform..."
docker build \
echo "Building $SERVICE for $PLATFORM..."
podman build \
--platform "$PLATFORM" \
$NO_CACHE \
$PROGRESS \
$DEBUG \
-t "$REGISTRY/$SERVICE:$TAG" \
-f "$CONTEXT/$DOCKERFILE" \
"$CONTEXT"
elif [ "$ACTION" = "push" ]; then
echo "Building and pushing $SERVICE for multiple platforms..."
docker buildx build \
$NO_CACHE \
$PROGRESS \
$DEBUG \
--platform "$PLATFORMS" \
-t "$REGISTRY/$SERVICE:$TAG" \
-f "$CONTEXT/$DOCKERFILE" \
"$CONTEXT" \
--push
else
echo "Building $SERVICE for current platform..."
docker build \
$NO_CACHE \
$PROGRESS \
$DEBUG \
-t "$REGISTRY/$SERVICE:$TAG" \
-t "$LOCAL_IMAGE_NAME" \
-t "$REGISTRY_IMAGE_NAME" \
-f "$CONTEXT/$DOCKERFILE" \
"$CONTEXT"
echo "Building and pushing $SERVICE for multiple platforms..."
docker buildx build \
elif [ "$ACTION" = "push" ]; then
echo "Building and pushing $SERVICE for $PLATFORM..."
podman build \
--platform "$PLATFORM" \
$NO_CACHE \
$PROGRESS \
$DEBUG \
--platform "$PLATFORMS" \
-t "$REGISTRY/$SERVICE:$TAG" \
-t "$LOCAL_IMAGE_NAME" \
-t "$REGISTRY_IMAGE_NAME" \
-f "$CONTEXT/$DOCKERFILE" \
"$CONTEXT" \
--push
"$CONTEXT"
echo "Pushing $SERVICE to registry..."
podman push "$REGISTRY_IMAGE_NAME"
else
# Both build and push
echo "Building $SERVICE for $PLATFORM..."
podman build \
--platform "$PLATFORM" \
$NO_CACHE \
$PROGRESS \
$DEBUG \
-t "$LOCAL_IMAGE_NAME" \
-t "$REGISTRY_IMAGE_NAME" \
-f "$CONTEXT/$DOCKERFILE" \
"$CONTEXT"
echo "Pushing $SERVICE to registry..."
podman push "$REGISTRY_IMAGE_NAME"
fi
}
@@ -146,31 +167,25 @@ else
SERVICES=("$@")
fi
# Check if eveai_builder exists, if not create it
if ! docker buildx inspect eveai_builder > /dev/null 2>&1; then
echo "Creating eveai_builder..."
docker buildx create --name eveai_builder
fi
# Use eveai_builder
echo "Using eveai_builder..."
docker buildx use eveai_builder
echo "Using simplified AMD64-only approach for maximum compatibility..."
echo "Images will be tagged as: $REGISTRY/$ACCOUNT/[service]:$TAG"
# Loop through services
for SERVICE in "${SERVICES[@]}"; do
if [[ "$SERVICE" == "nginx" ]]; then
./copy_specialist_svgs.sh ../config ../nginx/static/assets
./copy_specialist_svgs.sh ../config ../nginx/static/assets 2>/dev/null || echo "Warning: copy_specialist_svgs.sh not found or failed"
fi
if [[ "$SERVICE" == "nginx" || "$SERVICE" == eveai_* || "$SERVICE" == "flower" || "$SERVICE" == "prometheus" || "$SERVICE" == "grafana" ]]; then
if process_service "$SERVICE"; then
echo "Successfully processed $SERVICE"
echo "Successfully processed $SERVICE"
else
echo "Failed to process $SERVICE"
echo "Failed to process $SERVICE"
fi
else
echo "Skipping $SERVICE as it's not nginx, flower, prometheus, grafana or doesn't start with eveai_"
echo "⏭️ Skipping $SERVICE as it's not nginx, flower, prometheus, grafana or doesn't start with eveai_"
fi
done
echo -e "\033[35mAll specified services processed.\033[0m"
echo -e "\033[35mFinished at $(date +"%d/%m/%Y %H:%M:%S")\033[0m"
echo -e "\033[32m✅ All specified services processed successfully!\033[0m"
echo -e "\033[32m📦 Images are available locally and in registry\033[0m"
echo -e "\033[32m🕐 Finished at $(date +"%d/%m/%Y %H:%M:%S")\033[0m"

View File

@@ -1,13 +1,4 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker Compose reference guide at
# https://docs.docker.com/go/compose-spec-reference/
# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
# Podman Compose compatible versie met port schema compliance
x-common-variables: &common-variables
DB_HOST: db
DB_USER: luke
@@ -45,16 +36,13 @@ x-common-variables: &common-variables
services:
nginx:
container_name: nginx
image: josakola/nginx:latest
build:
context: ..
dockerfile: ./docker/nginx/Dockerfile
platforms:
- linux/amd64
- linux/arm64
ports:
- 80:80
- 8080:8080
- 3002:80 # Dev nginx proxy volgens port schema
environment:
<<: *common-variables
volumes:
@@ -72,18 +60,16 @@ services:
- eveai_api
- eveai_chat_client
networks:
- eveai-network
- eveai-dev-network
eveai_app:
container_name: eveai_app
image: josakola/eveai_app:latest
build:
context: ..
dockerfile: ./docker/eveai_app/Dockerfile
platforms:
- linux/amd64
- linux/arm64
ports:
- 5001:5001
- 3000:5001 # Dev app volgens port schema
expose:
- 8000
environment:
@@ -108,20 +94,18 @@ services:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5001/healthz/ready"]
interval: 30s
timeout: 1s
timeout: 10s
retries: 3
start_period: 30s
start_period: 60s
networks:
- eveai-network
- eveai-dev-network
eveai_workers:
container_name: eveai_workers
image: josakola/eveai_workers:latest
build:
context: ..
dockerfile: ./docker/eveai_workers/Dockerfile
platforms:
- linux/amd64
- linux/arm64
expose:
- 8000
environment:
@@ -142,18 +126,16 @@ services:
minio:
condition: service_healthy
networks:
- eveai-network
- eveai-dev-network
eveai_chat_client:
container_name: eveai_chat_client
image: josakola/eveai_chat_client:latest
build:
context: ..
dockerfile: ./docker/eveai_chat_client/Dockerfile
platforms:
- linux/amd64
- linux/arm64
ports:
- 5004:5004
- 3004:5004 # Dev chat client volgens port schema
expose:
- 8000
environment:
@@ -176,20 +158,18 @@ services:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5004/healthz/ready"]
interval: 30s
timeout: 1s
timeout: 10s
retries: 3
start_period: 30s
start_period: 60s
networks:
- eveai-network
- eveai-dev-network
eveai_chat_workers:
container_name: eveai_chat_workers
image: josakola/eveai_chat_workers:latest
build:
context: ..
dockerfile: ./docker/eveai_chat_workers/Dockerfile
platforms:
- linux/amd64
- linux/arm64
expose:
- 8000
environment:
@@ -208,26 +188,21 @@ services:
redis:
condition: service_healthy
networks:
- eveai-network
- eveai-dev-network
eveai_api:
container_name: eveai_api
image: josakola/eveai_api:latest
build:
context: ..
dockerfile: ./docker/eveai_api/Dockerfile
platforms:
- linux/amd64
- linux/arm64
ports:
- 5003:5003
- 3001:5003 # Dev API volgens port schema
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_api
WORDPRESS_HOST: host.docker.internal
WORDPRESS_PORT: 10003
WORDPRESS_PROTOCOL: http
volumes:
- ../eveai_api:/app/eveai_api
- ../common:/app/common
@@ -245,20 +220,18 @@ services:
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:5003/healthz/ready" ]
interval: 30s
timeout: 1s
timeout: 10s
retries: 3
start_period: 30s
start_period: 60s
networks:
- eveai-network
- eveai-dev-network
eveai_beat:
container_name: eveai_beat
image: josakola/eveai_beat:latest
build:
context: ..
dockerfile: ./docker/eveai_beat/Dockerfile
platforms:
- linux/amd64
- linux/arm64
environment:
<<: *common-variables
COMPONENT_NAME: eveai_beat
@@ -273,16 +246,14 @@ services:
redis:
condition: service_healthy
networks:
- eveai-network
- eveai-dev-network
eveai_entitlements:
container_name: eveai_entitlements
image: josakola/eveai_entitlements:latest
build:
context: ..
dockerfile: ./docker/eveai_entitlements/Dockerfile
platforms:
- linux/amd64
- linux/arm64
expose:
- 8000
environment:
@@ -303,13 +274,14 @@ services:
minio:
condition: service_healthy
networks:
- eveai-network
- eveai-dev-network
db:
container_name: db
hostname: db
image: ankane/pgvector
ports:
- 5432:5432
- 3005:5432 # Dev database volgens port schema (vermijd standaard 5432)
restart: always
environment:
- POSTGRES_DB=eveai
@@ -324,13 +296,14 @@ services:
timeout: 5s
retries: 5
networks:
- eveai-network
- eveai-dev-network
redis:
container_name: redis
image: redis:7.2.5
restart: always
ports:
- "6379:6379"
- "3006:6379" # Dev Redis volgens port schema (vermijd standaard 6379)
volumes:
- ./db/redis:/data
healthcheck:
@@ -339,9 +312,10 @@ services:
timeout: 5s
retries: 5
networks:
- eveai-network
- eveai-dev-network
flower:
container_name: flower
image: josakola/flower:latest
build:
context: ..
@@ -351,17 +325,18 @@ services:
volumes:
- ../scripts:/app/scripts
ports:
- "5555:5555"
- "3007:5555" # Dev Flower volgens port schema
depends_on:
- redis
networks:
- eveai-network
- eveai-dev-network
minio:
container_name: minio
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
- "3008:9000" # Dev MinIO volgens port schema
- "3009:9001" # Dev MinIO console
expose:
- 9000
volumes:
@@ -376,18 +351,18 @@ services:
interval: 30s
timeout: 20s
retries: 3
start_period: 30s
start_period: 60s
networks:
- eveai-network
- eveai-dev-network
prometheus:
image: prom/prometheus:latest
container_name: prometheus
image: josakola/prometheus:latest
build:
context: ./prometheus
dockerfile: Dockerfile
container_name: prometheus
ports:
- "9090:9090"
- "3010:9090" # Dev Prometheus volgens port schema
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus/data:/prometheus
@@ -399,24 +374,25 @@ services:
- '--web.enable-lifecycle'
restart: unless-stopped
networks:
- eveai-network
- eveai-dev-network
pushgateway:
container_name: pushgateway
image: prom/pushgateway:latest
restart: unless-stopped
ports:
- "9091:9091"
- "3011:9091" # Dev Pushgateway volgens port schema
networks:
- eveai-network
- eveai-dev-network
grafana:
image: grafana/grafana:latest
container_name: grafana
image: josakola/grafana:latest
build:
context: ./grafana
dockerfile: Dockerfile
container_name: grafana
ports:
- "3000:3000"
- "3012:3000" # Dev Grafana volgens port schema
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning
- ./grafana/data:/var/lib/grafana
@@ -428,21 +404,12 @@ services:
depends_on:
- prometheus
networks:
- eveai-network
- eveai-dev-network
networks:
eveai-network:
eveai-dev-network:
driver: bridge
# This enables the containers to access the host network
driver_opts:
com.docker.network.bridge.host_ipc: "true"
volumes:
minio_data:
eveai_logs:
# db-data:
# redis-data:
# tenant-files:
#secrets:
# db-password:
# file: ./db/password.txt
eveai_logs:

View File

@@ -43,36 +43,36 @@ x-common-variables: &common-variables
SW_EMAIL_NAME: "Evie Admin (test)"
SW_PROJECT: "f282f55a-ea52-4538-a979-5bcb890717ab"
name: eveai_test
services:
nginx:
image: josakola/nginx:${EVEAI_VERSION:-latest}
image: josakola/nginx:latest
ports:
- 80:80
- 8080:8080
- 4080:80
environment:
<<: *common-variables
volumes:
- eveai_logs:/var/log/nginx
- test_eveai_logs:/var/log/nginx
depends_on:
- eveai_app
- eveai_api
- eveai_chat_client
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_app:
image: josakola/eveai_app:${EVEAI_VERSION:-latest}
image: josakola/eveai_app:latest
ports:
- 5001:5001
- 4001:5001
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_app
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
@@ -85,40 +85,38 @@ services:
retries: 3
start_period: 30s
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_workers:
image: josakola/eveai_workers:${EVEAI_VERSION:-latest}
image: josakola/eveai_workers:latest
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_workers
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
minio:
condition: service_healthy
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_chat_client:
image: josakola/eveai_chat_client:${EVEAI_VERSION:-latest}
image: josakola/eveai_chat_client:latest
ports:
- 5004:5004
- 4004:5004
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_chat_client
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
@@ -131,38 +129,36 @@ services:
retries: 3
start_period: 30s
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_chat_workers:
image: josakola/eveai_chat_workers:${EVEAI_VERSION:-latest}
image: josakola/eveai_chat_workers:latest
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_chat_workers
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_api:
image: josakola/eveai_api:${EVEAI_VERSION:-latest}
image: josakola/eveai_api:latest
ports:
- 5003:5003
- 4003:5003
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_api
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
@@ -175,80 +171,78 @@ services:
retries: 3
start_period: 30s
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_beat:
image: josakola/eveai_beat:${EVEAI_VERSION:-latest}
image: josakola/eveai_beat:latest
environment:
<<: *common-variables
COMPONENT_NAME: eveai_beat
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
networks:
- eveai-network
- eveai-test-network
restart: "no"
eveai_entitlements:
image: josakola/eveai_entitlements:${EVEAI_VERSION:-latest}
image: josakola/eveai_entitlements:latest
expose:
- 8000
environment:
<<: *common-variables
COMPONENT_NAME: eveai_entitlements
volumes:
- eveai_logs:/app/logs
- crewai_storage:/app/crewai_storage
- test_eveai_logs:/app/logs
depends_on:
redis:
condition: service_healthy
minio:
condition: service_healthy
networks:
- eveai-network
- eveai-test-network
restart: "no"
redis:
image: redis:7.2.5
restart: no
ports:
- "6379:6379"
- "4006:6379"
volumes:
- redisdata:/data
- test_redisdata:/data
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
networks:
- eveai-network
- eveai-test-network
flower:
image: josakola/flower:${EVEAI_VERSION:-latest}
image: josakola/flower:latest
environment:
<<: *common-variables
ports:
- "5555:5555"
- "4007:5555"
depends_on:
- redis
networks:
- eveai-network
- eveai-test-network
restart: "no"
minio:
image: minio/minio
ports:
- "9000:9000"
- "9001:9001"
- "4008:9000"
- "4009:9001"
expose:
- 9000
volumes:
- miniodata:/data
- minioconfig:/root/.minio
- test_miniodata:/data
- test_minioconfig:/root/.minio
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin}
@@ -260,16 +254,16 @@ services:
retries: 3
start_period: 30s
networks:
- eveai-network
- eveai-test-network
restart: "no"
prometheus:
image: josakola/prometheus:${EVEAI_VERSION:-latest}
container_name: prometheus
ports:
- "9090:9090"
- "4010:9090"
volumes:
- prometheusdata:/prometheus
- test_prometheusdata:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
@@ -278,23 +272,23 @@ services:
- '--web.enable-lifecycle'
restart: no
networks:
- eveai-network
- eveai-test-network
pushgateway:
image: prom/pushgateway:latest
restart: unless-stopped
ports:
- "9091:9091"
- "4011:9091"
networks:
- eveai-network
- eveai-test-network
grafana:
image: josakola/grafana:${EVEAI_VERSION:-latest}
container_name: grafana
ports:
- "3000:3000"
- "4012:3000"
volumes:
- grafanadata:/var/lib/grafana
- test_grafanadata:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
@@ -303,21 +297,16 @@ services:
depends_on:
- prometheus
networks:
- eveai-network
- eveai-test-network
networks:
eveai-network:
eveai-test-network:
driver: bridge
# This enables the containers to access the host network
driver_opts:
com.docker.network.bridge.host_ipc: "true"
volumes:
eveai_logs:
pgdata:
redisdata:
miniodata:
minioconfig:
prometheusdata:
grafanadata:
crewai_storage:
test_eveai_logs:
test_redisdata:
test_miniodata:
test_minioconfig:
test_prometheusdata:
test_grafanadata:

View File

@@ -1,155 +0,0 @@
#!/bin/zsh
# or use #!/usr/bin/env zsh
# Function to display usage information
usage() {
echo "Usage: source $0 <environment> [version]"
echo " environment: The environment to use (dev, prod, test, integration, bugfix)"
echo " version : (Optional) Specific release version to deploy"
echo " If not specified, uses 'latest' (except for dev environment)"
}
# Replace the existing check at the beginning of docker_env_switch.sh
# Check if the script is sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Script is being executed directly from terminal
echo "Error: This script must be sourced, not executed directly."
echo "Please run: source $0 <environment> [version]"
exit 1
fi
# If we reach here, script is being sourced (either by terminal or another script)
# Check if an environment is provided
if [ $# -eq 0 ]; then
usage
return 1
fi
ENVIRONMENT=$1
VERSION=${2:-latest} # Default to latest if not specified
# Set variables based on the environment
case $ENVIRONMENT in
dev)
DOCKER_CONTEXT="default"
COMPOSE_FILE="compose_dev.yaml"
VERSION="latest" # Always use latest for dev
;;
prod)
DOCKER_CONTEXT="mxz536.stackhero-network.com"
COMPOSE_FILE="compose_stackhero.yaml"
;;
test)
DOCKER_CONTEXT="test-environment" # Change to your actual test Docker context
COMPOSE_FILE="compose_test.yaml"
;;
integration)
DOCKER_CONTEXT="integration-environment" # Change to your actual integration Docker context
COMPOSE_FILE="compose_integration.yaml"
;;
bugfix)
DOCKER_CONTEXT="bugfix-environment" # Change to your actual bugfix Docker context
COMPOSE_FILE="compose_bugfix.yaml"
;;
*)
echo "Invalid environment: $ENVIRONMENT"
usage
return 1
;;
esac
# Set Docker account
DOCKER_ACCOUNT="josakola"
# Check if Docker context exists
if ! docker context ls --format '{{.Name}}' | grep -q "^$DOCKER_CONTEXT$"; then
echo "Warning: Docker context '$DOCKER_CONTEXT' does not exist."
# Prompt user if they want to create the context
if [[ "$DOCKER_CONTEXT" != "default" ]]; then
echo "Do you want to set up this context now? (y/n): "
read CREATE_CONTEXT
if [[ "$CREATE_CONTEXT" == "y" || "$CREATE_CONTEXT" == "Y" ]]; then
# You would add here the specific code to create each context type
# For example, for remote contexts you might need SSH settings
echo "Please specify the Docker host URL (e.g., ssh://user@remote_host or tcp://remote_host:2375):"
read DOCKER_HOST
docker context create "$DOCKER_CONTEXT" --docker "host=$DOCKER_HOST"
if [ $? -ne 0 ]; then
echo "Failed to create Docker context. Please create it manually."
return 1
fi
else
echo "Using default context instead."
DOCKER_CONTEXT="default"
fi
fi
fi
# Check if compose file exists
if [ ! -f "$COMPOSE_FILE" ]; then
echo "Warning: Compose file '$COMPOSE_FILE' does not exist."
echo "Do you want to create it based on compose_dev.yaml? (y/n): "
read CREATE_FILE
if [[ "$CREATE_FILE" == "y" || "$CREATE_FILE" == "Y" ]]; then
# Create new compose file based on compose_dev.yaml with version variables
sed 's/\(image: josakola\/[^:]*\):latest/\1:${EVEAI_VERSION:-latest}/g' compose_dev.yaml > "$COMPOSE_FILE"
echo "Created $COMPOSE_FILE with version placeholders."
else
echo "Cannot proceed without a valid compose file."
return 1
fi
fi
# Switch Docker context
echo "Switching to Docker context: $DOCKER_CONTEXT"
docker context use $DOCKER_CONTEXT
# Set environment variables
export COMPOSE_FILE=$COMPOSE_FILE
export EVEAI_VERSION=$VERSION
export DOCKER_ACCOUNT=$DOCKER_ACCOUNT
echo "Set COMPOSE_FILE to $COMPOSE_FILE"
echo "Set EVEAI_VERSION to $VERSION"
echo "Set DOCKER_ACCOUNT to $DOCKER_ACCOUNT"
docker-compose() {
docker compose -f $COMPOSE_FILE "$@"
}
dc() {
docker compose -f $COMPOSE_FILE "$@"
}
dcup() {
docker compose -f $COMPOSE_FILE up -d --remove-orphans "$@"
}
dcdown() {
docker compose -f $COMPOSE_FILE down "$@"
}
dcps() {
docker compose -f $COMPOSE_FILE ps "$@"
}
dclogs() {
docker compose -f $COMPOSE_FILE logs "$@"
}
dcpull() {
docker compose -f $COMPOSE_FILE pull "$@"
}
dcrefresh() {
docker compose -f $COMPOSE_FILE pull && docker compose -f $COMPOSE_FILE up -d --remove-orphans "$@"
}
# Exporteer de functies zodat ze beschikbaar zijn in andere scripts
export -f docker-compose dc dcup dcdown dcps dclogs dcpull dcrefresh
echo "Docker environment switched to $ENVIRONMENT with version $VERSION"
echo "You can now use 'docker-compose', 'dc', 'dcup', 'dcdown', 'dcps', 'dclogs', 'dcpull' or 'dcrefresh' commands"

250
docker/podman_env_switch.sh Normal file
View File

@@ -0,0 +1,250 @@
#!/usr/bin/env zsh
# Function to display usage information
usage() {
echo "Usage: source $0 <environment> [version]"
echo " environment: The environment to use (dev, prod, test, integration, bugfix)"
echo " version : (Optional) Specific release version to deploy"
echo " If not specified, uses 'latest' (except for dev environment)"
}
# Check if the script is sourced - improved for both bash and zsh
is_sourced() {
if [[ -n "$ZSH_VERSION" ]]; then
# In zsh, check if we're in a sourced context
[[ "$ZSH_EVAL_CONTEXT" =~ "(:file|:cmdsubst)" ]] || [[ "$0" != "$ZSH_ARGZERO" ]]
else
# In bash, compare BASH_SOURCE with $0
[[ "${BASH_SOURCE[0]}" != "${0}" ]]
fi
}
if ! is_sourced; then
echo "Error: This script must be sourced, not executed directly."
echo "Please run: source $0 <environment> [version]"
if [[ -n "$ZSH_VERSION" ]]; then
return 1 2>/dev/null || exit 1
else
exit 1
fi
fi
# Check if an environment is provided
if [ $# -eq 0 ]; then
usage
return 1
fi
ENVIRONMENT=$1
VERSION=${2:-latest} # Default to latest if not specified
# Check if podman and podman-compose are available
if ! command -v podman &> /dev/null; then
echo "Error: podman is not installed or not in PATH"
echo "Please install podman first"
return 1
fi
if ! command -v podman-compose &> /dev/null; then
echo "Error: podman-compose is not installed or not in PATH"
echo "Please install podman-compose first"
return 1
fi
CONTAINER_CMD="podman"
# Store the actual path to podman-compose to avoid recursion
COMPOSE_CMD_PATH=$(command -v podman-compose)
echo "Using container runtime: $CONTAINER_CMD"
echo "Using compose command: $COMPOSE_CMD_PATH"
# Set default platform to AMD64 for consistency
export BUILDAH_PLATFORM=linux/amd64
export PODMAN_PLATFORM=linux/amd64
# Set variables based on the environment
case $ENVIRONMENT in
dev)
PODMAN_CONNECTION="default"
COMPOSE_FILE="compose_dev.yaml"
VERSION="latest" # Always use latest for dev
;;
prod)
PODMAN_CONNECTION="mxz536.stackhero-network.com"
COMPOSE_FILE="compose_stackhero.yaml"
;;
test)
PODMAN_CONNECTION="test-environment"
COMPOSE_FILE="compose_test.yaml"
;;
integration)
PODMAN_CONNECTION="integration-environment"
COMPOSE_FILE="compose_integration.yaml"
;;
bugfix)
PODMAN_CONNECTION="bugfix-environment"
COMPOSE_FILE="compose_bugfix.yaml"
;;
*)
echo "Invalid environment: $ENVIRONMENT"
usage
return 1
;;
esac
# Set container registry account
CONTAINER_ACCOUNT="josakola"
# Handle remote connections for podman
if [[ "$PODMAN_CONNECTION" != "default" ]]; then
echo "Setting up remote podman connection: $PODMAN_CONNECTION"
# Check if podman connection exists
if ! podman system connection list --format '{{.Name}}' 2>/dev/null | grep -q "^$PODMAN_CONNECTION$"; then
echo "Warning: Podman connection '$PODMAN_CONNECTION' does not exist."
echo -n "Do you want to set up this connection now? (y/n): "
read -r CREATE_CONNECTION
if [[ "$CREATE_CONNECTION" == "y" || "$CREATE_CONNECTION" == "Y" ]]; then
echo -n "Please specify the SSH connection string (e.g., user@remote_host): "
read -r SSH_CONNECTION
if [[ -n "$SSH_CONNECTION" ]]; then
podman system connection add "$PODMAN_CONNECTION" --identity ~/.ssh/id_rsa "ssh://$SSH_CONNECTION/run/user/1000/podman/podman.sock"
if [[ $? -ne 0 ]]; then
echo "Failed to create podman connection. Please create it manually."
return 1
fi
else
echo "No SSH connection string provided."
return 1
fi
else
echo "Using local podman setup instead."
PODMAN_CONNECTION="default"
fi
fi
# Set the connection
if [[ "$PODMAN_CONNECTION" != "default" ]]; then
# Use podman context instead of manually setting CONTAINER_HOST
podman system connection default "$PODMAN_CONNECTION" 2>/dev/null
if [[ $? -eq 0 ]]; then
echo "Switched to remote podman connection: $PODMAN_CONNECTION"
else
echo "Warning: Failed to switch to connection $PODMAN_CONNECTION, using local setup"
PODMAN_CONNECTION="default"
fi
fi
else
echo "Using local podman setup with AMD64 platform"
# Ensure we're using the default local connection
podman system connection default "" 2>/dev/null || true
fi
# Check if compose file exists
if [[ ! -f "$COMPOSE_FILE" ]]; then
echo "Warning: Compose file '$COMPOSE_FILE' does not exist."
if [[ -f "compose_dev.yaml" ]]; then
echo -n "Do you want to create it based on compose_dev.yaml? (y/n): "
read -r CREATE_FILE
if [[ "$CREATE_FILE" == "y" || "$CREATE_FILE" == "Y" ]]; then
# Create new compose file based on compose_dev.yaml with version variables
if sed 's/\(image: josakola\/[^:]*\):latest/\1:${EVEAI_VERSION:-latest}/g' compose_dev.yaml > "$COMPOSE_FILE" 2>/dev/null; then
echo "Created $COMPOSE_FILE with version placeholders."
else
echo "Failed to create $COMPOSE_FILE"
return 1
fi
else
echo "Cannot proceed without a valid compose file."
return 1
fi
else
echo "Cannot create $COMPOSE_FILE: compose_dev.yaml not found."
return 1
fi
fi
# Set environment variables
export COMPOSE_FILE=$COMPOSE_FILE
export EVEAI_VERSION=$VERSION
export CONTAINER_ACCOUNT=$CONTAINER_ACCOUNT
export CONTAINER_CMD=$CONTAINER_CMD
export COMPOSE_CMD_PATH=$COMPOSE_CMD_PATH
echo "Set COMPOSE_FILE to $COMPOSE_FILE"
echo "Set EVEAI_VERSION to $VERSION"
echo "Set CONTAINER_ACCOUNT to $CONTAINER_ACCOUNT"
echo "Set platform to AMD64 (linux/amd64)"
# Define compose wrapper functions using the full path to avoid recursion
pc() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE "$@"
}
pcup() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE up -d --remove-orphans "$@"
}
pcdown() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE down "$@"
}
pcps() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE ps "$@"
}
pclogs() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE logs "$@"
}
# Simplified pull - no platform tricks needed
pcpull() {
echo "Pulling AMD64 images..."
$COMPOSE_CMD_PATH -f $COMPOSE_FILE pull "$@"
}
pcrefresh() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE pull && $COMPOSE_CMD_PATH -f $COMPOSE_FILE up -d --remove-orphans "$@"
}
pcbuild() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE build "$@"
}
pcrestart() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE restart "$@"
}
pcstop() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE stop "$@"
}
pcstart() {
$COMPOSE_CMD_PATH -f $COMPOSE_FILE start "$@"
}
# Export functions - handle both bash and zsh
if [[ -n "$ZSH_VERSION" ]]; then
# In zsh, functions are automatically available in subshells
# But we can make them available globally with typeset
typeset -f pc pcup pcdown pcps pclogs pcpull pcrefresh pcbuild pcrestart pcstop pcstart > /dev/null
else
# Bash style export
export -f pc pcup pcdown pcps pclogs pcpull pcrefresh pcbuild pcrestart pcstop pcstart
fi
echo "✅ Podman environment switched to $ENVIRONMENT with version $VERSION"
echo "🖥️ Platform: AMD64 (compatible with both Intel and Apple Silicon)"
echo "Available commands:"
echo " pc - podman-compose shorthand"
echo " pcup - start services in background"
echo " pcdown - stop and remove services"
echo " pcps - list running services"
echo " pclogs - view service logs"
echo " pcpull - pull latest images"
echo " pcrefresh - pull and restart services"
echo " pcbuild - build services"
echo " pcrestart - restart services"
echo " pcstop - stop services"
echo " pcstart - start stopped services"