diff --git a/Containerfile b/Containerfile index 0ae9f09..8b77be1 100644 --- a/Containerfile +++ b/Containerfile @@ -1,77 +1,25 @@ -FROM public.ecr.aws/docker/library/ubuntu:22.04 +# See https://github.com/apache/cloudstack/blob/main/tools/docker/Dockerfile +FROM docker.io/apache/cloudstack-simulator:4.22.1.0 ENV DEBIAN_FRONTEND noninteractive -ARG src_url=https://github.com/apache/cloudstack/archive/refs/tags/4.19.1.3.tar.gz - -RUN echo 'mysql-server mysql-server/root_password password root' | debconf-set-selections; \ - echo 'mysql-server mysql-server/root_password_again password root' | debconf-set-selections; - -RUN apt-get -y update && apt-get install -y --no-install-recommends \ - genisoimage \ - libffi-dev \ - libssl-dev \ - sudo \ - ipmitool \ - maven \ - netcat \ - openjdk-11-jdk \ - python3 \ - python3-dev \ - python3-mysql.connector \ - python3-pip \ - python3-setuptools \ - python3-paramiko \ - supervisor \ +RUN apt-get -y update && apt-get upgrade -y && apt-get install -y --no-install-recommends \ wget \ nginx \ jq \ - mysql-server \ - openssh-client \ - build-essential \ - npm \ - nodejs \ + pipx \ + netcat-traditional \ && apt-get clean all && rm -rf /var/lib/apt/lists/*; -# TODO: check if and why this is needed -RUN mkdir -p /root/.ssh \ - && chmod 0700 /root/.ssh \ - && ssh-keygen -t rsa -N "" -f id_rsa.cloud - -RUN mkdir -p /var/run/mysqld; \ - chown mysql /var/run/mysqld; - -RUN (/usr/bin/mysqld_safe &); sleep 5; mysqladmin -u root -proot password '' - -RUN wget $src_url -O /opt/cloudstack.tar.gz; \ - mkdir -p /opt/cloudstack; \ - tar xvzf /opt/cloudstack.tar.gz -C /opt/cloudstack --strip-components=1 - -WORKDIR /opt/cloudstack - -RUN ln -s /usr/bin/python3 /usr/local/bin/python -RUN mvn -Pdeveloper -Dsimulator -DskipTests clean install -RUN mvn -Pdeveloper -Dsimulator dependency:go-offline -RUN mvn -pl client jetty:run -Dsimulator -Djetty.skip -Dorg.eclipse.jetty.annotations.maxWait=120 - COPY zones.cfg /opt/zones.cfg -RUN (/usr/bin/mysqld_safe &); \ - sleep 5; \ - mvn -Pdeveloper -pl developer -Ddeploydb; \ - mvn -Pdeveloper -pl developer -Ddeploydb-simulator; \ - mvn -Pdeveloper,marvin -pl :cloud-marvin; \ - MARVIN_FILE=$(find /opt/cloudstack/tools/marvin/dist/ -name "Marvin*.tar.gz"); \ - pip install wheel; \ - pip install $MARVIN_FILE; - COPY nginx_default.conf /etc/nginx/sites-available/default -RUN pip install cs + +RUN pipx install cs + COPY run.sh /opt/run.sh COPY deploy.sh /opt/deploy.sh -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf - -RUN cd ui && npm install && npm run build +COPY supervisord_nginx.conf /etc/supervisor/conf.d/nginx.conf RUN /opt/deploy.sh diff --git a/deploy.sh b/deploy.sh index 4d5e1de..155738d 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,15 +1,19 @@ #!/bin/bash +x +set -euo pipefail +export PATH="/root/.local/bin:$PATH" -/usr/bin/mysqld_safe & -cd /opt/cloudstack && mvn -pl client jetty:run -Dsimulator -Dorg.eclipse.jetty.annotations.maxWait=120 & +# Run the CloudStack Simulator +/usr/bin/supervisord --silent & +echo "--- Waiting for CloudStack Simulator to start ---" +sleep 30 until nc -z localhost 8096; do - echo "waiting for port 8096..." + echo "--- ...waiting for port 8096... ---" sleep 3 done - -sleep 3 -python3 /opt/cloudstack/tools/marvin/marvin/deployDataCenter.py -i /opt/zones.cfg +sleep 10 +echo "--- Deploying CloudStack Simulator Zones (this will take some minutes...) ---" +python3 /root/tools/marvin/marvin/deployDataCenter.py -i /opt/zones.cfg export CLOUDSTACK_ENDPOINT=http://127.0.0.1:8096 export CLOUDSTACK_KEY=dummy @@ -17,3 +21,8 @@ export CLOUDSTACK_SECRET=dummy # Add Simulator to supported hypervisors exclusively cs updateConfiguration name=hypervisor.list value=Simulator + +# Stop the CloudStack Simulator +supervisorctl stop all + +echo "--- CloudStack Simulator Zones deployed ---" diff --git a/nginx_default.conf b/nginx_default.conf index 300d6bd..55ffb07 100644 --- a/nginx_default.conf +++ b/nginx_default.conf @@ -2,6 +2,10 @@ upstream cloudstack-backend { server 127.0.0.1:8080; } +upstream cloudstack-ui { + server 127.0.0.1:5050; +} + server { listen 8888 default_server; server_name _; @@ -20,8 +24,9 @@ server { location /client { proxy_pass http://cloudstack-backend; } + location / { - root /opt/cloudstack/ui/dist; - index index.html; + proxy_set_header Host localhost; + proxy_pass http://cloudstack-ui; } } diff --git a/supervisord.conf b/supervisord.conf deleted file mode 100644 index ea8cb45..0000000 --- a/supervisord.conf +++ /dev/null @@ -1,28 +0,0 @@ -[supervisord] -nodaemon=true - -[program:mysqld] -command=/usr/bin/mysqld_safe -autostart=true -autorestart=true -user=root - -[program:cloudstack] -command=/bin/bash -c "mvn -pl client jetty:run -Dsimulator -Dorg.eclipse.jetty.annotations.maxWait=120" -directory=/opt/cloudstack -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -user=root - -[program:nginx] -command=/usr/sbin/nginx -autostart=true -autorestart=false -user=root - -[program:run] -command=/opt/run.sh -startsecs=0 -autorestart=false -startretries=1 -user=root diff --git a/supervisord_nginx.conf b/supervisord_nginx.conf new file mode 100644 index 0000000..4a328cd --- /dev/null +++ b/supervisord_nginx.conf @@ -0,0 +1,12 @@ +[program:nginx] +command=/usr/sbin/nginx +autostart=true +autorestart=false +user=root + +[program:run] +command=/opt/run.sh +startsecs=0 +autorestart=false +startretries=1 +user=root