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.
186 lines
4.3 KiB
186 lines
4.3 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
|
|
|
|
mkdir /opt/stacks/${PROJECT}
|
|
|
|
cat << EOF > /opt/stacks/${PROJECT}/compose.yaml
|
|
name: ${PROJECT}
|
|
services:
|
|
nginx:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: nginx
|
|
php:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: php
|
|
build:
|
|
args:
|
|
- PHP_VERSION=8.1
|
|
workspace:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: workspace
|
|
build:
|
|
args:
|
|
- PROJECT=\${PROJECT}
|
|
- PHP_VERSION=8.1
|
|
expose:
|
|
- 22
|
|
working_dir: /var/www/${PROJECT}
|
|
volumes:
|
|
- /opt/projects/${PROJECT}/profiler:/tmp/profiler
|
|
- /opt/projects/${PROJECT}/www:/var/www
|
|
mariadb:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: mariadb
|
|
redis:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: redis
|
|
seafile:
|
|
extends:
|
|
file: /opt/structure/docker-compose.base.yml
|
|
service: seafile
|
|
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
|
|
structure:
|
|
volumes:
|
|
seafile:
|
|
EOF
|
|
|
|
SEAFILE_USER="${MACHINE}-workspace-${PROJECT}@dimti.ru"
|
|
SEAFILE_PASS=$(pwgen -s 20 1)
|
|
SEAFILE_DUMPS_LIB=$2
|
|
|
|
echo "Seafile credentionals for create new account:"
|
|
echo "SEAFILE_USER=${SEAFILE_USER}"
|
|
echo "SEAFILE_PASS=${SEAFILE_PASS}"
|
|
|
|
cat << EOF > /opt/stacks/${PROJECT}/.env
|
|
PROJECT=${PROJECT}
|
|
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
|
|
SEAFILE_USER=${SEAFILE_USER}
|
|
SEAFILE_PASS=${SEAFILE_PASS}
|
|
SEAFILE_DUMPS_LIB=${SEAFILE_DUMPS_LIB}
|
|
EOF
|
|
|
|
chown -R $_PUID:$P_GID /opt/stacks/${PROJECT}
|
|
|
|
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 -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]
|
|
EOF
|
|
|
|
cat << EOF > ${CONFIG_DIR}/nginx/conf.d/vhosts.conf
|
|
upstream php {
|
|
server php:9000;
|
|
}
|
|
map \$http_host \$root {
|
|
${PROJECT}.local.wpstudio.ru /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
|
|
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}
|
|
chown -R $P_UID:$P_GID ${WWW_DIR}
|