Enable sandbox mode with CICD deply strategy
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -28,3 +28,4 @@ coverage
|
||||
*.sw?
|
||||
scripts/env.sh
|
||||
**.zip
|
||||
*.env
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user