diff --git a/.dockerignore b/.dockerignore index 0b4af7b428..ca30ad138c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,20 @@ settings web .drone.yml install.sh -uninstall.sh \ No newline at end of file +uninstall.sh + +server/tools +!server/tools/dbs/*.js +!server/tools/general/*.js +!server/tools/nexe +Dockerfile +server/docker-compose* +server/index.html +server/package-lock.json +server/logs +server/coverage +server/.nyc_output +server/.*docker-compose.yaml +server/.drone*.yml +server/hollaex-kit.env +server/hollaex-kit.env* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9fdc282cfe..7bef90e650 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ build # surge web/CNAME server/tools/hollaex-kit.env.local +server/tools/nginx-dev/logs/* +nginx/logs/* # misc web/.DS_Store @@ -64,7 +66,4 @@ templates/kubernetes/config/* .DS_Store .token -backups - -settings -settings/* \ No newline at end of file +backups \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f705f3bd91..1ade76db15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,8 +24,6 @@ RUN npm install --loglevel=error && \ pm2 update && \ cd /app/mail && npm install --loglevel=error -EXPOSE 10010 - -EXPOSE 10080 +EXPOSE 10010 10080 10011 ENTRYPOINT ["/entrypoint.sh"] diff --git a/install.sh b/install.sh index b96ea71a80..395bead857 100644 --- a/install.sh +++ b/install.sh @@ -1,18 +1,20 @@ #!/bin/bash +export ARCH=$(uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/ | sed s/s390x/s390x/) + # Dependencies installer for Debian (Ubuntu) based Linux. -if command apt-get -v > /dev/null 2>&1; then +if command apt -v > /dev/null 2>&1; then if ! command curl --version > /dev/null 2>&1; then printf "\n\033[93mHollaEx CLI requires CURL to operate. Installing it now...\033[39m\n" echo "Updating APT list" - sudo apt-get update + sudo apt update IS_APT_UPDATED=true echo "Installing Docker" - if command sudo apt-get install -y curl; then + if command sudo apt install -y curl; then printf "\n\033[92mCURL has been successfully installed!\033[39m\n" echo "Info: $(curl --version)" @@ -20,7 +22,7 @@ if command apt-get -v > /dev/null 2>&1; then else printf "\n\033[91mFailed to install CURL.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y curl'." + echo "Please review the logs and try to manually install it. - 'sudo apt install -y curl'." exit 1; fi @@ -32,11 +34,11 @@ if command apt-get -v > /dev/null 2>&1; then printf "\n\033[93mHollaEx CLI requires Docker to operate. Installing it now...\033[39m\n" echo "Updating APT list" - sudo apt-get update + sudo apt update IS_APT_UPDATED=true echo "Installing Docker" - if command sudo apt-get install -y docker.io; then + if command sudo apt install -y docker.io; then printf "\n\033[92mDocker has been successfully installed!\033[39m\n" echo "Info: $(docker -v)" @@ -51,33 +53,33 @@ if command apt-get -v > /dev/null 2>&1; then else printf "\n\033[91mFailed to install Docker.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y docker.io'." + echo "Please review the logs and try to manually install it. - 'sudo apt install -y docker.io'." exit 1; fi fi - if ! command docker-compose -v > /dev/null 2>&1; then + if ! command docker compose version > /dev/null 2>&1; then - printf "\n\033[93mHollaEx CLI requires Docker-Compose to operate. Installing it now...\033[39m\n" + printf "\n\033[93mHollaEx CLI requires docker compose v2 to operate. Installing it now...\033[39m\n" if [[ ! $IS_APT_UPDATED ]]; then echo "Updating APT list" - sudo apt-get update + sudo apt update fi - if command sudo apt-get install -y docker-compose; then + if command sudo apt install -y docker-compose-v2; then - printf "\n\033[92mDocker-Compose has been successfully installed!\033[39m\n" + printf "\n\033[92mdocker compose v2 has been successfully installed!\033[39m\n" - echo "Info: $(docker-compose -v)" + echo "Info: $(docker compose version)" else - printf "\n\033[91mFailed to install Docker-Compose.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y docker-compose'." + printf "\n\033[91mFailed to install docker compose v2.\033[39m\n" + echo "Please review the logs and try to manually install it. - 'sudo apt install -y docker compose'." exit 1; fi @@ -91,10 +93,10 @@ if command apt-get -v > /dev/null 2>&1; then if [[ ! $IS_APT_UPDATED ]]; then echo "Updating APT list" - sudo apt-get update + sudo apt update fi - if command sudo apt-get install -y jq; then + if command sudo apt install -y jq; then printf "\n\033[92mjq has been successfully installed!\033[39m\n" @@ -103,7 +105,28 @@ if command apt-get -v > /dev/null 2>&1; then else printf "\n\033[91mFailed to install jq.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y jq'." + echo "Please review the logs and try to manually install it. - 'sudo apt install -y jq'." + + fi + + fi + + if ! command yq --version > /dev/null 2>&1; then + + printf "\n\033[93mHollaEx CLI requires yq to operate. Installing it now...\033[39m\n" + + if command sudo curl -L https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_$(uname -s)_$ARCH -o /usr/local/bin/yq; then + + chmod +x /usr/local/bin/yq + + printf "\n\033[92myq has been successfully installed!\033[39m\n" + + echo "Info: $(yq --version)" + + else + + printf "\n\033[91mFailed to install yq.\033[39m\n" + echo "Please review the logs and try to manually install it. - 'sudo apt install -y jq'." fi @@ -116,10 +139,10 @@ if command apt-get -v > /dev/null 2>&1; then if [[ ! $IS_APT_UPDATED ]]; then echo "Updating APT list" - sudo apt-get update + sudo apt update fi - if command sudo apt-get install -y dnsutils; then + if command sudo apt install -y dnsutils; then printf "\n\033[92mnslookup(dnsutils) has been successfully installed!\033[39m\n" @@ -129,7 +152,7 @@ if command apt-get -v > /dev/null 2>&1; then else printf "\n\033[91mFailed to install nslookup.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y dnsutils'." + echo "Please review the logs and try to manually install it. - 'sudo apt install -y dnsutils'." fi @@ -142,11 +165,11 @@ if command apt-get -v > /dev/null 2>&1; then if [[ ! $IS_APT_UPDATED ]]; then echo "Updating APT list" - sudo apt-get update + sudo apt update fi echo "Installing Docker" - if command sudo apt-get install -y postgresql-client; then + if command sudo apt install -y postgresql-client; then printf "\n\033[92mPSQL Client has been successfully installed!\033[39m\n" echo "Info: $(psql --version)" @@ -154,7 +177,7 @@ if command apt-get -v > /dev/null 2>&1; then else printf "\n\033[91mFailed to install PSQL Client.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'sudo apt-get install -y postgresql-client'." + echo "Please review the logs and try to manually install it. - 'sudo apt install -y postgresql-client'." exit 1; fi @@ -228,9 +251,9 @@ elif command brew -v > /dev/null 2>&1; then fi - if ! command docker-compose -v > /dev/null 2>&1; then + if ! command docker compose version > /dev/null 2>&1; then - printf "\n\033[93mHollaEx CLI requires Docker-Compose to operate. Installing it now...\033[39m\n" + printf "\n\033[93mHollaEx CLI requires docker compose to operate. Installing it now...\033[39m\n" if [[ ! $IS_BREW_UPDATED ]]; then @@ -238,16 +261,16 @@ elif command brew -v > /dev/null 2>&1; then brew update fi - if command brew install docker-compose; then + if command brew install docker compose; then - printf "\n\033[92mDocker-Compose has been successfully installed!\033[39m\n" + printf "\n\033[92mdocker compose has been successfully installed!\033[39m\n" - echo "Info: $(docker-compose -v)" + echo "Info: $(docker compose version)" else - printf "\n\033[91mFailed to install Docker-Compose.\033[39m\n" - echo "Please review the logs and try to manually install it. - 'brew install docker-compose'." + printf "\n\033[91mFailed to install docker compose.\033[39m\n" + echo "Please review the logs and try to manually install it. - 'brew install docker compose'." exit 1; fi @@ -279,6 +302,31 @@ elif command brew -v > /dev/null 2>&1; then fi + if ! command yq --version > /dev/null 2>&1; then + + printf "\n\033[93mHollaEx CLI requires yq to operate. Installing it now...\033[39m\n" + + if [[ ! $IS_BREW_UPDATED ]]; then + + echo "Updating Homebrew list" + brew update + fi + + if command brew install yq; then + + printf "\n\033[92myq has been successfully installed!\033[39m\n" + + echo "Info: $(yq --version)" + + else + + printf "\n\033[91mFailed to install yq.\033[39m\n" + echo "Please review the logs and try to manually install it. - 'brew install yq'." + + fi + + fi + if ! command psql --version > /dev/null 2>&1; then printf "\n\033[93mHollaEx CLI requires PSQL Client to operate. Installing it now...\033[39m\n" @@ -366,21 +414,21 @@ elif command yum --version > /dev/null 2>&1; then fi - if ! command docker-compose -v > /dev/null 2>&1; then + if ! command docker compose version > /dev/null 2>&1; then - printf "\n\033[93mHollaEx CLI requires Docker-Compose to operate. Installing it now...\033[39m\n" + printf "\n\033[93mHollaEx CLI requires docker compose to operate. Installing it now...\033[39m\n" - if command sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose; then + if command sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker compose; then - sudo chmod +x /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker compose - printf "\n\033[92mDocker-Compose has been successfully installed!\033[39m\n" + printf "\n\033[92mdocker compose has been successfully installed!\033[39m\n" - echo "Info: $(docker-compose -v)" + echo "Info: $(docker compose version)" else - printf "\n\033[91mFailed to install Docker-Compose.\033[39m\n" + printf "\n\033[91mFailed to install docker compose.\033[39m\n" echo "Please review the logs and try to manually install it. - 'https://github.com/docker/compose/releases'." exit 1; @@ -407,6 +455,27 @@ elif command yum --version > /dev/null 2>&1; then fi + if ! command yq --version > /dev/null 2>&1; then + + printf "\n\033[93mHollaEx CLI requires yq to operate. Installing it now...\033[39m\n" + + if command sudo curl -L https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_$(uname -s)_$ARCH -o /usr/local/bin/yq; then + + chmod +x /usr/local/bin/yq + + printf "\n\033[92myq has been successfully installed!\033[39m\n" + + echo "Info: $(yq --version)" + + else + + printf "\n\033[91mFailed to install yq.\033[39m\n" + echo "Please review the logs and try to manually install it. - 'sudo apt install -y jq'." + + fi + + fi + if ! command nslookup -version > /dev/null 2>&1; then printf "\n\033[93mHollaEx CLI requires nslookup to operate. Installing it now...\033[39m\n" @@ -449,7 +518,7 @@ elif command yum --version > /dev/null 2>&1; then fi -if ! command docker -v > /dev/null 2>&1 || ! command docker-compose -v > /dev/null 2>&1 || ! command curl --version > /dev/null 2>&1 || ! command jq --version > /dev/null 2>&1 || ! command nslookup -version > /dev/null 2>&1 || ! command psql --version > /dev/null 2>&1; then +if ! command docker -v > /dev/null 2>&1 || ! command docker compose version > /dev/null 2>&1 || ! command curl --version > /dev/null 2>&1 || ! command jq --version > /dev/null 2>&1 || ! command nslookup -version > /dev/null 2>&1 || ! command psql --version > /dev/null 2>&1; then if command docker -v > /dev/null 2>&1; then @@ -457,7 +526,7 @@ if ! command docker -v > /dev/null 2>&1 || ! command docker-compose -v > /dev/nu fi - if command docker-compose -v > /dev/null 2>&1; then + if command docker compose version > /dev/null 2>&1; then IS_DOCKER_COMPOSE_INSTALLED=true @@ -486,8 +555,14 @@ if ! command docker -v > /dev/null 2>&1 || ! command docker-compose -v > /dev/nu IS_PSQL_CLIENT_INSTALLED=true fi + + if command yq --version > /dev/null 2>&1; then + + IS_YQ_CLIENT_INSTALLED=true - printf "\n\033[93mNote: HollaEx CLI requires Docker, Docker-Compose, and jq to operate.\033[39m\n\n" + fi + + printf "\n\033[93mNote: HollaEx CLI requires Docker, docker compose, and jq to operate.\033[39m\n\n" # Docker installation status chekc if [[ "$IS_DOCKER_INSTALLED" ]]; then @@ -500,14 +575,14 @@ if ! command docker -v > /dev/null 2>&1 || ! command docker-compose -v > /dev/nu fi - # Docker-compose installation status check + # docker compose installation status check if [[ "$IS_DOCKER_COMPOSE_INSTALLED" ]]; then - printf "\033[92mDocker-Compose: Installed\033[39m\n" + printf "\033[92mdocker compose: Installed\033[39m\n" else - printf "\033[91mDocker-Compose: Not Installed\033[39m\n" + printf "\033[91mdocker compose: Not Installed\033[39m\n" fi @@ -554,6 +629,17 @@ if ! command docker -v > /dev/null 2>&1 || ! command docker-compose -v > /dev/nu fi + # yq installation status check + if [[ "$IS_YQ_INSTALLED" ]]; then + + printf "\033[92myq: Installed\033[39m\n" + + else + + printf "\033[91myq: Not Installed\033[39m\n" + + fi + printf "\n\033[93mPlease install the missing one before you proceed to run exchange.\033[39m\n" else @@ -583,4 +669,103 @@ if [[ "$DOCKER_USERGROUP_ADDED" ]]; then fi + +function kit_cross_compatibility_converter() { + + CONFIG_FILE_PATH=$(pwd)/settings/* + + for i in ${CONFIG_FILE_PATH[@]}; do + source $i + done; + + # File conversion + if [[ -f "$(pwd)/templates/local/$ENVIRONMENT_EXCHANGE_NAME.env.local" ]]; then + + echo "Env file generated with HollaEx CLI v2 has been detected!" + echo "Converting it to the v3 format..." + mv $(pwd)/templates/local/$ENVIRONMENT_EXCHANGE_NAME.env.local $(pwd)/server/hollaex-kit.env + + fi + + + if [[ -f "$(pwd)/templates/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml" ]]; then + + echo "Docker-compose file generated with HollaEx CLI v2 has been detected!" + + echo "Converting the Docker-Compose file..." + yq "del(.services.$ENVIRONMENT_EXCHANGE_NAME-nginx)" $(pwd)/templates/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml > $(pwd)/server/docker-compose-prod.yaml + yq e -i '.services.*.env_file[] = "hollaex-kit.env"' $(pwd)/server/docker-compose-prod.yaml + + echo "name: 'local'" >> $(pwd)/server/docker-compose-prod.yaml + + rm $(pwd)/templates/local/$ENVIRONMENT_EXCHANGE_NAME-docker-compose.yaml + + fi + + if [[ -f "$(pwd)/templates/local/nginx/conf.d/upstream.conf" ]]; then + + echo "Nginx configuration files generated with HollaEx CLI v2 has been detected!" + echo "Copying the existing Nginx files to the new directory..." + mv $(pwd)/templates/local/nginx/conf.d/* $(pwd)/nginx/conf.d + mv $(pwd)/templates/local/nginx/nginx.conf $(pwd)/nginx/nginx.conf + + mv $(pwd)/templates/local/letsencrypt $(pwd)/nginx/ + + echo "Updating the Nginx file to have an existing docker network bind..." + yq e -i ".services |= with_entries(select(.key == \"hollaex-kit-prod-nginx\") | .key = \"$ENVIRONMENT_EXCHANGE_NAME-nginx\")" $(pwd)/nginx/docker-compose.yaml + yq e -i ".services.*.networks[] = \"local_$ENVIRONMENT_EXCHANGE_NAME-network\"" $(pwd)/nginx/docker-compose.yaml + yq e -i ".networks |= with_entries(select(.key == \"local_hollaex-kit-network\") | .key = \"local_$ENVIRONMENT_EXCHANGE_NAME-network\")" $(pwd)/nginx/docker-compose.yaml + + if command docker ps | grep local.*-nginx > /dev/null ; then + + docker compose -f $(pwd)/nginx/docker-compose.yaml down + docker compose -f $(pwd)/nginx/docker-compose.yaml up -d + + fi + + fi + + # Local web docker-compose + + if [[ -f "$(pwd)/templates/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose-web.yaml" ]]; then + + echo "Web doker-compose file generated with HollaEx CLI v2 has been detected." + echo "Converting it..." + mv $(pwd)/templates/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose-web.yaml $(pwd)/web/docker-compose.yaml + + echo "name: 'client'" >> $(pwd)/web/docker-compose.yaml + + fi + + # Kubernetes + # Ingress, Configmap, Secret conversion + if [[ -f "$(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-configmap.yaml" ]]; then + + echo "Kubernetes configmap generated with HollaEx CLI v2 has been detected." + echo "Converting it..." + mv $(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-configmap.yaml $(pwd)/server/tools/kubernetes/env/configmap.yaml + + fi + + if [[ -f "$(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-secret.yaml" ]]; then + + echo "Kubernetes secret generated with HollaEx CLI v2 has been detected." + echo "Converting it..." + mv $(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-secret.yaml $(pwd)/server/tools/kubernetes/env/secret.yaml + + fi + + if [[ -f "$(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-ingress.yaml" ]]; then + + echo "Kubernetes ingress yamls generated with HollaEx CLI v2 has been detected." + echo "Converting it..." + mv $(pwd)/templates/kubernetes/config/${ENVIRONMENT_EXCHANGE_NAME}-ingress.yaml $(pwd)/server/tools/kubernetes/ingress/hollaex-kit-ingress.yaml + + fi + +} + +kit_cross_compatibility_converter; + + exit 0; \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000000..d937f3c2d0 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,8 @@ +FROM nginx:1.25.3-alpine3.18 +RUN apk add --no-cache certbot py-pip && \ + apk add --no-cache --virtual .build-deps build-base libffi-dev openssl-dev python3-dev && \ + pip install certbot-nginx && \ + apk del .build-deps +EXPOSE 80 +EXPOSE 443 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/conf.d/upstream-web.conf b/nginx/conf.d/upstream-web.conf new file mode 100644 index 0000000000..bb4ba79614 --- /dev/null +++ b/nginx/conf.d/upstream-web.conf @@ -0,0 +1,4 @@ + + upstream web { + server hollaex-kit-web:80; + } \ No newline at end of file diff --git a/nginx/conf.d/upstream.conf b/nginx/conf.d/upstream.conf new file mode 100644 index 0000000000..74e8d74166 --- /dev/null +++ b/nginx/conf.d/upstream.conf @@ -0,0 +1,13 @@ + + upstream api { + server hollaex-kit-server-api:10010; + } + + upstream socket { + ip_hash; + server hollaex-kit-server-stream:10080; + } + + upstream plugins { + server hollaex-kit-server-plugins:10011; + } \ No newline at end of file diff --git a/nginx/docker-compose.yaml b/nginx/docker-compose.yaml new file mode 100644 index 0000000000..1fdaf29848 --- /dev/null +++ b/nginx/docker-compose.yaml @@ -0,0 +1,32 @@ +version: '3' +name: "local" +services: + hollaex-kit-prod-nginx: + image: nginx-with-certbot + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + volumes: + - ./:/etc/nginx + - ./logs:/var/log/nginx + - ./static/:/usr/share/nginx/html + - ./letsencrypt:/etc/letsencrypt + ports: + - 80:80 + - 443:443 + environment: + - NGINX_PORT=80 + entrypoint: + - /bin/sh + - -c + - ip -4 route list match 0/0 | awk '{print $$3 " host.access"}' >> /etc/hosts && nginx -g "daemon off;" + networks: + - local_hollaex-kit-network + +networks: + local_hollaex-kit-network: + external: true + + + diff --git a/server/tools/nginx/mime.types b/nginx/mime.types similarity index 100% rename from server/tools/nginx/mime.types rename to nginx/mime.types diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000000..b9cd903b17 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,69 @@ +worker_processes 4; + +error_log /var/log/error.log warn; +pid /var/log/nginx.pid; + +worker_rlimit_nofile 8192; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + include /etc/nginx/proxy.conf; + include /etc/nginx/conf.d/upstream*.conf; + + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] $status ' + '"$request" $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + limit_req_zone $remote_addr zone=api:1m rate=4r/s; + limit_req_zone $remote_addr zone=order:1m rate=5r/s; + +# SERVER BLOCK +server { + listen 80; + server_name _; #Server domain + + access_log /var/log/hollaex.access.log main; + + include /etc/nginx/conf.d/plugin*.conf; + + location / { + proxy_pass http://web; + } + + location /api { + proxy_pass http://api; + + limit_req zone=api burst=14 nodelay; + limit_req_log_level notice; + limit_req_status 429; + + rewrite /api(/|$)(.*) /$2 break; + + } + + location /api/plugins { + proxy_pass http://plugins; + + rewrite /api(/|$)(.*) /$2 break; + } + + location /stream { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_pass http://socket; + } + + error_page 429 /429.html; + location = /429.html { + root /usr/share/nginx/html; + internal; + } + } + } diff --git a/server/tools/nginx/proxy.conf b/nginx/proxy.conf similarity index 100% rename from server/tools/nginx/proxy.conf rename to nginx/proxy.conf diff --git a/server/tools/nginx/static/429.html b/nginx/static/429.html similarity index 63% rename from server/tools/nginx/static/429.html rename to nginx/static/429.html index 3b90326039..937b15e46b 100644 --- a/server/tools/nginx/static/429.html +++ b/nginx/static/429.html @@ -4,6 +4,6 @@
There is a limit of 1 requests per second. Try again soon.
+Please chillex and try again soon.