Skip to content

Commit 6b6bbb8

Browse files
committed
docker ocal environment
1 parent 41b4f0a commit 6b6bbb8

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# The base image
2+
FROM ubuntu:20.04
3+
4+
# Prevent interactive prompts during installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Initialize system tools
8+
RUN apt-get update && apt-get install -y \
9+
iputils-ping \
10+
wget \
11+
gnupg \
12+
openjdk-17-jdk \
13+
maven \
14+
python3 \
15+
python3-pip \
16+
mysql-server \
17+
mysql-client \
18+
git \
19+
curl \
20+
libssl-dev \
21+
build-essential \
22+
net-tools \
23+
sudo \
24+
lsof \
25+
iproute2 \
26+
tar
27+
28+
# Set JAVA_HOME globally
29+
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-arm64
30+
ENV PATH="$JAVA_HOME/bin:$PATH"
31+
32+
# Verify Java installation
33+
RUN java -version && echo $JAVA_HOME
34+
35+
# Download & Extract CloudStack Source Code
36+
RUN mkdir -p /cloudstack && \
37+
wget https://dlcdn.apache.org/cloudstack/releases/4.20.0.0/apache-cloudstack-4.20.0.0-src.tar.bz2 -P /tmp && \
38+
tar -xjf /tmp/apache-cloudstack-4.20.0.0-src.tar.bz2 -C /cloudstack
39+
40+
# Set working directory
41+
WORKDIR /cloudstack/apache-cloudstack-4.20.0.0-src
42+
43+
# Build from source
44+
RUN mvn clean install -P developer,systemvm
45+
46+
# Ensure MySQL user has a valid shell before installation
47+
RUN usermod -s /bin/bash mysql
48+
49+
# Create a MySQL data directory volume
50+
VOLUME /var/lib/mysql
51+
52+
# Copy entrypoint and init scripts into CloudStack directory
53+
COPY docker-entrypoint.sh /cloudstack/docker-entrypoint.sh
54+
COPY init-mysql.sh /cloudstack/init-mysql.sh
55+
RUN chmod +x /cloudstack/docker-entrypoint.sh /cloudstack/init-mysql.sh
56+
57+
# Expose CloudStack and MySQL ports
58+
EXPOSE 8080 3306
59+
60+
# Keep the container running for debugging
61+
CMD ["tail", "-f", "/dev/null"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0
4+
restart: always
5+
networks:
6+
cloudstack-docker_mynetwork:
7+
aliases:
8+
- mysql
9+
environment:
10+
MYSQL_ROOT_PASSWORD: rootpass
11+
MYSQL_DATABASE: cloud
12+
MYSQL_USER: cloud
13+
MYSQL_PASSWORD: cloud
14+
ports:
15+
- "3306:3306"
16+
volumes:
17+
- mysql_data:/var/lib/mysql
18+
command: [
19+
"--default-authentication-plugin=mysql_native_password",
20+
"--bind-address=0.0.0.0"
21+
]
22+
healthcheck:
23+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
24+
interval: 5s
25+
timeout: 3s
26+
retries: 5
27+
28+
cloudstack:
29+
build: .
30+
restart: no
31+
depends_on:
32+
mysql:
33+
condition: service_healthy
34+
environment:
35+
DB_HOST: mysql
36+
DB_USER: cloud
37+
DB_PASSWORD: cloud
38+
volumes:
39+
- ./docker-entrypoint.sh:/cloudstack/docker-entrypoint.sh
40+
- ./init-mysql.sh:/cloudstack/init-mysql.sh
41+
command: "/bin/bash /cloudstack/docker-entrypoint.sh"
42+
networks:
43+
cloudstack-docker_mynetwork:
44+
aliases:
45+
- cloudstack
46+
47+
volumes:
48+
mysql_data:
49+
50+
networks:
51+
cloudstack-docker_mynetwork:
52+
driver: bridge
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e # Exit immediately on error
3+
4+
echo "----Starting MySQL container..."
5+
6+
# Start MySQL in the background
7+
service mysql start
8+
9+
# Wait for MySQL to fully initialize
10+
until mysqladmin ping &>/dev/null; do
11+
echo "Waiting for MySQL to be ready..."
12+
sleep 2
13+
done
14+
15+
echo "----MySQL is running!"
16+
17+
# Run the initialization script for database setup
18+
bash /cloudstack/init-mysql.sh
19+
20+
echo "----Starting CloudStack Management Server..."
21+
service cloudstack-management start
22+
23+
# Keep the container running
24+
exec bash
25+
tail -f /dev/null
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e # Exit immediately on error
3+
4+
echo "----Running MySQL initialization script..."
5+
6+
# Wait until MySQL is ready, pings the MySQL server awaiting a response
7+
until mysqladmin ping &>/dev/null; do
8+
echo "----Waiting for MySQL to be ready..."
9+
sleep 2
10+
done
11+
12+
# Validate the database exists before creating it
13+
DB_EXISTS=$(mysql -u root -p${MYSQL_ROOT_PASSWORD} -se "SHOW DATABASES LIKE 'cloud';")
14+
15+
if [ -z "$DB_EXISTS" ]; then
16+
echo "----Creating MySQL database..."
17+
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE cloud;"
18+
else
19+
echo "----Database 'cloud' already exists—skipping creation."
20+
fi
21+
22+
# Validate the cloud user exists before creating it
23+
USER_EXISTS=$(mysql -u root -p${MYSQL_ROOT_PASSWORD} -se "SELECT COUNT(*) FROM mysql.user WHERE user='cloud';")
24+
25+
if [ "$USER_EXISTS" -eq 0 ]; then
26+
echo "----Creating MySQL user..."
27+
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "
28+
CREATE USER 'cloud'@'%' IDENTIFIED BY 'cloud';
29+
GRANT ALL PRIVILEGES ON cloud.* TO 'cloud'@'%';
30+
FLUSH PRIVILEGES;"
31+
else
32+
echo "----MySQL user 'cloud' already exists—skipping."
33+
fi
34+
35+
echo "----MySQL setup complete"

0 commit comments

Comments
 (0)