-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: 4.22
Are you sure you want to change the base?
docker local environment #10993
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 \ | |
| python3 \ |
| 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 |
| 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 | ||||
|
||||
| exec bash |
| 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" |
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.