Compare commits
19 Commits
75298677b0
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
441dc6b371 | ||
|
|
cde2a715fb | ||
|
|
c55c46df0d | ||
|
|
4971511309 | ||
|
|
95391a995c | ||
|
|
6e0719ec50 | ||
|
|
c1ae487788 | ||
|
|
d582d4c7f0 | ||
|
|
f94e7baba5 | ||
|
|
3c22799e47 | ||
|
|
ba2b4bdaa1 | ||
|
|
bbd07933ff | ||
|
|
f86fa8b9f3 | ||
|
|
d0a70be1b2 | ||
|
|
f3afb76350 | ||
|
|
f85c57c9b9 | ||
|
|
4e845592e2 | ||
|
|
12d556d660 | ||
|
|
deb52616bf |
@@ -4,6 +4,8 @@ DB_NAME=wordpress
|
||||
DB_ROOT_PASSWORD=root
|
||||
DB_USER=user
|
||||
DB_USER_PASSWORD=password
|
||||
LARAVEL_VERSION=11.0
|
||||
LIVEWIRE_VERSION=3.5.10
|
||||
PHP_POST_MAX_SIZE=10m
|
||||
PHP_UPLOAD_MAX_FILESIZE=10M
|
||||
PREFIX=wpdocker
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
.env
|
||||
backup-volumes/
|
||||
exclude-list
|
||||
root-volume/
|
||||
tmp/
|
||||
traefik-volumes/
|
||||
webroot-remote/
|
||||
|
||||
3
TODO.md
3
TODO.md
@@ -1,2 +1,5 @@
|
||||
- [ ] modifier pull-remote-db.sh pour qu'il fasse tourner wp-cli directement sur le conteneur et récupère ensuite le contenu localement
|
||||
- [ ] ajouter dump sql au backup
|
||||
- [ ] ajouter un moyen d'accéder à la db via un port
|
||||
- [ ] ajouter une option pour créer sans traefik et sans adminer (via override compose)
|
||||
- [ ] remplacer -a par --recursive,etc pour éviter qu'rsync n'affiche un transfert si atime, ctime, mtime a changé pour un fichier
|
||||
|
||||
@@ -14,7 +14,7 @@ now="$(date +%Y-%m_%d-%H-%M-%S)"
|
||||
backup_path="${PWD}/backup-volumes/${now}"
|
||||
mkdir -p "${backup_path}"
|
||||
|
||||
volumes="db traefik-dynamic traefik-certs traefik-logs traefik-static webroot"
|
||||
volumes="db root traefik-dynamic traefik-certs traefik-logs traefik-static webroot"
|
||||
for volume in ${volumes}; do
|
||||
mkdir -p "${backup_path}/${volume}"
|
||||
docker run \
|
||||
|
||||
30
create.sh
30
create.sh
@@ -9,18 +9,21 @@ fi
|
||||
set -a
|
||||
. "${PWD}/.env"
|
||||
. "${PWD}/env_files/certs.env"
|
||||
. "${PWD}/env_files/project.env"
|
||||
set +a
|
||||
|
||||
mkdir -p "/tmp/${PREFIX}"
|
||||
|
||||
echo "Setting up docker volumes"
|
||||
docker volume create "${PREFIX}-db"
|
||||
docker volume create "${PREFIX}-root"
|
||||
docker volume create "${PREFIX}-traefik-certs"
|
||||
docker volume create "${PREFIX}-traefik-dynamic"
|
||||
docker volume create "${PREFIX}-traefik-logs"
|
||||
docker volume create "${PREFIX}-traefik-static"
|
||||
docker volume create "${PREFIX}-webroot"
|
||||
docker volume create wp-cli-cache
|
||||
docker volume create composer-cache
|
||||
|
||||
echo "Copying SSL certificates to traefik volume"
|
||||
if [ ! -f "${SSL_CRT_LOCATION}/${SSL_CRT_NAME}" ] || [ ! -f "${SSL_KEY_LOCATION}/${SSL_KEY_NAME}" ]; then
|
||||
@@ -110,6 +113,31 @@ while ! docker exec "${PREFIX}-app" /bin/sh -c "mysqladmin ping -h ${PREFIX}-db
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ "${PROJECT_TYPE}" = "laravel" ]; then
|
||||
echo "Installing laravel"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project --prefer-dist laravel/laravel /var/www/html '${LAREVEL_VERSION}'"
|
||||
fi
|
||||
|
||||
if [ "${PROJECT_TYPE}" = "livewire" ]; then
|
||||
echo "Installing livewire"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project --prefer-dist laravel/laravel /var/www/html '${LARAVEL_VERSION}'"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer require livewire/livewire ${LIVEWIRE_VERSION}"
|
||||
fi
|
||||
|
||||
if [ "${PROJECT_TYPE}" = "wintercms" ]; then
|
||||
echo "Installing wintercms"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project wintercms/winter /var/www/html"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "echo ASSET_URL=https://${APP_URL} >> /var/www/html/.env"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "echo DB_DATABASE=${DB_NAME} >> /var/www/html/.env"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "echo DB_USERNAME=${DB_USER} >> /var/www/html/.env"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "echo DB_PASSWORD=${DB_USER_PASSWORD} >> /var/www/html/.env"
|
||||
docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "echo DB_HOST=${PREFIX}-db >> /var/www/html/.env"
|
||||
docker exec --user root "${PREFIX}-app" /bin/sh -c "sed -i 's|/var/www/html/public|/var/www/html|g' /etc/apache2/sites-available/000-default.conf"
|
||||
docker restart "${PREFIX}-app"
|
||||
docker exec --user www-data --workdir "/var/www/html" -it "${PREFIX}-app" /bin/sh -c "php artisan winter:install"
|
||||
fi
|
||||
|
||||
if [ "${PROJECT_TYPE}" = "wordpress" ]; then
|
||||
echo "Downloading WordPress core"
|
||||
docker exec --user www-data "${PREFIX}-app" /bin/sh -c "
|
||||
wp core download \
|
||||
@@ -148,6 +176,8 @@ docker exec --user www-data "${PREFIX}-app" /bin/sh -c "
|
||||
wp theme install ${WP_THEME} \
|
||||
--activate \
|
||||
--path=/var/www/html"
|
||||
fi
|
||||
|
||||
docker compose up -d adminer
|
||||
docker compose up -d app
|
||||
docker compose up -d traefik
|
||||
|
||||
@@ -29,7 +29,7 @@ if [ "${do_backup}" = "yes" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${remote_is_docker}" != "yes" ]; then
|
||||
if [ "${use_maintenance_mode}" = "yes" ]; then
|
||||
if ssh ${remote_ssh_string} "wp option patch update wpmm_settings general status 1 --path=${remote_wp_path}"; then
|
||||
echo maintenance mode activated
|
||||
else
|
||||
@@ -38,14 +38,16 @@ if [ "${remote_is_docker}" != "yes" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if rsync --archive --compress --delete --delete-excluded --exclude-from="${deployment_exclude_file}" --human-readable --progress "${local_directory_path}/" "${remote_ssh_string}":"${remote_directory_path}"; then
|
||||
# --update removed after kartolok-child shenaningans
|
||||
# --checksum added instead
|
||||
if rsync --checksum --compress --delete --delete-excluded --exclude-from="${deployment_exclude_file}" --executability --human-readable --progress --recursive "${local_directory_path}/" "${remote_ssh_string}":"${remote_directory_path}"; then
|
||||
echo syncing OK
|
||||
else
|
||||
echo syncing NOK
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${remote_is_docker}" != "yes" ]; then
|
||||
if [ "${use_maintenance_mode}" = "yes" ]; then
|
||||
if ssh ${remote_ssh_string} "wp option patch update wpmm_settings general status 0 --path=${remote_wp_path}"; then
|
||||
echo maintenance mode deactivated
|
||||
else
|
||||
@@ -53,3 +55,9 @@ if [ "${remote_is_docker}" != "yes" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${restart_remote_varnish}" = "yes" ]; then
|
||||
set -x
|
||||
ssh "${sudo_remote_ssh_string}" sudo service varnish restart
|
||||
set +x
|
||||
fi
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
deployment_exclude_file=
|
||||
local_directory_path=
|
||||
now="$(date +%Y-%m-%d-%H-%M-%S)"
|
||||
remote_deployment_path=
|
||||
remote_deployment_directory_path=
|
||||
remote_directory_path=
|
||||
remote_ssh_string=
|
||||
remote_wp_path=
|
||||
remote_is_docker=
|
||||
restart_remote_varnish=no
|
||||
sudo_remote_ssh_string=
|
||||
use_maintenance_mode=no
|
||||
do_backup=yes
|
||||
|
||||
@@ -6,6 +6,8 @@ networks:
|
||||
services:
|
||||
adminer:
|
||||
container_name: ${PREFIX}-adminer
|
||||
dns:
|
||||
- 1.1.1.1
|
||||
hostname: ${PREFIX}-adminer
|
||||
image: adminer:4.8.1-standalone
|
||||
labels:
|
||||
@@ -16,11 +18,14 @@ services:
|
||||
- traefik.http.services.${PREFIX}-adminer.loadbalancer.server.port=8080
|
||||
app:
|
||||
container_name: ${PREFIX}-app
|
||||
dns:
|
||||
- 1.1.1.1
|
||||
environment:
|
||||
- PHP_POST_MAX_SIZE=${PHP_POST_MAX_SIZE}
|
||||
- PHP_UPLOAD_MAX_FILESIZE=${PHP_UPLOAD_MAX_FILESIZE}
|
||||
- XDEBUG_CLIENT_HOST=${XDEBUG_CLIENT_HOST}
|
||||
- XDEBUG_MODE=${XDEBUG_MODE}
|
||||
hostname: ${PREFIX}-app
|
||||
image: ${APP_IMAGE_TAG}
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
@@ -32,8 +37,10 @@ services:
|
||||
- traefik.http.routers.${PREFIX}-webssl.tls=true
|
||||
- traefik.http.services.${PREFIX}-webssl.loadbalancer.server.port=80
|
||||
volumes:
|
||||
- root:/root
|
||||
- webroot:/var/www/html
|
||||
- wp-cli-cache:/var/www/.wp-cli
|
||||
- cache:/var/www/.cache
|
||||
db:
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
container_name: ${PREFIX}-db
|
||||
@@ -51,6 +58,8 @@ services:
|
||||
traefik:
|
||||
container_name: ${PREFIX}-traefik
|
||||
command: ["--configFile=/etc/traefik/static/traefik.yml"]
|
||||
dns:
|
||||
- 1.1.1.1
|
||||
image: traefik:2.5.3
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
@@ -72,8 +81,12 @@ services:
|
||||
version: "3.4"
|
||||
|
||||
volumes:
|
||||
cache:
|
||||
name: composer-cache
|
||||
db:
|
||||
name: ${PREFIX}-db
|
||||
root:
|
||||
name: ${PREFIX}-root
|
||||
traefik-certs:
|
||||
name: ${PREFIX}-traefik-certs
|
||||
traefik-dynamic:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
SSL_CRT_LOCATION=<path>
|
||||
SSL_CRT_NAME<certificate filename>
|
||||
SSL_CRT_NAME=<certificate filename>
|
||||
SSL_KEY_LOCATION=<path>
|
||||
SSL_KEY_NAME=<key filename>
|
||||
|
||||
4
env_files/project-example.env
Normal file
4
env_files/project-example.env
Normal file
@@ -0,0 +1,4 @@
|
||||
PROJECT_TYPE=wordpress
|
||||
PROJECT_TYPE=laravel
|
||||
PROJECT_TYPE=livewire
|
||||
PROJECT_TYPE=wintercms
|
||||
@@ -1,2 +1,2 @@
|
||||
REMOTE_SSH_STRING=<sshconfig hostname>
|
||||
REMOTE_WP_PATH=</var/www/example.com.be>
|
||||
REMOTE_WP_PATH=</var/www/example.com>
|
||||
|
||||
4
env_files/ssh-tunnel-example.env
Normal file
4
env_files/ssh-tunnel-example.env
Normal file
@@ -0,0 +1,4 @@
|
||||
LOCAL_IP_ON_REMOTE=localhost
|
||||
LOCAL_PORT=5432
|
||||
LOCAL_PORT_ON_REMOTE=5432
|
||||
REMOTE_HOST=federal-non-interactive
|
||||
@@ -11,7 +11,7 @@ set -a
|
||||
. "${PWD}/env_files/manage.env"
|
||||
set +a
|
||||
|
||||
volumes="certs dynamic logs static webroot"
|
||||
volumes="certs dynamic logs root static webroot"
|
||||
for volume in ${volumes}; do
|
||||
mount_path="${PWD}/traefik-volumes/${volume}"
|
||||
volume_path="${DOCKER_VOLUMES_PATH}/${PREFIX}-traefik-${volume}/_data"
|
||||
@@ -19,6 +19,10 @@ for volume in ${volumes}; do
|
||||
mount_path="${PWD}/${volume}-volume"
|
||||
volume_path="${DOCKER_VOLUMES_PATH}/${PREFIX}-${volume}/_data"
|
||||
fi
|
||||
if [ "${volume}" = "root" ]; then
|
||||
mount_path="${PWD}/${volume}-volume"
|
||||
volume_path="${DOCKER_VOLUMES_PATH}/${PREFIX}-${volume}/_data"
|
||||
fi
|
||||
sudo -u "${MOUNT_USER}" mkdir -p "${mount_path}"
|
||||
if mountpoint "${mount_path}" -q; then
|
||||
echo "exiting because something is mounted at ${mount_path}"
|
||||
|
||||
@@ -12,6 +12,7 @@ if [ "$REPLY" != "${REPLY#[YyOo]}" ]; then
|
||||
docker compose rm
|
||||
docker network rm "${PREFIX}"
|
||||
docker volume rm "${PREFIX}-db"
|
||||
docker volume rm "${PREFIX}-root"
|
||||
docker volume rm "${PREFIX}-traefik-certs"
|
||||
docker volume rm "${PREFIX}-traefik-dynamic"
|
||||
docker volume rm "${PREFIX}-traefik-logs"
|
||||
|
||||
@@ -36,5 +36,7 @@ echo "dropping ${DB_NAME}"
|
||||
docker exec "${PREFIX}-db" /bin/sh -c "mysqladmin --force -uroot -p${DB_ROOT_PASSWORD} drop ${DB_NAME}"
|
||||
echo "creating ${DB_NAME}"
|
||||
docker exec "${PREFIX}-db" /bin/sh -c "mysqladmin -uroot -p${DB_ROOT_PASSWORD} create ${DB_NAME}"
|
||||
echo "run this command in another terminal/window to monitor progress:"
|
||||
echo "docker exec -it watch -n1 ${PREFIX}-db du /var/lib/mysql/${DB_NAME}-sh"
|
||||
echo "importing ${dump_filename_path} (${PREFIX}-db/tmp/dump.sql) into ${DB_NAME}"
|
||||
docker exec "${PREFIX}-db" /bin/sh -c "mysql -uroot -p${DB_ROOT_PASSWORD} ${DB_NAME} < /tmp/dump.sql"
|
||||
|
||||
24
start-ssh-tunnel.sh
Normal file
24
start-ssh-tunnel.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
|
||||
if [ "$#" -eq 0 ] || [ "$#" -gt 1 ]; then
|
||||
echo takes only one argument
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e "${1}" ]; then
|
||||
echo cannot find "${1}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck source=./env_files/ssh-tunnel-example.env
|
||||
. "${1}"
|
||||
# shellcheck source=./.env-example
|
||||
. ./.env
|
||||
|
||||
ssh \
|
||||
-v \
|
||||
-N \
|
||||
-L \
|
||||
"${TRAEFIK_LISTENING_IP}:${LOCAL_PORT}:${LOCAL_IP_ON_REMOTE}:${LOCAL_PORT_ON_REMOTE}" \
|
||||
"${REMOTE_HOST}"
|
||||
@@ -6,12 +6,15 @@ if [ "$(id -u)" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
volumes="certs dynamic logs static webroot"
|
||||
volumes="certs dynamic logs root static webroot"
|
||||
for volume in ${volumes}; do
|
||||
mount_path="${PWD}/traefik-volumes/${volume}"
|
||||
if [ "${volume}" = "webroot" ]; then
|
||||
mount_path="${PWD}/${volume}-volume"
|
||||
fi
|
||||
if [ "${volume}" = "root" ]; then
|
||||
mount_path="${PWD}/${volume}-volume"
|
||||
fi
|
||||
if mountpoint "${mount_path}" -q; then
|
||||
echo "umounting ${mount_path}"
|
||||
umount "${mount_path}"
|
||||
|
||||
Reference in New Issue
Block a user