initial commit for full install scripts

This commit is contained in:
starbirdtech383
2024-01-25 18:11:47 +05:30
parent 07c7f6af03
commit 818f8082be
15 changed files with 381 additions and 0 deletions

View File

@@ -0,0 +1 @@
NC_INSTALL_ROOT=./

View File

@@ -0,0 +1,3 @@
conf
data
logs

View File

@@ -0,0 +1,56 @@
# Install full stack nocodb with Docker (compose)
This page provides instructions to install nocodb full stack using Docker. The installation will run multiple contianers in single node.
## Prerequisites
Before you begin, ensure you have the following prerequisites:
- Docker (version 20.10.7 or later)
- Docker-Compose (version 2.17.3 or later)
- Ports 80 and 443 are available
TIP: you could simply run ./pre-req-check.sh from this directory which will check.
## Install
Run install.sh, This script performs pre-requisite check, prompts you through required application properties and finally performs `docker-compose up -d`.
Note: For most cases where any external integration is not required. The defaults properties are just fine.
```
./install.sh
```
* At this point, your installation is completed and you should be able to access your nocodb instance *
### An example output will be like below.
```
```
## Data and Conf directories
This directory acts as the NC_INSTALL_ROOT by default and it will have data, conf directories which are `.gitingore` to avoid accidentlly exposing to git.
```
.
├── conf
│ └── nc_properties.env
├── data
│ ├── nginx
│ ├── nocodb
│ ├── postgres
│ └── redis
├── docker
│ └── docker-compose.yml
```
## Read below, if you wish to understand what does install.sh do
install script performs the following steps
1. pre-req-check.sh and warns if there is anything missing which could potentially cause issues at later stage. However it will let you proceed if you wish to.
2. create application properties file under conf dir which will then be used for future upgrades etc.
3. runs docker-compose up -d
##

View File

@@ -0,0 +1 @@
docker exec -it nginx /etc/init.d/nginx reload

View File

@@ -0,0 +1,12 @@
#!/bin/bash
# starts the docker containers configured in this components
# docker compose dir
#
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
COMPONENT_DIR=${SCRIPT_DIR}/../
cd ${COMPONENT_DIR}/docker
mkdir -p ${COMPONENT_DIR}/data
chmod -R 777 ${COMPONENT_DIR}/data
docker-compose restart nginx

View File

@@ -0,0 +1,91 @@
version: '3.8'
networks:
nocodb-001:
# external: true
services:
redis:
image: redis:latest
container_name: redis
restart: unless-stopped
env_file:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/conf/nc_properties.env
expose:
- "6379"
volumes:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/data/redis:/data
networks:
- nocodb-001
deploy:
resources:
limits:
cpus: '0.5'
memory: 1000M
postgres:
image: postgres:14.7
container_name: postgres
restart: unless-stopped
env_file:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/conf/nc_properties.env
expose:
- "5432"
volumes:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/data/postgres:/var/lib/postgresql/data
networks:
- nocodb-001
deploy:
resources:
limits:
cpus: '1'
memory: 1000M
nocodb:
depends_on:
- postgres
- redis
image: nocodb/nocodb:latest
container_name: nocodb
restart: unless-stopped
env_file:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/conf/nc_properties.env
expose:
- "8080"
volumes:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/data/nocodb:/usr/app/data/
networks:
- nocodb-001
deploy:
resources:
limits:
cpus: '1'
memory: 1000M
nginx:
container_name: nginx
depends_on:
- nocodb
image: nginx
restart: unless-stopped
env_file:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/conf/nc_properties.env
volumes:
- ${NC_INSTALL_ROOT:-/opt/nocodb}/nginx/conf.d:/etc/nginx/conf.d:ro
- ${NC_INSTALL_ROOT:-/opt/nocodb}/nginx/conf:/opt/nocohub/nginx/conf
- ${NC_INSTALL_ROOT:-/opt/nocodb}/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
- ${NC_INSTALL_ROOT:-/opt/nocodb}/data/nginx:/opt/nocohub/nginx/data
# - ../nginx/conf/ssl:/etc/nginx/ssl/:ro
expose:
- "80"
- "443"
ports:
- "80:80"
- "443:443"
networks:
- nocodb-001
deploy:
resources:
limits:
cpus: '1'
memory: 1000M

View File

@@ -0,0 +1,53 @@
#!/bin/bash
# Performs Initial setup and System Requirements Check
## 1. validate system requirements
# a. docker, docker-compose, jq installed
# b. port mapping check
# - port 80,443 are free or being used by nginx container
# - port 8080 is open if used for multi-instance setup
# - port 6379 for redis access
# - port 9001 for minio access
# c. docker repo accessiblity quay.io/minio/minio:RELEASE.2023-12-09T18-17-51Z, redis:latest, postgres:14.7, nocodb/nocodb:latest, nginx
# d. licence check (tbd)
## utility functions
asksure() {
echo -n "Are you sure (Y/N)? "
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}
# -- main line code starts here
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
${SCRIPT_DIR}/pre-req-check.sh
PRE_REQ_SUCCESS=$?
if [[ ${PRE_REQ_SUCCESS} != 0 ]]
then
echo "Few pre-requisites are failing.\n Recommend to resolve and proceed.\n However you could still proceed to install" >&2
else
echo "All pre-requistites are taken care of. Proceed to install.."
fi
if asksure; then
echo "Preparing environment file before install.."
${SCRIPT_DIR}/prepare_env.sh
echo "Installing docker containers"
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml up -d
else
echo "Exiting without install. You can install using docker-compose -f ${SCRIPT_DIR}/docker-compose.yml up -d "
fi

View File

@@ -0,0 +1,5 @@
upstream nocodb_backend {
server nocodb:8080;
# server nocodb-1:8080;
# server nocodb-2:8080;
}

View File

@@ -0,0 +1,28 @@
server {
listen 80;
listen [::]:80;
server_name localhost;
# server_name my.nocodb.com;
# listen 443 default_server ssl;
# listen [::]:443 ssl ;
# ssl_certificate /etc/nginx/ssl/live/status.nocodb.com/fullchain.pem;
# ssl_certificate_key /etc/nginx/ssl/live/status.nocodb.com/privkey.pem;
location / {
proxy_pass http://nocodb_backend;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_intercept_errors on;
error_page 404 = @handle404;
}
location @handle404 {
rewrite ^ /dashboard permanent;
}
}

View File

@@ -0,0 +1,7 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/conf.d/*.conf;
}

View File

@@ -0,0 +1,61 @@
#!/bin/bash
# Performs Initial setup and System Requirements Check
## 1. validate system requirements
# a. docker, docker-compose, jq installed
# b. port mapping check
# - port 80,443 are free or being used by nginx container
# - port 8080 is open if used for multi-instance setup
# - port 6379 for redis access
# - port 9001 for minio access
# c. docker repo accessiblity quay.io/minio/minio:RELEASE.2023-12-09T18-17-51Z, redis:latest, postgres:14.7, nocodb/nocodb:latest, nginx
# d. licence check (tbd)
# -- main line code starts here
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/sbin/util.sh
source ${SCRIPT_DIR}/sbin/install_vars.sh
echo "Performing nocodb system check and setup. This step may require sudo permissions to"
echo "Check if ports are accessible"
PRE_REQ=0
# d. Check if required tools are installed
echo "Checking if required tools (docker, docker-compose, jq, lsof) are installed..."
for tool in docker docker-compose lsof; do
if ! command -v "$tool" &> /dev/null; then
echo "Error: $tool is not installed. Please install it before proceeding."
exit 1
fi
done
# e. Check if NocoDB is already installed and its expected version
# echo "Checking if NocoDB is already installed and its expected version..."
# Replace the following command with the actual command to check NocoDB installation and version
# Example: nocodb_version=$(command_to_get_nocodb_version)
# echo "NocoDB version: $nocodb_install_version"
# f. Port mapping check
echo "Checking port accessibility..."
for port in "${REQUIRED_PORTS[@]}"; do
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; then
echo "Port $port is in use. Please make sure it is free." >&2
PRE_REQ=1
else
echo "Port $port is free."
fi
done
# # g. Docker repository accessibility check
# echo "Checking Docker repository accessibility..."
# for image in "${DOCKER_IMAGES[@]}"; do
# if docker pull "$image" &> /dev/null; then
# echo "Docker image $image is accessible."
# else
# echo "Error: Docker image $image is not accessible. Please check the repository or internet connection."
# PRE_REQ=1
# fi
# done
echo "System check completed successfully."
exit $PRE_REQ

View File

@@ -0,0 +1,41 @@
#!/bin/bash
# prepares env file with all the required env variables.
#
# -- main line code starts here --
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ENV_FILE=${SCRIPT_DIR}/conf/nc_properties.env
bkp_file=${ENV_FILE}-$(date +%s).bak
# Source existing nc_envs.env file to get current values
if [ -f ${ENV_FILE} ]; then
source ${ENV_FILE}
echo "backing up previous ${ENV_FILE} file to ${bkp_file}"
cp ${ENV_FILE} ${bkp_file}
fi
# Array of properties with default values
properties=("NC_INSTALL_ROOT=${SCRIPT_DIR}" "MINIO_ROOT_USER=minioadmin" "MINIO_ROOT_PASSWORD=minioadmin" "POSTGRES_USER=postgres" "POSTGRES_PASSWORD=test123" "POSTGRES_DB=nocodb" "NC_REDIS_URL=redis://redis:6379/4" 'NC_DB=pg://postgres:5432?u=postgres&password=${POSTGRES_PASSWORD:-nocodb}&d=postgres' "NO_COLOR=NEST_JS_LOG_MESSAGE_NO_COLOR_SET_NON_NULL_VALUE" "LOKI_ENDPOINT=http://localhost:3100")
echo "Update or confirm the values to be set"
# Iterate over the properties array and prompt user for input
for prop in "${properties[@]}"; do
key=$(echo "$prop" | cut -d'=' -f1)
default_value="${prop#*=}"
prev_value_or_default=${!key:-${default_value}}
read -p "Enter value for $key (default: ${prev_value_or_default}): " user_input
# Use user input or default value if empty
value=${user_input:-$prev_value_or_default}
# Store key-value pair in a variable
userValues="${userValues}${key}=${value}\n"
done
# Write key-value pairs to nc_envs.env file
echo -e "# Environment Variables\n$userValues" > ${ENV_FILE}
echo "Environment variables written to ${ENV_FILE} file."
echo "creating data conf, data and log directories"
mkdir -p ${INSTALL_ROOT}/conf ${INSTALL_ROOT}/data ${INSTALL_ROOT}/logs

View File

@@ -0,0 +1,3 @@
nocodb_install_version="1.0.0" # Replace with actual version
REQUIRED_PORTS=(80 443)
DOCKER_IMAGES=("redis:latest" "postgres:14.7" "nocodb/nocodb:latest" "nginx")

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# this file contains the utility functions
# used during installation
#
asksure() {
echo -n "Are you sure (Y/N)? "
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}