commit 27a4f4153f4ca31290563a4568e88c3666420f6a Author: cracklesparkle Date: Mon Nov 25 01:20:02 2024 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bf3b61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +dist/* + +nginx/www + +xreports/*.deb + +xrad/xrad +xrad/config.json +xrad/xrad.lic + +xdac/*.deb +xdac/config.json +xdac/xdac +xdac/xdac.lic + +pghs/pghs +pghs/pghs.lic +pghs/config.json + +postgres/db/* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfeeb7d --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Демонстрационный стенд EDU - XSQUARE-PGHS в Docker + +pghs.xsquare - hostname:8001 +xrad.xsquare - hostname:8002 + +# Установка и запуск (требуется unzip и docker compose) + +```bash +chmod +x start.sh +``` + +```bash +./start.sh +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b88bb9f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,100 @@ +services: + nginx-pghs: + image: nginx:stable + container_name: nginx-pghs + ports: + - "8001:80" + restart: always + volumes: + - ./dist:/dist + - ./nginx/nginx-pghs.conf:/etc/nginx/nginx.conf:ro + - ./nginx/www:/var/www:ro + depends_on: + - postgres + - pghs + + nginx-xrad: + image: nginx:stable + container_name: nginx-xrad + ports: + - "8002:80" + restart: always + volumes: + - ./dist:/dist + - ./nginx/nginx-xrad.conf:/etc/nginx/nginx.conf:ro + - ./nginx/www:/var/www:ro + links: + - xrad:xrad + depends_on: + - postgres + - xrad + + postgres: + build: + context: ./postgres + container_name: postgres + restart: always + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + expose: + - "5432:5432" + volumes: + - ./dist:/dist + + xdac: + build: + context: ./xdac + container_name: xdac + depends_on: + - postgres + restart: always + expose: + - "8088:8088" + links: + - postgres:postgres + volumes: + - ./dist:/dist + + pghs: + build: + context: ./pghs + container_name: pghs + expose: + - "8888:8888" + depends_on: + - postgres + restart: always + links: + - postgres:postgres + volumes: + - ./dist:/dist + + xrad: + build: + context: ./xrad + container_name: xrad + depends_on: + - postgres + restart: always + expose: + - "8889:8889" + links: + - postgres:postgres + volumes: + - ./dist:/dist + + xreports: + build: + context: ./xreports + container_name: xreports + restart: always + depends_on: + - postgres + expose: + - "8087:8087" + volumes: + - ./dist:/dist + +volumes: + postgres_data: \ No newline at end of file diff --git a/nginx/nginx-pghs.conf b/nginx/nginx-pghs.conf new file mode 100644 index 0000000..2e39d5f --- /dev/null +++ b/nginx/nginx-pghs.conf @@ -0,0 +1,39 @@ +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + sendfile on; + keepalive_timeout 65; + + upstream pghs_service { + server pghs:8888; + } + + server { + listen 80; + + location / { + root /var/www/pghs.xsquare; + index index.html; + } + + location /pghs { + proxy_pass http://pghs_service; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /files { + alias /var/www/pghs.xsquare.files.local; + autoindex on; + allow all; + } + } +} \ No newline at end of file diff --git a/nginx/nginx-xrad.conf b/nginx/nginx-xrad.conf new file mode 100644 index 0000000..9bf1243 --- /dev/null +++ b/nginx/nginx-xrad.conf @@ -0,0 +1,33 @@ +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + sendfile on; + keepalive_timeout 65; + + upstream xrad_service { + server xrad:8889; + } + + server { + listen 80; + + location / { + root /var/www/xrad.xsquare; + index index.html; + } + + location /ds { + proxy_pass http://xrad_service; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} diff --git a/pghs/Dockerfile b/pghs/Dockerfile new file mode 100644 index 0000000..decf916 --- /dev/null +++ b/pghs/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:bookworm AS base + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + apache2 \ + postgresql \ + unzip \ + wget \ + locales \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN dpkg-reconfigure locales + +FROM base AS installer + +COPY . /home/dist + +RUN mkdir /usr/local/xsquare.pghs + +RUN cp /home/dist/config.json /usr/local/xsquare.pghs/config.json +RUN cp /home/dist/pghs /usr/local/xsquare.pghs/pghs +RUN cp /home/dist/pghs.lic /usr/local/xsquare.pghs/pghs.lic + +RUN sed -i 's/"host": "127.0.0.1"/"host": "postgres"/g' /usr/local/xsquare.pghs/config.json + +RUN chmod +x /usr/local/xsquare.pghs/pghs + +WORKDIR /usr/local/xsquare.pghs + +CMD ["/usr/local/xsquare.pghs/pghs"] \ No newline at end of file diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..c6bb006 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,12 @@ +FROM postgres:14 AS base + +RUN apt-get update && apt-get install -y locales-all \ + && locale-gen ru_RU.UTF-8 \ + && update-locale LANG=ru_RU.UTF-8 + +ENV LANG=ru_RU.UTF-8 +ENV LC_NUMERIC=ru_RU.UTF-8 + +COPY ./db /docker-entrypoint-initdb.d + +COPY init.sql /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/postgres/init.sql b/postgres/init.sql new file mode 100644 index 0000000..08f41a8 --- /dev/null +++ b/postgres/init.sql @@ -0,0 +1,18 @@ +-- Create users +CREATE USER xrad_user WITH ENCRYPTED PASSWORD 'xrad_user'; +CREATE USER app_user WITH ENCRYPTED PASSWORD 'app_user'; + +-- Grant SUPERUSER privileges +ALTER USER xrad_user WITH SUPERUSER; +ALTER USER app_user WITH SUPERUSER; + +-- Create databases and set owners +CREATE DATABASE xraddb OWNER xrad_user; +CREATE DATABASE appdb OWNER app_user; + +-- Restore the database dumps +\connect xraddb; +\i /docker-entrypoint-initdb.d/xraddb.xsquare.pgsql; + +\connect appdb; +\i /docker-entrypoint-initdb.d/appdb.xsquare.pgsql; \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..1f6168e --- /dev/null +++ b/setup.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -e + +DIST_DIR="dist" +ZIP_FILE="$DIST_DIR/xsquare.lcdp.4.11.13.14.8.8_release.zip" +XREPORTS_DEB="xreports/xsquare.xreports_3.3.3.6.deb" +XDAC_DEB="xdac/xsquare.xdac_3.4.1.12.deb" +DOCKER_COMPOSE_CMD="docker compose" + +echo "Готовим..." +mkdir -p $DIST_DIR + +if [ ! -f "$ZIP_FILE" ]; then + echo "Скачиваю $ZIP_FILE..." + wget -q -O $ZIP_FILE https://lcdp.xsquare.ru/files/pghs/xsquare.lcdp.v4/xsquare.lcdp.4.11.13.14.8.8_release.zip +else + echo "$ZIP_FILE уже существует. Пропускаю скачивание." +fi + +if [ ! -f "$XREPORTS_DEB" ]; then + echo "Скачиваю $XREPORTS_DEB..." + wget -q -O $XREPORTS_DEB https://lcdp.xsquare.ru/files/xreports/rpm_dep/3.3.3.6/xsquare.xreports_3.3.3.6.deb +else + echo "$XREPORTS_DEB уже существует. Пропускаю скачивание." +fi + +if [ ! -f "$XDAC_DEB" ]; then + echo "Скачиваю $XDAC_DEB..." + wget -q -O $XDAC_DEB https://lcdp.xsquare.ru/files/xdac/3.4.1.12/xsquare.xdac_3.4.1.12.deb +else + echo "$XDAC_DEB уже существует. Пропускаю скачивание." +fi + +echo "Распаковка..." +unzip -q -o $ZIP_FILE -d $DIST_DIR + +echo "Кладу var/www..." +cp -r dist/xsquare.lcdp.4.11.13.14.8.8_release/var/www nginx/www + +echo "Кладу usr/local/xsquare.pghs..." +cp -r dist/xsquare.lcdp.4.11.13.14.8.8_release/usr/local/xsquare.pghs/* pghs/ + +echo "Кладу usr/local/xsquare.xdac..." +cp -r dist/xsquare.lcdp.4.11.13.14.8.8_release/usr/local/xsquare.xdac/* xdac/ + +echo "Кладу usr/local/xsquare.xrad..." +cp -r dist/xsquare.lcdp.4.11.13.14.8.8_release/usr/local/xsquare.xrad/* xrad/ + +echo "Кладу db..." +cp -r dist/xsquare.lcdp.4.11.13.14.8.8_release/db/* postgres/db/ + +echo "Собираю Docker..." +$DOCKER_COMPOSE_CMD up -d --build + +echo "Жду PostgreSQL..." +POSTGRES_CONTAINER=$($DOCKER_COMPOSE_CMD ps -q postgres) +while ! docker exec $POSTGRES_CONTAINER pg_isready -U postgres > /dev/null 2>&1; do + sleep 2 +done +echo "PostgreSQL готов." + +echo "Настраиваю базу данных..." +docker exec -i $POSTGRES_CONTAINER psql -U xrad_user -d xraddb < $DIST_DIR/xsquare.lcdp.4.11.13.14.8.8_release/db/xraddb.xsquare.pgsql +docker exec -i $POSTGRES_CONTAINER psql -U app_user -d appdb < $DIST_DIR/xsquare.lcdp.4.11.13.14.8.8_release/db/appdb.xsquare.pgsql + +echo "Установка завершена!" + +echo "localhost:8001 - Демо стенд - XSQUARE - EDU v.4.11" +echo "localhost:8002 - xRad Builder" \ No newline at end of file diff --git a/xdac/Dockerfile b/xdac/Dockerfile new file mode 100644 index 0000000..b72558f --- /dev/null +++ b/xdac/Dockerfile @@ -0,0 +1,29 @@ +FROM debian:bookworm AS base + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + apache2 \ + postgresql \ + unzip \ + wget \ + locales \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN dpkg-reconfigure locales + +FROM base AS installer + +COPY . /home/dist + +RUN dpkg -i /home/dist/xsquare.xdac_3.4.1.12.deb + +RUN cp /home/dist/config.json /usr/local/xsquare.xdac/config.json +RUN cp /home/dist/xdac /usr/local/xsquare.xdac/xdac +RUN cp /home/dist/xdac.lic /usr/local/xsquare.xdac/xdac.lic + +RUN sed -i 's/"domain": "localhost"/"domain": "postgres"/' /usr/local/xsquare.xdac/config.json + +WORKDIR /usr/local/xsquare.xdac + +CMD ["/usr/local/xsquare.xdac/xdac"] \ No newline at end of file diff --git a/xrad/Dockerfile b/xrad/Dockerfile new file mode 100644 index 0000000..52123bf --- /dev/null +++ b/xrad/Dockerfile @@ -0,0 +1,31 @@ +FROM debian:bookworm AS base + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + apache2 \ + postgresql \ + unzip \ + wget \ + locales \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN dpkg-reconfigure locales + +FROM base AS installer + +COPY . /home/dist + +RUN mkdir /usr/local/xsquare.xrad + +RUN cp /home/dist/config.json /usr/local/xsquare.xrad/config.json +RUN cp /home/dist/xrad /usr/local/xsquare.xrad/xrad +RUN cp /home/dist/xrad.lic /usr/local/xsquare.xrad/xrad.lic + +RUN sed -i 's/"host": "127.0.0.1"/"host": "postgres"/' /usr/local/xsquare.xrad/config.json + +RUN chmod +x /usr/local/xsquare.xrad/xrad + +WORKDIR /usr/local/xsquare.xrad + +CMD ["/usr/local/xsquare.xrad/xrad"] \ No newline at end of file diff --git a/xreports/Dockerfile b/xreports/Dockerfile new file mode 100644 index 0000000..d1a4d1b --- /dev/null +++ b/xreports/Dockerfile @@ -0,0 +1,23 @@ +FROM debian:bookworm AS base + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + apache2 \ + postgresql \ + unzip \ + wget \ + locales \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN dpkg-reconfigure locales + +FROM base AS installer + +COPY . /home/dist + +RUN dpkg -i /home/dist/xsquare.xreports_3.3.3.6.deb + +WORKDIR /usr/local/xsquare.xreports + +CMD ["/usr/local/xsquare.xreports/xreports"] \ No newline at end of file