From 8fd5b4b1bc193d5d283462cb7964d4060b0337ac Mon Sep 17 00:00:00 2001 From: Josepablo Cruz Baas Date: Sat, 28 Mar 2026 21:18:37 +0000 Subject: [PATCH] Enable sandbox mode with CICD deply strategy --- .gitignore | 3 +- .gitlab-ci.yml | 38 ++++++++++++++++++---- Dockerfile | 10 ++++++ scripts/ci_functions.sh | 71 ++++++++++++++++++++++++++++++++++------- 4 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 39c350b..664c985 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ coverage *.sln *.sw? scripts/env.sh -**.zip \ No newline at end of file +**.zip +*.env diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ab4c295..8846f7f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,30 +1,54 @@ stages: - build + - upload - deploy variables: PIPELINE_WORK_DIR: "./" - DOCKERFILE_PATH: "./" BUILD_NAME: "enruta_web_dashboard" - CONTAINER_NAME: "enruta-web_dashboard" - VITE_API_URL: "https://api.etaviaporte.com/api" - PUBLIC_PORT: 8000 - PRIVATE_PORT: 8000 build-job: stage: build script: - . ./scripts/ci_functions.sh - - build_static + - build_production artifacts: paths: - $PIPELINE_WORK_DIR/$BUILD_NAME.zip expire_in: 1 week + only: + - master deploy-job: stage: deploy script: - . ./scripts/ci_functions.sh - - deploy + - deploy_production only: - master + +build-sandbox-job: + stage: build + script: + - . ./scripts/ci_functions.sh + - build_sandbox + only: + - develop + +upload-sandbox-job: + stage: upload + script: + - . ./scripts/ci_functions.sh + - upload_sandbox + only: + - develop + +deploy-sandbox-job: + stage: deploy + script: + - . ./scripts/ci_functions.sh + - deploy_sandbox + only: + - develop + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..50ce6f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM nginx:stable-alpine + +WORKDIR /app + +COPY dist /usr/share/nginx/html + +RUN sed -i.bak '/index.html/ a try_files $uri $uri/ /index.html;' /etc/nginx/conf.d/default.conf + +EXPOSE 80 + diff --git a/scripts/ci_functions.sh b/scripts/ci_functions.sh index b4535ec..fafede0 100644 --- a/scripts/ci_functions.sh +++ b/scripts/ci_functions.sh @@ -3,28 +3,75 @@ source ~/bash_config.sh # Requirements # Node v18 -function build_static(){ +function build_production(){ #Global ENV VAR: BUILD_NAME - #Global ENV VAR: VITE_API_URL nvm use 18 npm install --force 2>/dev/null - set -x - cat dotenv > .env - npm run build 2>/dev/null - cp htaccess dist/.htaccess - zip -r $BUILD_NAME.zip dist/ - set +x + + # Production API + echo "VITE_API_URL=\"https://api.etaviaporte.com/api\"" > .env + echo "VITE_MAP_KEY=\"${CICD_MAP_KEY}\"" >> .env + + set -x + npm run build 2>/dev/null + cp htaccess dist/.htaccess + zip -r ${BUILD_NAME}.zip dist/ + set +x } -function deploy(){ +function deploy_production(){ # Global Env Var: SYSTEM_HOSTINGER_HOSTNAME # Global Env Var: SYSTEM_HOSTINGER_SSH_USERNAME # Global Env Var: SYSTEM_HOSTINGER_SSH_PORT # Global Env Var: BUILD_NAME INSTALL_PATH="public_html/subdomains/console/" set -x - scp ./$BUILD_NAME.zip "$SYSTEM_HOSTINGER_HOSTNAME":~/$INSTALL_PATH - scp ./scripts/ssh_install_script.sh "$SYSTEM_HOSTINGER_HOSTNAME":~/$INSTALL_PATH - ssh "$SYSTEM_HOSTINGER_HOSTNAME" "cd ~/$INSTALL_PATH && bash ssh_install_script.sh && rm ssh_install_script.sh" + scp ./${BUILD_NAME}.zip "${SYSTEM_HOSTINGER_HOSTNAME}":~/${INSTALL_PATH} + scp ./scripts/ssh_install_script.sh "${SYSTEM_HOSTINGER_HOSTNAME}":~/${INSTALL_PATH} + ssh "${SYSTEM_HOSTINGER_HOSTNAME}" "cd ~/${INSTALL_PATH} && bash ssh_install_script.sh && rm ssh_install_script.sh" set +x } + +function build_sandbox(){ + # Global Env Var: CICD_REGISTRY_HOST + # Global Env Var: SANDBOX_HOMEPAGE + CONTAINER_NAME="console" + CONTAINER_VERSION="sandbox" + + # Sandbox API + echo "VITE_API_URL=\"https://dev.api.etaviaporte.com/api\"" > .env + echo "VITE_MAP_KEY=\"${CICD_MAP_KEY}\"" >> .env + + set -x + nvm use 18 + npm install + npm run build + + npm run build 2>/dev/null + cp htaccess dist/.htaccess + + docker rmi -f "${CICD_REGISTRY_HOST}/${CONTAINER_NAME}:${CONTAINER_VERSION}" + docker buildx build --no-cache -t "${CICD_REGISTRY_HOST}/${CONTAINER_NAME}:${CONTAINER_VERSION}" ./ + set +x +} + +function upload_sandbox(){ + # Global Env Var: CICD_REGISTRY_HOST + # Global Env Var: CICD_REGISTRY_USER + # Global Env Var: CICD_REGISTRY_TOKEN + CONTAINER_NAME="console" + CONTAINER_VERSION="sandbox" + + docker login ${CICD_REGISTRY_HOST} -u ${CICD_REGISTRY_USER} -p ${CICD_REGISTRY_TOKEN} + set -x + docker push "${CICD_REGISTRY_HOST}/${CONTAINER_NAME}:${CONTAINER_VERSION}" + set +x +} + +function deploy_sandbox(){ + #Global ENV VAR: CICD_CONSOLE_SANDBOX_WEBHOOK + set -x + curl -X POST "${CICD_CONSOLE_SANDBOX_WEBHOOK}" + set +x +} +