Compare commits

..

26 Commits

Author SHA1 Message Date
a26b88def7 Atualizar install.sh 2024-11-23 23:36:20 +00:00
03c8cf4d07 Atualizar install.sh 2024-11-23 23:25:33 +00:00
7b74b441ff Atualizar docker-compose.yaml 2024-11-23 20:26:43 +00:00
3c9610ce4f Atualizar docker-compose.yaml 2024-11-23 20:25:56 +00:00
f3870d98b7 Atualizar install.sh 2024-11-23 20:25:21 +00:00
1680e2aa2a Atualizar docker-compose.yaml 2024-11-23 20:17:18 +00:00
7b77f58079 Atualizar docker-compose.yaml 2024-11-23 20:12:52 +00:00
7fcf93cfa1 Atualizar install.sh 2024-11-23 18:56:06 +00:00
584a6fa3d2 Atualizar docker-compose.yaml 2024-11-23 18:50:01 +00:00
49dadeccf7 Atualizar install.sh 2024-11-23 18:45:08 +00:00
006a6819e2 Atualizar install.sh 2024-11-23 18:42:53 +00:00
3c9e329121 Adicionar docker-compose.yaml 2024-11-23 18:42:40 +00:00
4c59d8d898 Atualizar install.sh 2024-11-23 17:10:56 +00:00
db84cec53e Atualizar README.md 2024-11-23 17:08:56 +00:00
f07e72a98a Atualizar install.sh 2024-11-23 17:02:16 +00:00
e25feea97b Atualizar install.sh 2024-11-23 17:01:20 +00:00
53d2410ce3 Atualizar install.sh 2024-11-23 16:56:08 +00:00
677093396f Atualizar install.sh 2024-11-23 16:48:35 +00:00
5224c00c4b Atualizar install.sh 2024-11-23 16:45:51 +00:00
a5fbd2f300 Atualizar install.sh 2024-11-23 16:43:22 +00:00
ed8b09a4bf Merge pull request 'Atualizar install.sh' (#2) from wallaceosmar-patch-1 into main
Reviewed-on: #2
2024-11-23 16:42:43 +00:00
ec183b9d58 Atualizar install.sh 2024-11-23 16:42:06 +00:00
af8f4d7d75 Atualizar README.md 2024-11-23 16:40:43 +00:00
89ee0a70cf Merge pull request 'Install' (#1) from wallaceosmar-patch-1 into main
Reviewed-on: #1
2024-11-23 16:35:06 +00:00
0c243d6bb1 Adicionar kube-deploy.yaml 2024-11-23 16:34:30 +00:00
d33f506219 Adicionar install.sh 2024-11-23 16:33:29 +00:00
4 changed files with 583 additions and 0 deletions

View File

@ -1,2 +1,7 @@
# nexo-cloud-scripts
Installation scripts
```
curl -s https://git.masscivicdynamic.com/wallaceosmar/nexo-cloud-scripts/raw/branch/main/install.sh -o install.sh && bash install.sh && rm install.sh
```

104
docker-compose.yaml Normal file
View File

@ -0,0 +1,104 @@
services:
nexo-cloud:
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
ports:
- "8080:8080"
environment:
- SSL_MODE=${SSL_MODE-off}
- APP_KEY=${APP_KEY}
- APP_NAME=${APP_NAME}
- DB_CONNECTION=${DB_CONNECTION:-pgsql}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_PASSWORD=${REDIS_PASSWORD}
- APP_PREVIOUS_KEYS=${APP_PREVIOUS_KEYS}
- PHP_OPCACHE_ENABLE=${PHP_OPCACHE_ENABLE:-1}
- LOG_CHANNEL=${LOG_CHANNEL:-stack}
networks:
- nexo-cloud
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
reverb:
condition: service_healthy
volumes:
- /data/nexo-cloud/logs:/var/www/html/storage/logs
- /data/nexo-cloud/ssh:/var/www/html/storage/app/ssh
- /data/nexo-cloud/applications:/var/www/html/storage/app/applications
- /data/nexo-cloud/databases:/var/www/html/storage/app/databases
- /data/nexo-cloud/services:/var/www/html/storage/app/services
- /data/nexo-cloud/backups:/var/www/html/storage/app/backups
postgres:
image: postgres:16-alpine
environment:
- POSTGRES_USER=${DB_USERNAME:-nexo-cloud}
- POSTGRES_PASSWORD=${DB_PASSWORD:-nexo-cloud}
- POSTGRES_DB=${DB_DATABASE:-nexo-cloud}
networks:
- nexo-cloud
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${DB_USERNAME}", "-d", "${DB_DATABASE:-nexo-cloud}" ]
interval: 5s
retries: 10
timeout: 2s
redis:
image: redis:7.2-alpine
command: redis-server --save 20 1 --loglevel warning --requirepass ${REDIS_PASSWORD}
environment:
- REDIS_PASSWORD="${REDIS_PASSWORD}"
networks:
- nexo-cloud
healthcheck:
test: redis-cli ping
interval: 5s
retries: 10
timeout: 2s
task:
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
command: ["php", "/var/www/html/artisan", "schedule:work"]
stop_signal: SIGTERM
networks:
- nexo-cloud
healthcheck:
test: ["CMD", "healthcheck-schedule"]
start_period: 10s
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
queue:
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
command: [ "php", "/var/www/html/artisan", "queue:work", "--tries=3" ]
stop_signal: SIGTERM
networks:
- nexo-cloud
healthcheck:
test: [ "CMD", "healthcheck-queue" ]
start_period: 10s
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
reverb:
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
command: [ "php", "/var/www/html/artisan", "--port=8000", "reverb:start" ]
stop_signal: SIGTERM
environment:
- REVERB_APP_ID=${REVERB_APP_ID:-271026}
- REVERB_APP_KEY=${REVERB_APP_KEY:-dyadpyflxsz00fd60az2}
- REVERB_APP_SECRET=${REVERB_APP_SECRET:-quuxylmbloar05e6kk0e}
- REVERB_HOST="${REVERB_HOST:-*}"
- REVERB_PORT=${REVERB_PORT:-8000}
- REVERB_SCHEME=${REVERB_SCHEME:-http}
healthcheck:
test: [ "CMD", "healthcheck-reverb" ]
start_period: 10s
ports:
- "8000:8000"
networks:
nexo-cloud:

239
install.sh Normal file
View File

@ -0,0 +1,239 @@
#!/bin/bash
# URLs for configuration files
DOCKER_COMPOSE_URL="https://git.masscivicdynamic.com/masscivicdynamic/nexo-cloud-scripts/raw/branch/main/docker-compose.yml"
KUBERNETES_DEPLOY_URL="https://git.masscivicdynamic.com/masscivicdynamic/nexo-cloud-scripts/raw/branch/main/kube-deploy.yaml"
ENV_FILE="/data/nexo-cloud/.env"
DATA_DIR="/data/nexo-cloud"
SSL_DIR="$DATA_DIR/ssh"
KUBE_DIR="$DATA_DIR/kubernetes"
SSL_CERT="$SSL_DIR/server.crt"
SSL_KEY="$SSL_DIR/server.key"
KUBECONFIG_FILE="$KUBE_DIR/config"
# Minimum disk space requirements (in GB)
MIN_TOTAL_DISK_SPACE=30
MIN_AVAILABLE_DISK_SPACE=20
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to generate a random password
generate_random_password() {
echo "$(openssl rand -base64 16)"
}
# Function to generate an APP_KEY
generate_app_key() {
echo "$(openssl rand -base64 32)"
}
# Function to generate SSL certificate
generate_ssl_certificate() {
if [ ! -f "$SSL_CERT" ] || [ ! -f "$SSL_KEY" ]; then
echo "Generating SSL certificate..."
mkdir -p "$SSL_DIR"
openssl req -newkey rsa:2048 -nodes -keyout "$SSL_KEY" \
-x509 -days 365 -out "$SSL_CERT" -subj "/CN=NexoCloud"
echo "SSL certificate generated and stored in $SSL_DIR."
else
echo "SSL certificate already exists in $SSL_DIR."
fi
}
# Function to check disk space
check_disk_space() {
local total_space=$(df --output=size "$DATA_DIR" | tail -n 1 | awk '{print $1}')
local available_space=$(df --output=avail "$DATA_DIR" | tail -n 1 | awk '{print $1}')
local total_space_gb=$((total_space / 1024 / 1024))
local available_space_gb=$((available_space / 1024 / 1024))
if [ "$total_space_gb" -lt "$MIN_TOTAL_DISK_SPACE" ]; then
echo "Error: Total disk space is less than $MIN_TOTAL_DISK_SPACE GB."
exit 1
fi
if [ "$available_space_gb" -lt "$MIN_AVAILABLE_DISK_SPACE" ]; then
echo "Error: Available disk space is less than $MIN_AVAILABLE_DISK_SPACE GB."
exit 1
fi
}
# Function to create the data directory and subdirectories if they don't exist
ensure_data_directory() {
if [ ! -d "$DATA_DIR" ]; then
echo "Creating data directory at $DATA_DIR..."
mkdir -p "$DATA_DIR"
fi
# Create subdirectories
for subdir in logs ssh applications databases services backups kubernetes; do
if [ ! -d "$DATA_DIR/$subdir" ]; then
echo "Creating subdirectory $subdir in $DATA_DIR..."
mkdir -p "$DATA_DIR/$subdir"
fi
done
echo "Directories created successfully."
}
# Function to copy kubeconfig file if Kubernetes is installed
copy_kubeconfig_file() {
if command_exists kubectl; then
echo "Kubernetes detected. Checking kubeconfig..."
if [ -f "$HOME/.kube/config" ]; then
mkdir -p "$KUBE_DIR"
cp "$HOME/.kube/config" "$KUBECONFIG_FILE"
echo "Kubeconfig file copied to $KUBECONFIG_FILE."
else
echo "Kubeconfig file not found in $HOME/.kube/config."
fi
elif command_exists k3s; then
echo "K3s detected. Checking kubeconfig..."
if [ -f "/etc/rancher/k3s/k3s.yaml" ]; then
mkdir -p "$KUBE_DIR"
cp "/etc/rancher/k3s/k3s.yaml" "$KUBECONFIG_FILE"
echo "Kubeconfig file copied to $KUBECONFIG_FILE."
else
echo "K3s kubeconfig file not found in /etc/rancher/k3s/k3s.yaml."
fi
else
echo "No Kubernetes or K3s installation detected. Skipping kubeconfig copy."
fi
}
# Function to handle the .env file
handle_env_file() {
if [ ! -f "$ENV_FILE" ]; then
echo "Environment file not found. Creating a new one."
touch "$ENV_FILE"
fi
APP_KEY=$(generate_app_key)
DB_USERNAME="nexo-cloud"
DB_PASSWORD=$(generate_random_password)
REDIS_PASSWORD=$(generate_random_password)
# Ask if user wants to change APP_NAME
read -p "Do you want to change the APP_NAME? (y/n) [default: NexoCloud]: " change_app_name
if [ "$change_app_name" == "y" ] || [ "$change_app_name" == "Y" ]; then
read -p "Enter the new APP_NAME: " new_app_name
APP_NAME="$new_app_name"
else
APP_NAME="NexoCloud"
fi
# Update environment variables
sed -i '/^APP_NAME=/d' "$ENV_FILE"
echo "APP_NAME=$APP_NAME" >> "$ENV_FILE"
if grep -q "^APP_KEY=" "$ENV_FILE"; then
PREVIOUS_KEYS=$(grep "^APP_PREVIOUS_KEYS=" "$ENV_FILE" | cut -d'=' -f2)
NEW_PREVIOUS_KEYS="${PREVIOUS_KEYS},$(grep "^APP_KEY=" "$ENV_FILE" | cut -d'=' -f2)"
sed -i '/^APP_PREVIOUS_KEYS=/d' "$ENV_FILE"
echo "APP_PREVIOUS_KEYS=$NEW_PREVIOUS_KEYS" >> "$ENV_FILE"
else
echo "APP_PREVIOUS_KEYS=$APP_KEY" >> "$ENV_FILE"
fi
sed -i '/^APP_KEY=/d' "$ENV_FILE"
echo "APP_KEY=$APP_KEY" >> "$ENV_FILE"
if ! grep -q "^DB_USERNAME=" "$ENV_FILE"; then
echo "DB_USERNAME=$DB_USERNAME" >> "$ENV_FILE"
fi
if ! grep -q "^DB_PASSWORD=" "$ENV_FILE"; then
echo "DB_PASSWORD=$DB_PASSWORD" >> "$ENV_FILE"
fi
if ! grep -q "^REDIS_PASSWORD=" "$ENV_FILE"; then
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> "$ENV_FILE"
fi
echo "Environment variables configured in $ENV_FILE."
}
# Function to set up Docker
setup_docker() {
docker swarm init
curl -o "$DATA_DIR/docker-compose.yml" "$DOCKER_COMPOSE_URL"
docker-compose -f "$DATA_DIR/docker-compose.yml" up -d
}
# Function to deploy Kubernetes application
deploy_kubernetes() {
curl -o "$DATA_DIR/kubernetes/kube-deploy.yaml" "$KUBERNETES_DEPLOY_URL"
kubectl apply -f "$DATA_DIR/kubernetes/kube-deploy.yaml"
}
# Main deployment logic
deploy_application() {
echo "Deploying the application..."
if [ "$1" == "docker" ]; then
setup_docker
elif [ "$1" == "kubernetes" ]; then
deploy_kubernetes
fi
echo "Deployment completed."
}
# Function to handle installation or restart
install_application() {
echo "Do you want to:"
echo "1) Install a fresh application"
echo "2) Restart the deployment"
read -p "Enter your choice (1-2): " deployment_choice
if [ "$deployment_choice" == "1" ]; then
ensure_data_directory
check_disk_space
handle_env_file
generate_ssl_certificate
echo "Choose the platform to install or manage:"
echo "1) Docker"
echo "2) Kubernetes (K8s)"
echo "3) K3s (Lightweight Kubernetes)"
read -p "Enter your choice (1-3): " platform_choice
case $platform_choice in
1)
PLATFORM="docker"
if ! command_exists docker; then
echo "Installing Docker..."
curl -s https://get.docker.com | sh -s --
fi
;;
2)
PLATFORM="kubernetes"
if ! command_exists kubectl; then
echo "Installing Kubernetes..."
apt-get update && apt-get install -y kubeadm kubectl kubelet
fi
copy_kubeconfig_file
;;
3)
PLATFORM="kubernetes"
if ! command_exists k3s; then
echo "Installing K3s..."
curl -sfL https://get.k3s.io | sh -
fi
copy_kubeconfig_file
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
deploy_application "$PLATFORM"
elif [ "$deployment_choice" == "2" ]; then
echo "Restarting deployment..."
deploy_application "$PLATFORM"
else
echo "Invalid choice. Exiting."
exit 1
fi
}
install_application

235
kube-deploy.yaml Normal file
View File

@ -0,0 +1,235 @@
apiVersion: v1
kind: Namespace
metadata:
name: nexo-cloud
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-data
namespace: nexo-cloud
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexo-cloud-storage
namespace: nexo-cloud
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexo-cloud
namespace: nexo-cloud
spec:
replicas: 2
selector:
matchLabels:
app: nexo-cloud
template:
metadata:
labels:
app: nexo-cloud
spec:
containers:
- name: nexo-cloud
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
ports:
- containerPort: 8000
env:
- name: APP_ENV
value: production
- name: APP_KEY
valueFrom:
secretKeyRef:
name: nexo-cloud-secret
key: app-key
- name: DB_HOST
value: postgres
- name: DB_PORT
value: "5432"
- name: DB_DATABASE
value: laravel
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: nexo-cloud-db-secret
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: nexo-cloud-db-secret
key: password
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: "6379"
volumeMounts:
- name: storage
mountPath: /var/www/html/storage
volumes:
- name: storage
persistentVolumeClaim:
claimName: nexo-cloud-storage
---
apiVersion: v1
kind: Service
metadata:
name: nexo-cloud-service
namespace: nexo-cloud
spec:
selector:
app: laravel
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: nexo-cloud
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: laravel
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: nexo-cloud-db-secret
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: nexo-cloud-db-secret
key: password
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-data
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: nexo-cloud
spec:
selector:
app: postgres
ports:
- protocol: TCP
port: 5432
targetPort: 5432
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: nexo-cloud
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7.2
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: nexo-cloud
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 6379
targetPort: 6379
type: ClusterIP
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: nexo-cloud-scheduler
namespace: nexo-cloud
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: scheduler
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
command: ["php", "/var/www/html/artisan", "schedule:run"]
restartPolicy: OnFailure
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexo-cloud-worker
namespace: nexo-cloud
spec:
replicas: 2
selector:
matchLabels:
app: nexo-cloud-worker
template:
metadata:
labels:
app: nexo-cloud-worker
spec:
containers:
- name: worker
image: git.masscivicdynamic.com/masscivicdynamic/nexo-cloud:latest
command: ["php", "/var/www/html/artisan", "queue:work", "--tries=3"]