Skip to content

docker local environment #10993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions docker-local-environment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# The base image
FROM ubuntu:20.04

# Prevent interactive prompts during installation
ENV DEBIAN_FRONTEND=noninteractive

# Initialize system tools
RUN apt-get update && apt-get install -y \
iputils-ping \
wget \
gnupg \
openjdk-17-jdk \
maven \
python3 \
Copy link
Preview

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

Ensure there is no trailing whitespace after the backslash in this installation command to prevent potential build issues. This can help avoid unexpected errors during the Docker build process.

Suggested change
python3 \
python3 \

Copilot uses AI. Check for mistakes.

python3-pip \
mysql-server \
mysql-client \
git \
curl \
libssl-dev \
build-essential \
net-tools \
sudo \
lsof \
iproute2 \
tar

# Set JAVA_HOME globally
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-arm64
ENV PATH="$JAVA_HOME/bin:$PATH"

# Verify Java installation
RUN java -version && echo $JAVA_HOME

# Download & Extract CloudStack Source Code
RUN mkdir -p /cloudstack && \
wget https://dlcdn.apache.org/cloudstack/releases/4.20.0.0/apache-cloudstack-4.20.0.0-src.tar.bz2 -P /tmp && \
tar -xjf /tmp/apache-cloudstack-4.20.0.0-src.tar.bz2 -C /cloudstack

# Set working directory
WORKDIR /cloudstack/apache-cloudstack-4.20.0.0-src

# Build from source
RUN mvn clean install -P developer,systemvm

# Ensure MySQL user has a valid shell before installation
RUN usermod -s /bin/bash mysql

# Create a MySQL data directory volume
VOLUME /var/lib/mysql

# Copy entrypoint and init scripts into CloudStack directory
COPY docker-entrypoint.sh /cloudstack/docker-entrypoint.sh
COPY init-mysql.sh /cloudstack/init-mysql.sh
RUN chmod +x /cloudstack/docker-entrypoint.sh /cloudstack/init-mysql.sh

# Expose CloudStack and MySQL ports
EXPOSE 8080 3306

# Keep the container running for debugging
CMD ["tail", "-f", "/dev/null"]
52 changes: 52 additions & 0 deletions docker-local-environment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
services:
mysql:
image: mysql:8.0
restart: always
networks:
cloudstack-docker_mynetwork:
aliases:
- mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: cloud
MYSQL_USER: cloud
MYSQL_PASSWORD: cloud
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
command: [
"--default-authentication-plugin=mysql_native_password",
"--bind-address=0.0.0.0"
]
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 5s
timeout: 3s
retries: 5

cloudstack:
build: .
restart: no
depends_on:
mysql:
condition: service_healthy
environment:
DB_HOST: mysql
DB_USER: cloud
DB_PASSWORD: cloud
volumes:
- ./docker-entrypoint.sh:/cloudstack/docker-entrypoint.sh
- ./init-mysql.sh:/cloudstack/init-mysql.sh
command: "/bin/bash /cloudstack/docker-entrypoint.sh"
networks:
cloudstack-docker_mynetwork:
aliases:
- cloudstack

volumes:
mysql_data:

networks:
cloudstack-docker_mynetwork:
driver: bridge
25 changes: 25 additions & 0 deletions docker-local-environment/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -e # Exit immediately on error

echo "----Starting MySQL container..."

# Start MySQL in the background
service mysql start

# Wait for MySQL to fully initialize
until mysqladmin ping &>/dev/null; do
echo "Waiting for MySQL to be ready..."
sleep 2
done

echo "----MySQL is running!"

# Run the initialization script for database setup
bash /cloudstack/init-mysql.sh

echo "----Starting CloudStack Management Server..."
service cloudstack-management start

# Keep the container running
exec bash
Copy link
Preview

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

The command 'exec bash' at line 24 will replace the current shell, making the subsequent 'tail -f /dev/null' unreachable. Consider removing one of these commands to keep the container running as intended.

Suggested change
exec bash

Copilot uses AI. Check for mistakes.

tail -f /dev/null
35 changes: 35 additions & 0 deletions docker-local-environment/init-mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e # Exit immediately on error

echo "----Running MySQL initialization script..."

# Wait until MySQL is ready, pings the MySQL server awaiting a response
until mysqladmin ping &>/dev/null; do
echo "----Waiting for MySQL to be ready..."
sleep 2
done

# Validate the database exists before creating it
DB_EXISTS=$(mysql -u root -p${MYSQL_ROOT_PASSWORD} -se "SHOW DATABASES LIKE 'cloud';")

if [ -z "$DB_EXISTS" ]; then
echo "----Creating MySQL database..."
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE cloud;"
else
echo "----Database 'cloud' already exists—skipping creation."
fi

# Validate the cloud user exists before creating it
USER_EXISTS=$(mysql -u root -p${MYSQL_ROOT_PASSWORD} -se "SELECT COUNT(*) FROM mysql.user WHERE user='cloud';")

if [ "$USER_EXISTS" -eq 0 ]; then
echo "----Creating MySQL user..."
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "
CREATE USER 'cloud'@'%' IDENTIFIED BY 'cloud';
GRANT ALL PRIVILEGES ON cloud.* TO 'cloud'@'%';
FLUSH PRIVILEGES;"
else
echo "----MySQL user 'cloud' already exists—skipping."
fi

echo "----MySQL setup complete"
Loading