You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
5.1 KiB

#!/bin/bash
set -e
PROJECT=$1
if [[ -z "${PROJECT}" ]]; then
echo 'Usage: ./create-stack-project PROJECT [SEAFILE_DUMPS_LIB_UUID]';
exit 1;
fi
test -f .env || {
echo 'No env';
exit 1;
}
echo
source .env
P_UID=1000
P_GID=1000
PROJECT_DIR=/opt/projects/${PROJECT}
CONFIG_DIR=${PROJECT_DIR}/config
HOSTFILES_DIR=${PROJECT_DIR}/hostfiles
LOGS_DIR=${PROJECT_DIR}/logs
MARIADB_DIR=${PROJECT_DIR}/mariadb
PROFILER_DIR=${PROJECT_DIR}/profiler
SSH_DIR=${PROJECT_DIR}/ssh
WWW_DIR=${PROJECT_DIR}/www
mkdir /opt/stacks/${PROJECT}
cat << EOF > /opt/stacks/${PROJECT}/compose.yaml
services:
nginx:
extends:
file: ./../structure/compose.base.yaml
service: nginx
php:
extends:
file: ./../structure/compose.base.yaml
service: php
workspace:
extends:
file: ./../structure/compose.base.yaml
service: workspace
build:
args:
- INSTALL_NODE=false
working_dir: /var/www/\${PROJECT}
volumes:
- ConfigJetBrains:/home/laradock/.config/JetBrains
- BashHistoryLog:/home/laradock/.bash_history
- VSCodeServerInsiders:/home/laradock/.vscode-server-insiders
secrets:
- composer_auth
networks:
apihole_net:
aliases:
- workspace.${PROJECT}.saturn
mariadb:
extends:
file: ./../structure/compose.base.yaml
service: mariadb
redis:
extends:
file: ./../structure/compose.base.yaml
service: redis
secrets:
user_authorized_keys:
file: /opt/projects/\${PROJECT}/ssh/authorized_keys
user_ssh_key:
file: /opt/projects/\${PROJECT}/ssh/id_ed25519
user_ssh_key_pub:
file: /opt/projects/\${PROJECT}/ssh/id_ed25519.pub
composer_auth:
file: /opt/projects/\${PROJECT}/config/composer/auth.json
networks:
dockge_default:
external: true
pma_default:
external: true
apihole_net:
external: true
volumes:
ConfigJetBrains:
BashHistoryLog:
VSCodeServerInsiders:
EOF
# Possible PHP_VERSION is 7.4, 8.1, 8.2 & 8.3
cat << EOF > /opt/stacks/${PROJECT}/.env
PROJECT=${PROJECT}
PHP_VERSION=8.3
EOF
SEAFILE_USER="${MACHINE}-${PROJECT}-workspace@dimti.ru"
SEAFILE_PASS=$(pwgen -s 20 1)
SEAFILE_LIB=$2
echo "Seafile credentionals for create new account:"
echo "SEAFILE_USER: ${SEAFILE_USER}"
echo "SEAFILE_PASS: ${SEAFILE_PASS}"
PROJECT_UPPERCASE=$(echo ${PROJECT} | tr '[:lower:]' '[:upper:]')
cat << EOF >> /opt/stacks/seafile/.env
${PROJECT_UPPERCASE}_USER=${SEAFILE_USER}
${PROJECT_UPPERCASE}_PASS=${SEAFILE_PASS}
${PROJECT_UPPERCASE}_LIB=${SEAFILE_LIB}
EOF
sed -e "s/volumes:/volumes:\n\s\sseafile-$PROJECT:/g" /opt/stacks/seafile/compose.yaml
cat << EOF >> /opt/stacks/seafile/compose.yaml
${PROJECT}:
extends:
file: ./compose.base.yaml
service: seafile
volumes:
- /opt/projects/${PROJECT}/hostfiles:/library
- seafile-${PROJECT}:/seafile
environment:
SEAF_USERNAME: "\${${PROJECT_UPPERCASE}_USER}"
SEAF_PASSWORD: "\${${PROJECT_UPPERCASE}_PASS}"
SEAF_LIBRARY: "\${${PROJECT_UPPERCASE}_LIB}"
EOF
chown -R $_PUID:$P_GID /opt/stacks/${PROJECT}
mkdir -p ${CONFIG_DIR}/composer
mkdir -p ${CONFIG_DIR}/mariadb
mkdir -p ${CONFIG_DIR}/nginx/conf.d
mkdir -p ${CONFIG_DIR}/nginx/includes.d
mkdir -p ${CONFIG_DIR}/nginx/ssl.d
mkdir -p ${CONFIG_DIR}/redis
cat << EOF > ${CONFIG_DIR}/composer/auth.json
{
"github-oauth": {
"github.com": ""
}
}
EOF
cat << EOF > ${CONFIG_DIR}/mariadb/90-mysqld.cnf
[mysqld]
general_log=OFF
general_log_file=/var/log/mariadb/mariadb.log
EOF
cat << EOF > ${CONFIG_DIR}/nginx/conf.d/vhosts.conf
upstream php {
server php:9000;
}
map \$http_host \$root {
${PROJECT}.${DOMAIN_PLACEHOLDER} /var/www/${PROJECT};
}
server {
listen 80 default;
root \$root;
include includes.d/octobercms.conf;
include includes.d/staticfiles.conf;
client_max_body_size 300M;
large_client_header_buffers 4 32k;
location ~ ^/index.php {
fastcgi_pass php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param SERVER_NAME \$host;
}
}
EOF
cp /opt/stacks/structure/config/nginx/includes.d/octobercms.conf ${CONFIG_DIR}/nginx/includes.d/
cp /opt/stacks/structure/config/nginx/includes.d/staticfiles.conf ${CONFIG_DIR}/nginx/includes.d/
cat << EOF > ${CONFIG_DIR}/redis/redis-local.conf
port 6379
tcp-backlog 128
protected-mode no
stop-writes-on-bgsave-error no
databases 4
always-show-logo no
syslog-enabled yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
EOF
chown $P_UID:$P_GID -R ${CONFIG_DIR}
mkdir ${HOSTFILES_DIR}
chown $P_UID:$P_GID ${HOSTFILES_DIR}
mkdir -p ${LOGS_DIR}/mariadb
mkdir -p ${LOGS_DIR}/nginx
mkdir -p ${LOGS_DIR}/php-fpm
mkdir ${MARIADB_DIR}
mkdir ${PROFILER_DIR}
mkdir ${SSH_DIR}
touch ${SSH_DIR}/authorized_keys
ssh-keygen -N "" -t ed25519 -f ${SSH_DIR}/id_ed25519 -C workspace-${PROJECT}@${MACHINE} 2>&1 > /dev/null
echo "SSH Key:"
cat ${SSH_DIR}/id_ed25519.pub
echo
ssh-keyscan -H github.com > ${SSH_DIR}/known_hosts 2>/dev/null
chown $P_UID:$P_GID -R ${SSH_DIR}
mkdir -p ${WWW_DIR}/${PROJECT}
cat << EOF > ${WWW_DIR}/${PROJECT}/index.php
<?php
phpinfo();
EOF
chown -R $P_UID:$P_GID ${WWW_DIR}