- Getting containers ready for the cloud
This commit is contained in:
78
docker/build_and_push_eveai.sh
Executable file
78
docker/build_and_push_eveai.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Load environment variables
|
||||
source .env
|
||||
|
||||
# Docker registry
|
||||
REGISTRY="josakola"
|
||||
|
||||
# Tag (you might want to use a version or git commit hash)
|
||||
TAG="latest"
|
||||
|
||||
# Platforms to build for
|
||||
PLATFORMS="linux/amd64,linux/arm64"
|
||||
|
||||
# Function to build and push a service
|
||||
build_and_push_service() {
|
||||
local SERVICE="$1"
|
||||
echo "Building and pushing $SERVICE..."
|
||||
|
||||
# Extract the build context and dockerfile from the compose file
|
||||
CONTEXT=$(yq e ".services.$SERVICE.build.context" compose_dev.yaml)
|
||||
DOCKERFILE=$(yq e ".services.$SERVICE.build.dockerfile" compose_dev.yaml)
|
||||
|
||||
# Check if context directory exists
|
||||
if [ ! -d "$CONTEXT" ]; then
|
||||
echo "Error: Build context directory '$CONTEXT' for service '$SERVICE' does not exist."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if Dockerfile exists
|
||||
if [ ! -f "$CONTEXT/$DOCKERFILE" ]; then
|
||||
echo "Error: Dockerfile '$DOCKERFILE' for service '$SERVICE' does not exist in context '$CONTEXT'."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Build and push
|
||||
docker buildx build \
|
||||
--platform "$PLATFORMS" \
|
||||
-t "$REGISTRY/$SERVICE:$TAG" \
|
||||
-f "$CONTEXT/$DOCKERFILE" \
|
||||
"$CONTEXT" \
|
||||
--push
|
||||
}
|
||||
|
||||
# If no arguments are provided, build all services
|
||||
if [ $# -eq 0 ]; then
|
||||
mapfile -t SERVICES < <(yq e '.services | keys | .[]' compose_dev.yaml | grep -E '^(nginx|eveai_)')
|
||||
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
|
||||
|
||||
# Loop through services
|
||||
for SERVICE in "${SERVICES[@]}"; do
|
||||
if [[ "$SERVICE" == "nginx" || "$SERVICE" == eveai_* ]]; then
|
||||
if build_and_push_service "$SERVICE"; then
|
||||
echo "Successfully built and pushed $SERVICE"
|
||||
else
|
||||
echo "Failed to build and push $SERVICE"
|
||||
fi
|
||||
else
|
||||
echo "Skipping $SERVICE as it's not nginx or doesn't start with eveai_"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "All specified services processed."
|
||||
@@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source the environment setup script
|
||||
if [ -f "./docker_env_switch.sh" ]; then
|
||||
source ./docker_env_switch.sh dev
|
||||
else
|
||||
echo "Error: set_environment.sh not found in the current directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Docker Hub username
|
||||
USERNAME="josakola"
|
||||
|
||||
# List of all your services
|
||||
ALL_SERVICES=("eveai_app" "eveai_workers" "eveai_chat" "eveai_chat_workers" "nginx")
|
||||
|
||||
# Function to build, tag and push an image
|
||||
build_tag_and_push() {
|
||||
local service=$1
|
||||
echo "Building, tagging, and pushing ${service}..."
|
||||
|
||||
# Extract dockerfile and context paths from Docker Compose configuration
|
||||
local dockerfile_path
|
||||
local context_path
|
||||
|
||||
dockerfile_path=$(docker compose -f "$COMPOSE_FILE" config | grep "${service}" -A 10 | grep "dockerfile" | awk '{print $2}')
|
||||
context_path=$(docker compose -f "$COMPOSE_FILE" config | grep "${service}" -A 10 | grep "context" | awk '{print $2}')
|
||||
|
||||
# Verify the paths
|
||||
echo "Dockerfile path: ${dockerfile_path}"
|
||||
echo "Context path: ${context_path}"
|
||||
|
||||
# Use docker buildx to build the image
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
-t "${USERNAME}/${service}:latest" \
|
||||
--push \
|
||||
--file "${dockerfile_path}" \
|
||||
"${context_path}"
|
||||
}
|
||||
|
||||
# Function to check if a service is in the ALL_SERVICES array
|
||||
service_exists() {
|
||||
local service=$1
|
||||
for s in "${ALL_SERVICES[@]}"; do
|
||||
if [[ "$s" == "$service" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Ensure we're using buildx
|
||||
docker buildx create --use
|
||||
|
||||
# If COMPOSE_FILE is not set, use a default value
|
||||
if [ -z "$COMPOSE_FILE" ]; then
|
||||
COMPOSE_FILE="compose_dev.yaml"
|
||||
echo "COMPOSE_FILE not set, using default: $COMPOSE_FILE"
|
||||
else
|
||||
echo "Using COMPOSE_FILE: $COMPOSE_FILE"
|
||||
fi
|
||||
|
||||
# If no arguments are provided, process all services
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "No specific services provided. Processing all services..."
|
||||
for service in "${ALL_SERVICES[@]}"; do
|
||||
build_tag_and_push "$service"
|
||||
done
|
||||
else
|
||||
# Process only the specified services
|
||||
for service in "$@"; do
|
||||
if service_exists "$service"; then
|
||||
build_tag_and_push "$service"
|
||||
else
|
||||
echo "Warning: ${service} is not a recognized service name. Skipping."
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Done!"
|
||||
@@ -33,8 +33,8 @@ x-common-variables: &common-variables
|
||||
services:
|
||||
nginx:
|
||||
build:
|
||||
context: ../nginx
|
||||
dockerfile: Dockerfile
|
||||
context: ..
|
||||
dockerfile: ./docker/nginx/Dockerfile
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
|
||||
@@ -33,16 +33,17 @@ x-common-variables: &common-variables
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
platform: linux/amd64
|
||||
image: josakola/nginx:latest
|
||||
ports:
|
||||
- 80:80
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- ../nginx:/etc/nginx
|
||||
- ../nginx/sites-enabled:/etc/nginx/sites-enabled
|
||||
- ../nginx/static:/etc/nginx/static
|
||||
- ../nginx/public:/etc/nginx/public
|
||||
- ./logs/nginx:/var/log/nginx
|
||||
# - ../nginx:/etc/nginx
|
||||
# - ../nginx/sites-enabled:/etc/nginx/sites-enabled
|
||||
# - ../nginx/static:/etc/nginx/static
|
||||
# - ../nginx/public:/etc/nginx/public
|
||||
- logs:/var/log/nginx
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.api.rule=Host(`evie.askeveai.com`)"
|
||||
@@ -52,13 +53,14 @@ services:
|
||||
- eveai_chat
|
||||
|
||||
eveai_app:
|
||||
platform: linux/amd64
|
||||
image: josakola/eveai_app:latest
|
||||
ports:
|
||||
- 5001:5001
|
||||
environment:
|
||||
<<: *common-variables
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
- logs:/app/logs
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
|
||||
interval: 10s
|
||||
@@ -67,13 +69,14 @@ services:
|
||||
command: ["sh", "-c", "scripts/start_eveai_app.sh"]
|
||||
|
||||
eveai_workers:
|
||||
platform: linux/amd64
|
||||
image: josakola/eveai_workers:latest
|
||||
# ports:
|
||||
# - 5001:5001
|
||||
environment:
|
||||
<<: *common-variables
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
- logs:/app/logs
|
||||
# healthcheck:
|
||||
# test: [ "CMD", "curl", "-f", "http://localhost:5001/health" ]
|
||||
# interval: 10s
|
||||
@@ -82,13 +85,14 @@ services:
|
||||
command: [ "sh", "-c", "scripts/start_eveai_workers.sh" ]
|
||||
|
||||
eveai_chat:
|
||||
platform: linux/amd64
|
||||
image: josakola/eveai_chat:latest
|
||||
ports:
|
||||
- 5002:5002
|
||||
environment:
|
||||
<<: *common-variables
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
- logs:/app/logs
|
||||
healthcheck:
|
||||
test: [ "CMD", "curl", "-f", "http://localhost:5002/health" ] # Adjust based on your health endpoint
|
||||
interval: 10s
|
||||
@@ -97,13 +101,14 @@ services:
|
||||
command: ["sh", "-c", "scripts/start_eveai_chat.sh"]
|
||||
|
||||
eveai_chat_workers:
|
||||
platform: linux/amd64
|
||||
image: josakola/eveai_chat_workers:latest
|
||||
# ports:
|
||||
# - 5001:5001
|
||||
environment:
|
||||
<<: *common-variables
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
- logs:/app/logs
|
||||
# healthcheck:
|
||||
# test: [ "CMD", "curl", "-f", "http://localhost:5001/health" ]
|
||||
# interval: 10s
|
||||
@@ -112,8 +117,9 @@ services:
|
||||
command: [ "sh", "-c", "scripts/start_eveai_chat_workers.sh" ]
|
||||
|
||||
|
||||
#volumes:
|
||||
# minio_data:
|
||||
volumes:
|
||||
logs:
|
||||
# miniAre theo_data:
|
||||
# db-data:
|
||||
# redis-data:
|
||||
# tenant-files:
|
||||
|
||||
Reference in New Issue
Block a user