62 lines
2.2 KiB
Bash
Executable File
62 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
_docker_dir="$_docker_base_dir/$_remote_host"
|
|
|
|
_ssh_cmd="ssh root@$_remote_host.$_domain"
|
|
_scp_to_base="root@$_remote_host.$_domain:$_docker_dir"
|
|
|
|
echo "HOST=$_remote_host" > .env
|
|
echo "DOMAIN=$_domain" >> .env
|
|
echo "MYSQL_ROOT_PASSWD=$_mysql_root_passwd" >> .env
|
|
echo "MYSQL_USER=wordpress" >> .env
|
|
echo "MYSQL_PASSWORD=wordpress" >> .env
|
|
echo "MYSQL_DATABASE=wordpress" >> .env
|
|
|
|
$_ssh_cmd "mkdir -p $_docker_dir/wordpress"
|
|
|
|
scp -r production/config "$_scp_to_base"/config
|
|
scp production/Dockerfile "$_scp_to_base"/Dockerfile
|
|
scp production/entrypoint.sh "$_scp_to_base"/entrypoint.sh
|
|
scp ./.env "$_scp_to_base"/.env
|
|
scp production/docker-compose.yml "$_scp_to_base"/docker-compose.yml
|
|
|
|
scp wordpress.tar.gz "$_scp_to_base"/wordpress.tar.gz
|
|
$_ssh_cmd "tar -xf $_docker_dir/wordpress.tar.gz -C $_docker_dir/wordpress && rm $_docker_dir/wordpress.tar.gz"
|
|
|
|
$_ssh_cmd "sed -i 's/__HOST__/$_remote_host/g' $_docker_dir/config/nginx.conf"
|
|
# TODO make this more robust than just changing any old localhost
|
|
$_ssh_cmd "sed -i 's/localhost/$_remote_host-mysql/g' $_docker_dir/wordpress/wp-config.php"
|
|
$_ssh_cmd "chown -R $_docker_user: $_docker_dir"
|
|
|
|
$_ssh_cmd "cd $_docker_dir && docker-compose up -d --build"
|
|
|
|
# TODO - need to wait for mysql to initialise
|
|
# temporary
|
|
echo "waiting for mysql to initialise ..."
|
|
sleep 10
|
|
echo "still waiting for mysql to initialise ..."
|
|
sleep 10
|
|
echo "waiting a little bit longer for mysql to initialise ..."
|
|
sleep 5
|
|
|
|
# TODO does docker always assign ips in range 172.% ????
|
|
_ssh_shell_cmd='echo "GRANT ALL PRIVILEGES ON wordpress."*" TO \"wordpress\"@\"172.%\" IDENTIFIED BY \"wordpress\";" | mysql -uroot -pdb'
|
|
# _ssh_shell_cmd='echo "'"$_mysql_cmd"'" | mysql -uroot -pdb'
|
|
echo "$_ssh_shell_cmd"
|
|
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-mysql /bin/sh -c '$_ssh_shell_cmd'"
|
|
|
|
echo "$_ssh_cmd -- $_cmd_docker_exec"
|
|
$_ssh_cmd $_cmd_docker_exec
|
|
|
|
|
|
_cmd_wp_import="wp db import --dbuser=wordpress --dbpass=$_wp_db_passwd data.sql"
|
|
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin/sh -c '$_cmd_wp_import'"
|
|
$_ssh_cmd "echo '$_wp_db_passwd' && $_cmd_docker_exec"
|
|
|
|
# set correct URLS
|
|
|
|
# ensure HTTP_X_FORWARDED_PROTO header is set in wp-config.php
|
|
|
|
# rm .env
|
|
|