-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
bri-harris
wants to merge
1
commit into
apache:main
Choose a base branch
from
bri-harris:feature_docker_local_environment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
docker local environment #10993
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
tail -f /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.