From f154d5d716cd4ef129fa08a7b22e1119a154d444 Mon Sep 17 00:00:00 2001 From: risadmin_prod Date: Thu, 17 Sep 2026 07:14:32 +0000 Subject: [PATCH] deployment_files --- .../src/main/resources/application.properties | 11 +- .../lib/resources/api_constants.dart | 4 +- sureops/17sep01-back-b/deployment/Dockerfile | 35 +++ sureops/17sep01-back-b/deployment/build.sh | 37 +++ sureops/Dockerfile | 202 ++++++++++++++++ sureops/build.sh | 227 ++++++++++++++++++ sureops/entrypoint.sh | 85 +++++++ sureops/init-db.sh | 146 +++++++++++ sureops/nginx.conf | 49 ++++ sureops/supervisord.conf | 46 ++++ 10 files changed, 833 insertions(+), 9 deletions(-) create mode 100755 sureops/17sep01-back-b/deployment/Dockerfile create mode 100755 sureops/17sep01-back-b/deployment/build.sh create mode 100755 sureops/Dockerfile create mode 100755 sureops/build.sh create mode 100755 sureops/entrypoint.sh create mode 100755 sureops/init-db.sh create mode 100755 sureops/nginx.conf create mode 100755 sureops/supervisord.conf diff --git a/17sep01-back-b/authsec_springboot/backend/src/main/resources/application.properties b/17sep01-back-b/authsec_springboot/backend/src/main/resources/application.properties index 14768ee..67ae400 100644 --- a/17sep01-back-b/authsec_springboot/backend/src/main/resources/application.properties +++ b/17sep01-back-b/authsec_springboot/backend/src/main/resources/application.properties @@ -24,15 +24,15 @@ System.Net.ServicePointManager.Expect100Continue = false; # **** MY SQL DATABASE CONNECTION **** -spring.datasource.url=jdbc:mysql://realit-prod.cj462uqsa4mz.ap-south-1.rds.amazonaws.com:3306/realnet_CNSBENEW?createDatabaseIfNotExist=true +spring.datasource.url=jdbc:mysql://157.66.191.31:3306/dnam?createDatabaseIfNotExist=true spring.datasource.username=cnsdev -spring.datasource.password=cnsdevprod1212 +spring.datasource.password=cnsdev7304 spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect -# Prefix Path +server.servlet.contextPath=/back #spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true @@ -99,7 +99,4 @@ app.oauth2.authorizedRedirectUris=http://localhost:8081/oauth2/redirect,myandroi projectPath=/data angularProjectPath=/data/webui -BACKEND_PORTAL_DOMAIN=http://157.66.191.31:30166 - - - +BACKEND_PORTAL_DOMAIN=http://157.66.191.31:30166 \ No newline at end of file diff --git a/17sep01-frontend-f/authsec_flutter_new/base_project/lib/resources/api_constants.dart b/17sep01-frontend-f/authsec_flutter_new/base_project/lib/resources/api_constants.dart index c965839..7d08af8 100644 --- a/17sep01-frontend-f/authsec_flutter_new/base_project/lib/resources/api_constants.dart +++ b/17sep01-frontend-f/authsec_flutter_new/base_project/lib/resources/api_constants.dart @@ -23,5 +23,5 @@ class ApiConstants { static const getSystemParameters = '$baseUrl/sysparam/getSysParams'; static const updateSystemParams = '$baseUrl/sysparam/updateSysParams'; - static const baseUrl = 'http://localhost:9292'; -} + static const baseUrl ='http://157.66.191.31:46284/back'; +} \ No newline at end of file diff --git a/sureops/17sep01-back-b/deployment/Dockerfile b/sureops/17sep01-back-b/deployment/Dockerfile new file mode 100755 index 0000000..b054e55 --- /dev/null +++ b/sureops/17sep01-back-b/deployment/Dockerfile @@ -0,0 +1,35 @@ +#pulling from github + +FROM alpine/git:v2.30.1 AS code +ARG BUILD_ID +ARG GITEA_USER +ARG GITEA_PASS +RUN echo $BUILD_ID +LABEL stage=builder +LABEL build_id=$BUILD_ID +RUN mkdir repo +WORKDIR /repo +RUN git clone http://$GITEA_USER:$GITEA_PASS@157.66.191.31:3000/risadmin_prod/17sep01.git +#************* Stage 2 - Maven Build ************** +FROM maven:3.9.3 AS mvn +LABEL stage=builder +LABEL build=$BUILD_ID +WORKDIR /workspace/app +COPY --from=code /repo/17sep01/17sep01-back-b/authsec_springboot/backend/ /workspace/app +RUN mkdir builder/ +RUN mvn install -Dmaven.test.skip + +#******** Stage 3 - Docker Build ********* + +#FROM java:8-jdk-alpine +#FROM openjdk:8-jdk-alpine +FROM eclipse-temurin:8-jdk-alpine +LABEL stage=app +LABEL build=$BUILD_ID +RUN mkdir /usr/app +RUN mkdir /data +COPY --from=mvn /workspace/app/target/*jar /usr/app/gtest.jar +RUN mkdir /usr/app/sureops +WORKDIR /usr/app +EXPOSE 9292 +ENTRYPOINT ["java", "-jar", "gtest.jar"] \ No newline at end of file diff --git a/sureops/17sep01-back-b/deployment/build.sh b/sureops/17sep01-back-b/deployment/build.sh new file mode 100755 index 0000000..bf186c3 --- /dev/null +++ b/sureops/17sep01-back-b/deployment/build.sh @@ -0,0 +1,37 @@ +#!/bin/bash +PRJ_NAME=17sep01-back-b +DOCKER_USER=risadmin_prod +DOCKER_PASS=adminprod1234 +DOCKER_URL=157.66.191.31:3000 +#******************** +REPO_NAME=17sep01 +GITEA_USER=risadmin_prod +GITEA_PASS=adminprod1234 +GITEA_EMAIL=ganeshk@dekatc.com +GIT_BRANCH=main +DOMAIN=157.66.191.31:3000 +#WEB-URL-PORT +CONT_PORT=3306 +TARGET_PORT=9292 +PATH_DIR=/data/66158_1789629213511/sureops/17sep01-back-b/deployment +#********************** +cd $PATH_DIR +DOCKER_TAG=1.0 +#docker system prune -f +# Stop any existing containers with the same name and ports +docker stop $PRJ_NAME >/dev/null 2>&1 || true +docker rm $PRJ_NAME >/dev/null 2>&1 || true + +# Build and push the Docker image +DOCKER_BUILDKIT=0 docker build --no-cache -t $DOCKER_URL/$DOCKER_USER/$PRJ_NAME:$DOCKER_TAG --build-arg GITEA_PASS=adminprod1234 --build-arg GITEA_USER=risadmin_prod . +docker login --username=$DOCKER_USER --password=$DOCKER_PASS $DOCKER_URL +docker tag $DOCKER_URL/$DOCKER_USER/$PRJ_NAME:$DOCKER_TAG $DOCKER_URL/$DOCKER_USER/$PRJ_NAME +docker push $DOCKER_URL/$DOCKER_USER/$PRJ_NAME +docker push $DOCKER_URL/$DOCKER_USER/$PRJ_NAME:$DOCKER_TAG +docker logout $DOCKER_URL +#docker system prune -f +# Deploy the image in a Docker container +#docker run -d --name $PRJ_NAME -p $CONT_PORT:$TARGET_PORT $DOCKER_USER/$PRJ_NAME:$DOCKER_TAG + +curl -X GET "http://157.66.191.31:31170/sureops/suredocker/updaterepo?repoName=$REPO_NAME&packageName=$PRJ_NAME" + diff --git a/sureops/Dockerfile b/sureops/Dockerfile new file mode 100755 index 0000000..3cd92a6 --- /dev/null +++ b/sureops/Dockerfile @@ -0,0 +1,202 @@ +######################################## +# Global build arguments +######################################## +ARG GITEA_USER +ARG GITEA_PASS +ARG GITEA_URL=157.66.191.31:3000 +ARG GITEA_ORG +ARG REPO_NAME +ARG GIT_BRANCH=main +ARG JAR_NAME=app-1.0.0.jar + +######################################## +# Stage 1 - Clone Repository + Auto-discover modules +######################################## + +FROM alpine/git:latest AS source + +ARG GITEA_USER +ARG GITEA_PASS +ARG GITEA_URL +ARG GITEA_ORG +ARG REPO_NAME +ARG GIT_BRANCH + +WORKDIR /src + +RUN git clone --branch ${GIT_BRANCH} --single-branch \ + http://${GITEA_USER}:${GITEA_PASS}@${GITEA_URL}/${GITEA_ORG}/${REPO_NAME}.git + +RUN set -e; \ + BACKEND_DIR=$(find /src/${REPO_NAME} -maxdepth 1 -type d -name "*-b" | head -n1); \ + FRONTEND_DIR=$(find /src/${REPO_NAME} -maxdepth 1 -type d -name "*-f" | head -n1); \ + if [ -z "$BACKEND_DIR" ]; then \ + echo "ERROR: No backend module folder (ending in -b) found under /src/${REPO_NAME}"; \ + ls -la /src/${REPO_NAME}; \ + exit 1; \ + fi; \ + if [ -z "$FRONTEND_DIR" ]; then \ + echo "ERROR: No frontend module folder (ending in -f) found under /src/${REPO_NAME}"; \ + ls -la /src/${REPO_NAME}; \ + exit 1; \ + fi; \ + echo "Backend module found : $BACKEND_DIR"; \ + echo "Frontend module found : $FRONTEND_DIR"; \ + ln -s "$BACKEND_DIR" /src/backend-module; \ + ln -s "$FRONTEND_DIR" /src/frontend-module + + +######################################## +# Stage 2 - Backend Build +######################################## + +FROM maven:3.9.3-eclipse-temurin-8 AS backend-build + +WORKDIR /workspace/backend + +COPY --from=source \ + /src/backend-module/authsec_springboot/backend/ \ + ./ + +RUN mvn clean package -DskipTests + + +######################################## +# Stage 3 - Frontend Build (Flutter APK) +######################################## + +FROM ghcr.io/cirruslabs/flutter:3.27.3 AS frontend-build + +WORKDIR /workspace/frontend + +COPY --from=source \ + /src/frontend-module/authsec_flutter_new/base_project/ \ + ./ + +RUN flutter pub get + +# Optional project-specific cleanup script, skipped if absent +RUN if [ -f ./remove_unused.sh ]; then \ + chmod +x ./remove_unused.sh && ./remove_unused.sh; \ + else \ + echo "remove_unused.sh not found, skipping"; \ + fi + +RUN flutter clean +RUN flutter pub get +RUN flutter build apk --target-platform android-arm64 + + +######################################## +# Stage 4 - Runtime +######################################## + +FROM ubuntu:22.04 + +ARG REPO_NAME +ARG JAR_NAME + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && \ + apt-get install -y \ + openjdk-17-jre \ + mysql-server \ + nginx \ + supervisor \ + curl \ + wget \ + git \ + nano \ + net-tools \ + procps \ + ca-certificates && \ + rm -f /etc/nginx/conf.d/default.conf && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +######################################## +# Create Directories +######################################## + +RUN mkdir -p \ + /opt/backend \ + /opt/database \ + /usr/share/nginx/html \ + /var/log/supervisor + + +######################################## +# Backend +######################################## + +COPY --from=backend-build \ + /workspace/backend/target/${JAR_NAME} \ + /opt/backend/app.jar + + +######################################## +# SQL Files (optional - only copied if present in repo) +######################################## + +COPY --from=source \ + /src/backend-module/authsec_springboot/backend/src/main/resources/schema.sql \ + /opt/database/schema.sql + +COPY --from=source \ + /src/backend-module/authsec_springboot/backend/src/main/resources/data.sql \ + /opt/database/data.sql + + +######################################## +# Frontend (APK served for download) +######################################## + +COPY --from=frontend-build \ + /workspace/frontend/build/app/outputs/flutter-apk/app-release.apk \ + /usr/share/nginx/html/app-release.apk + + +######################################## +# Configuration Files +######################################## + +COPY --from=source \ + /src/${REPO_NAME}/sureops/entrypoint.sh \ + /usr/local/bin/entrypoint.sh + +COPY --from=source \ + /src/${REPO_NAME}/sureops/init-db.sh \ + /usr/local/bin/init-db.sh + +COPY --from=source \ + /src/${REPO_NAME}/sureops/supervisord.conf \ + /etc/supervisor/conf.d/supervisord.conf + +COPY --from=source \ + /src/${REPO_NAME}/sureops/nginx.conf \ + /etc/nginx/nginx.conf + + +######################################## +# Permissions +######################################## + +RUN chmod +x /usr/local/bin/entrypoint.sh && \ + chmod +x /usr/local/bin/init-db.sh + + +######################################## +# Ports +######################################## + +EXPOSE 80 +EXPOSE 9292 + + +######################################## +# Start +######################################## + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] \ No newline at end of file diff --git a/sureops/build.sh b/sureops/build.sh new file mode 100755 index 0000000..f426415 --- /dev/null +++ b/sureops/build.sh @@ -0,0 +1,227 @@ +#!/bin/bash + +set -Eeuo pipefail + +SECONDS=0 + +######################################## +# Error Handling +######################################## + +trap 'echo "ERROR: Script failed at line ${LINENO}. Command: ${BASH_COMMAND}" >&2' ERR + +######################################## +# Project Identity +# NOTE: Fill these in per-project. Do not +# hardcode values here that other projects +# also use, to avoid collisions. +######################################## + +PRJ_NAME="17sep01-frontend-f" + +IMAGE_PROJECT_NAME="${PRJ_NAME}" + +######################################## +# Gitea Source Repository +######################################## + +GITEA_USER="risadmin_prod" +GITEA_PASS="adminprod1234" +GITEA_URL="http://157.66.191.31:3000" +GITEA_URL="${GITEA_URL#http://}" +GITEA_ORG="risadmin_prod" +GITEA_EMAIL="ganeshk@dekatc.com" + +REPO_NAME="17sep01" +GIT_BRANCH=main + +######################################## +# Module Paths (per project, inside -b / -f dirs) +######################################## + +JAR_NAME=app-1.0.0.jar +BACKEND_SUBPATH="" # e.g. authsec_springboot/backend +FRONTEND_SUBPATH="" # e.g. authsec_flutter_new/frontend/flutter_new +APK_NAME=app-release.apk + +######################################## +# Docker Registry +######################################## + +DOCKER_USER=risadmin_prod +DOCKER_PASS=adminprod1234 +DOCKER_URL=157.66.191.31:3000 + +DOCKER_TAG=1.0 + +######################################## +# Build Path +######################################## + +PATH_DIR="/data/66158_1789629213511/sureops" + +######################################## +# Image Names +######################################## + +IMAGE_NAME="${DOCKER_URL}/${DOCKER_USER}/${IMAGE_PROJECT_NAME}:${DOCKER_TAG}" +LATEST_IMAGE="${DOCKER_URL}/${DOCKER_USER}/${IMAGE_PROJECT_NAME}:latest" + +######################################## +# Display Configuration +######################################## + +echo "==========================================" +echo " SINGLE CONTAINER BUILD (Flutter + SpringBoot + MySQL)" +echo "==========================================" + +echo "Project Name : ${PRJ_NAME}" +echo "Container Name : ${IMAGE_PROJECT_NAME}" +echo "Repository : ${GITEA_ORG}/${REPO_NAME}" +echo "Branch : ${GIT_BRANCH}" +echo "Docker Image : ${IMAGE_NAME}" +echo "Latest Image : ${LATEST_IMAGE}" +echo "Build Path : ${PATH_DIR}" + +echo "==========================================" + +######################################## +# Validate Configuration +######################################## + +echo "Validating configuration..." + +REQUIRED_VARIABLES=( + "PRJ_NAME" + "GITEA_USER" + "GITEA_PASS" + "GITEA_URL" + "GITEA_ORG" + "REPO_NAME" + "GIT_BRANCH" + "JAR_NAME" + "BACKEND_SUBPATH" + "FRONTEND_SUBPATH" + "DOCKER_USER" + "DOCKER_PASS" + "DOCKER_URL" + "DOCKER_TAG" + "PATH_DIR" +) + +for VARIABLE in "${REQUIRED_VARIABLES[@]}"; do + VALUE="${!VARIABLE:-}" + + if [[ -z "${VALUE}" ]]; then + echo "ERROR: Required variable '${VARIABLE}' is empty." + exit 1 + fi + + if [[ "${VALUE}" == "<"*">" ]]; then + echo "ERROR: Variable '${VARIABLE}' still contains placeholder value: ${VALUE}" + exit 1 + fi +done + +echo "Configuration validation successful." + +######################################## +# Check Docker +######################################## + +if ! command -v docker >/dev/null 2>&1; then + echo "ERROR: Docker is not installed or not available in PATH." + exit 1 +fi + +if ! docker info >/dev/null 2>&1; then + echo "ERROR: Docker daemon is not running or current user has no permission." + exit 1 +fi + +######################################## +# Change Directory +######################################## + +if [[ ! -d "${PATH_DIR}" ]]; then + echo "ERROR: Directory not found: ${PATH_DIR}" + exit 1 +fi + +cd "${PATH_DIR}" + +######################################## +# Build Docker Image +######################################## + +echo "==========================================" +echo " BUILDING DOCKER IMAGE" +echo "==========================================" + +docker build \ + --no-cache \ + --build-arg "GITEA_USER=${GITEA_USER}" \ + --build-arg "GITEA_PASS=${GITEA_PASS}" \ + --build-arg "GITEA_URL=${GITEA_URL}" \ + --build-arg "GITEA_ORG=${GITEA_ORG}" \ + --build-arg "REPO_NAME=${REPO_NAME}" \ + --build-arg "GIT_BRANCH=${GIT_BRANCH}" \ + --build-arg "JAR_NAME=${JAR_NAME}" \ + --build-arg "BACKEND_SUBPATH=${BACKEND_SUBPATH}" \ + --build-arg "FRONTEND_SUBPATH=${FRONTEND_SUBPATH}" \ + --build-arg "APK_NAME=${APK_NAME}" \ + -t "${IMAGE_NAME}" \ + . + +echo "Docker build successful." + +######################################## +# Verify Image +######################################## + +if ! docker image inspect "${IMAGE_NAME}" >/dev/null 2>&1; then + echo "ERROR: Docker image was not created: ${IMAGE_NAME}" + exit 1 +fi + +docker images "${IMAGE_NAME}" + +######################################## +# Docker Registry Login + Push +######################################## + +if ! echo "${DOCKER_PASS}" | docker login \ + --username "${DOCKER_USER}" \ + --password-stdin \ + "${DOCKER_URL}"; then + + echo "ERROR: Docker registry login failed." + exit 1 +fi + +docker tag "${IMAGE_NAME}" "${LATEST_IMAGE}" + +docker push "${IMAGE_NAME}" +docker push "${LATEST_IMAGE}" + +docker logout "${DOCKER_URL}" || true + +######################################## +# Deployment Note +# +# DO NOT RUN CONTAINER HERE. +# Deployment service will perform: +# docker pull / docker stop / docker rm / docker run +######################################## + +echo "==========================================" +echo " BUILD AND PUSH COMPLETED" +echo "==========================================" +echo "Project Name : ${PRJ_NAME}" +echo "Image : ${IMAGE_NAME}" +echo "Latest Image : ${LATEST_IMAGE}" + +DURATION="${SECONDS}" +echo "Total time taken: $((DURATION / 60)) min $((DURATION % 60)) sec" + +exit 0 diff --git a/sureops/entrypoint.sh b/sureops/entrypoint.sh new file mode 100755 index 0000000..802bfb8 --- /dev/null +++ b/sureops/entrypoint.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +set -e + +echo "========================================" +echo " Starting Combined Application Container" +echo " Flutter APK + Backend + MySQL" +echo "========================================" + +# ======================================== +# Project-specific DB name +# Fill this in per project so each combined +# container keeps its own isolated local DB +# and never collides with another project. +# ======================================== + +DB_NAME="" + +# ======================================== +# Start MySQL +# ======================================== + +echo "Starting MySQL..." + +service mysql start + +echo "Waiting for MySQL..." + +until mysqladmin ping -h "127.0.0.1" --silent; do + echo "MySQL is not ready yet..." + sleep 2 +done + +echo "MySQL Started Successfully." + +echo "Setting MySQL root password..." +mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Root@1234';" 2>/dev/null || \ +mysqladmin -u root password 'Root@1234' 2>/dev/null || \ +echo "Root password already set or using socket auth, continuing..." + +# ======================================== +# Initialize Database +# ======================================== + +if [ -f "/usr/local/bin/init-db.sh" ]; then + + echo "========================================" + echo " Initializing Database" + echo "========================================" + + chmod +x /usr/local/bin/init-db.sh + + DB_NAME="${DB_NAME}" /usr/local/bin/init-db.sh + + echo "Database Initialization Completed." + +else + + echo "init-db.sh not found." + echo "Skipping database initialization." + +fi + +# ======================================== +# Force Backend to use local combined-container MySQL +# (overrides application.properties datasource without +# touching the template file, so standalone/multi-container +# builds remain unaffected) +# ======================================== + +export SPRING_DATASOURCE_URL="jdbc:mysql://127.0.0.1:3306/${DB_NAME}?createDatabaseIfNotExist=true" +export SPRING_DATASOURCE_USERNAME="root" +export SPRING_DATASOURCE_PASSWORD="Root@1234" + +# ======================================== +# Start Supervisor +# ======================================== + +echo "========================================" +echo " Starting Supervisor" +echo "========================================" + +exec /usr/bin/supervisord \ + -n \ + -c /etc/supervisor/conf.d/supervisord.conf \ No newline at end of file diff --git a/sureops/init-db.sh b/sureops/init-db.sh new file mode 100755 index 0000000..432eee8 --- /dev/null +++ b/sureops/init-db.sh @@ -0,0 +1,146 @@ +#!/bin/bash + +set -e + +# ======================================== +# MySQL Configuration +# ======================================== + +MYSQL_USER="root" +MYSQL_PASS="Root@1234" + +# DB_NAME is passed in from entrypoint.sh (per-project, unique). +# Fallback below only used if script is run standalone. +DB_NAME="${DB_NAME:-}" + +SQL_DIR="${SQL_DIR:-/opt/database}" + +echo "========================================" +echo " Database Initialization" +echo "========================================" +echo "Database : ${DB_NAME}" +echo "SQL Dir : ${SQL_DIR}" +echo "========================================" + + +# ======================================== +# Create Database +# ======================================== + +echo "Creating database if not exists..." + +mysql \ + -u"${MYSQL_USER}" \ + -p"${MYSQL_PASS}" \ + -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\`;" + +echo "Database ready." + + +# ======================================== +# Check Existing Tables +# ======================================== + +echo "Checking database initialization..." + +TABLE_COUNT=$( + mysql \ + -u"${MYSQL_USER}" \ + -p"${MYSQL_PASS}" \ + -N -s \ + -e "SELECT COUNT(*) + FROM information_schema.tables + WHERE table_schema='${DB_NAME}';" +) + +echo "Existing tables: ${TABLE_COUNT}" + + +# ======================================== +# Initialize Database +# ======================================== + +if [ "${TABLE_COUNT}" -eq 0 ]; then + + echo "Fresh database detected." + echo "Searching SQL files in ${SQL_DIR}..." + + # ------------------------------------ + # Import SQL files in FIXED order: + # schema.sql (structure) MUST run before + # data.sql (inserts), otherwise inserts + # fail with "table doesn't exist". + # ------------------------------------ + + if [ -d "${SQL_DIR}" ]; then + + ORDERED_FILES=("schema.sql" "data.sql") + IMPORTED_ANY=false + + for FILE_NAME in "${ORDERED_FILES[@]}"; do + + SQL_FILE="${SQL_DIR}/${FILE_NAME}" + + if [ -f "${SQL_FILE}" ]; then + + echo "----------------------------------------" + echo "Importing: ${SQL_FILE}" + echo "----------------------------------------" + + mysql \ + -u"${MYSQL_USER}" \ + -p"${MYSQL_PASS}" \ + "${DB_NAME}" < "${SQL_FILE}" + + echo "Imported successfully: ${SQL_FILE}" + IMPORTED_ANY=true + + else + echo "Not found, skipping: ${SQL_FILE}" + fi + + done + + # Import any other .sql files not in the fixed list + OTHER_FILES=$(find "${SQL_DIR}" -maxdepth 1 -type f -name "*.sql" \ + ! -name "schema.sql" ! -name "data.sql" | sort) + + for SQL_FILE in ${OTHER_FILES}; do + + echo "----------------------------------------" + echo "Importing (extra): ${SQL_FILE}" + echo "----------------------------------------" + + mysql \ + -u"${MYSQL_USER}" \ + -p"${MYSQL_PASS}" \ + "${DB_NAME}" < "${SQL_FILE}" + + echo "Imported successfully: ${SQL_FILE}" + IMPORTED_ANY=true + + done + + if [ "${IMPORTED_ANY}" = false ]; then + echo "No SQL files found." + fi + + else + + echo "WARNING: SQL directory does not exist:" + echo "${SQL_DIR}" + + fi + + echo "========================================" + echo " Database initialization completed." + echo "========================================" + +else + + echo "========================================" + echo " Database already initialized." + echo " Skipping SQL import." + echo "========================================" + +fi \ No newline at end of file diff --git a/sureops/nginx.conf b/sureops/nginx.conf new file mode 100755 index 0000000..cf263d7 --- /dev/null +++ b/sureops/nginx.conf @@ -0,0 +1,49 @@ +events { + worker_connections 768; +} + +http { + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + + listen 80; + server_name _; + root /usr/share/nginx/html; + + # ========================================== + # APK DOWNLOAD + # Serves the built APK for direct download, + # e.g. http:///app-release.apk + # ========================================== + + location / { + autoindex on; + try_files $uri $uri/ =404; + } + + location ~ \.apk$ { + add_header Content-Disposition "attachment"; + default_type application/vnd.android.package-archive; + } + + # ========================================== + # BACKEND (handles /backend/ AND //backend/) + # ========================================== + + location ~ ^/(?:[^/]+/)*backend/(.*)$ { + + proxy_pass http://127.0.0.1:9292/$1$is_args$args; + + proxy_http_version 1.1; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Authorization $http_authorization; + } + } +} \ No newline at end of file diff --git a/sureops/supervisord.conf b/sureops/supervisord.conf new file mode 100755 index 0000000..547b4ef --- /dev/null +++ b/sureops/supervisord.conf @@ -0,0 +1,46 @@ +[supervisord] +nodaemon=true +user=root + +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +; ========================================== +; Spring Boot +; ========================================== + +[program:springboot] + +command=java -jar /opt/backend/app.jar + +directory=/opt/backend + +autostart=true +autorestart=true + +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 + +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +priority=20 + +; ========================================== +; Nginx (serves APK download + proxies backend) +; ========================================== + +[program:nginx] + +command=/usr/sbin/nginx -g "daemon off;" + +autostart=true +autorestart=true + +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 + +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +priority=30 \ No newline at end of file