Compare commits

...

4 Commits

Author SHA1 Message Date
Ray Elliott c389c52385 allow to set docker user 2020-03-12 20:01:15 +00:00
Ray Elliott d3e61d9983 deploy container successfully 2020-03-12 19:31:36 +00:00
Ray Elliott ce426e3f30 provision webserver working 2020-03-12 19:20:03 +00:00
Ray Elliott 213fbb4a5a tidy up config 2020-03-12 17:41:16 +00:00
7 changed files with 66 additions and 23 deletions

View File

@ -4,6 +4,7 @@ TODO
## TODO
* implement option to not have remote url include hostname (i.e., bare domain)
* convert scripts to use ssh pipes/bash here documents.
see [ssh pipes](https://stackoverflow.com/a/4412324), [Bash Here Document](https://stackoverflow.com/a/4412338)
* Script to export database from production database

View File

@ -8,10 +8,10 @@ export _local_domain="home"
export _user_www='www-data'
export _passwd_www='www-data'
export _wp_title="WP Test"
export _wp_title="WP Title"
export _wp_admin_user="admin"
export _wp_password="admin"
export _wp_email="$_local_hostname@isnet.uk"
export _wp_password="a_better_password_than_this_bro"
export _wp_email="wp@example.org"
export _wp_db_passwd="wordpress"
export _wp_theme_active="twentytwenty"
@ -23,9 +23,10 @@ export _wp_plugins_active="elementor wp-mail-smtp gdpr-cookie-compliance regener
# remote configuration
export _docker_user="ray"
export _remote_host="www"
export _domain="isnet.uk"
_lets_encrypt_email="letsencrypt@example.org"
export _remote_host="seven"
export _domain="wptest.isnet.uk"
export _docker_user="ray"
export _docker_base_dir="/var/docker"
export _mysql_root_passwd="db"
export _mysql_root_passwd="another_password_better_than_this_bruh"

View File

@ -1,5 +1,7 @@
#!/bin/sh
set -e
if [ -z "$1" ] ; then
_target_filename='.'
else
@ -11,8 +13,9 @@ _cmd_wp_export="wp db export --dbuser=wordpress --dbpass=$_wp_db_passwd --add-dr
_ssh_cmd="sshpass -p$_passwd_www ssh $_user_www@$_host"
_scp_cmd="sshpass -p$_passwd_www scp $_user_www@$_host:/tmp/wordpress.tar.gz"
echo "Exporting data ..."
echo "Exporting database ..."
$_ssh_cmd "cd /var/www/html/wordpress &&" $_cmd_wp_export
echo "Exporting files ..."
$_ssh_cmd 'cd /var/www/html/wordpress && tar czf /tmp/wordpress.tar.gz .'
$_ssh_cmd "rm /var/www/html/wordpress/data.sql"
$_scp_cmd "$_target_filename"

5
production/export-data.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -e

View File

@ -1,5 +1,7 @@
#!/bin/sh
set -e
_docker_dir="$_docker_base_dir/$_remote_host"
_ssh_cmd="ssh root@$_remote_host.$_domain"
@ -49,12 +51,12 @@ echo "Configuring WordPress ..."
# TODO does docker always assign ips in range 172.% ????
# TODO - sort this mess out - use functions or something
_ssh_shell_cmd='echo "GRANT ALL PRIVILEGES ON wordpress."*" TO \"wordpress\"@\"172.%\" IDENTIFIED BY \"wordpress\";" | mysql -uroot -pdb'
_ssh_shell_cmd='echo "GRANT ALL PRIVILEGES ON wordpress."*" TO \"wordpress\"@\"172.%\" IDENTIFIED BY \"'"$_wp_db_passwd"'\";" | mysql -uroot -p'"$_mysql_root_passwd"
_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="wp db import --dbuser=wordpress --dbpass=$_wp_db_passwd data.sql"
_cmd_wp="wp db import --dbuser=wordpress --dbpass=$_wp_db_passwd data.sql && rm data.sql"
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin/sh -c '$_cmd_wp'"
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
@ -79,9 +81,15 @@ _cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
_cmd_wp="wp search-replace '$_local_hostname.$_local_domain' '$_remote_host.$_domain' --skip-columns=guid"
_remote_url="$_remote_host.$_domain"
_cmd_wp="wp search-replace '$_local_hostname.$_local_domain' '$_remote_url' --skip-columns=guid"
_cmd_docker_exec="cd $_docker_dir && docker exec -t $_remote_host-wordpress /bin/sh -c '$_cmd_wp'"
echo "$_ssh_cmd $_cmd_docker_exec"
$_ssh_cmd "$_cmd_docker_exec"
echo ""
echo "-------------------------------------------------------------------------"
echo "Deploy complete"
echo " URL: https://$_remote_url/wp-login.php"
rm .env

View File

@ -1,23 +1,30 @@
#!/bin/sh
set -e
# TODO basic error checking
# TODO verbosity
# TODO hardening
_lets_encrypt_email="wptest@isnet.uk"
_server_base_url="wptest.isnet.uk"
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
_server_base_url="$_domain"
echo "Provisioning: $_server_base_url$ - (whoami)@$(hostname)"
_docker_container_config_dir="/var/docker"
_docker_compose_version="1.25.4"
# add user
useradd -m -s /bin/bash ray
useradd -m -s /bin/bash "$_docker_user"
groupadd docker
usermod -aG docker ray
mkdir /home/ray/.ssh
cp /root/.ssh/authorized_keys /home/ray/.ssh/
chown ray: /home/ray/.ssh/authorized_keys
usermod -aG docker "$_docker_user"
mkdir /home/"$_docker_user"/.ssh
cp /root/.ssh/authorized_keys /home/"$_docker_user"/.ssh/
chown "$_docker_user": /home/"$_docker_user"/.ssh/authorized_keys
apt-get update
apt-get upgrade --yes
apt-get install \
apt-transport-https \
ca-certificates \
@ -30,9 +37,9 @@ apt-get install \
ufw allow ssh
ufw allow http
ufw allow https
ufw enable
ufw --force enable
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
@ -43,8 +50,8 @@ apt-get install docker-ce docker-ce-cli containerd.io
curl -L "https://github.com/docker/compose/releases/download/$_docker_compose_version/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "Basic HTTP authorisation password for user: ray"
_HT_PASSWD=$(htpasswd -nB ray | sed -e 's/\$/\$\$/g')
echo "Basic HTTP authorisation password for user: $_docker_user"
_HT_PASSWD=$(htpasswd -nB "$_docker_user" | sed -e 's/\$/\$\$/g')
docker network create web
@ -154,5 +161,14 @@ networks:
" >> docker-compose.yml
docker-compose up -d
echo "VISIT PORTAINER URL NOW TO SET INITIAL LOGIN:" # or see if can set from script
echo "-------------------------------------------------------------------------"
echo ""
echo "VISIT PORTAINER URL NOW TO SET INITIAL LOGIN:"
echo " https://$_portainer_url"
echo ""
echo "Traefik URl: https://$_server_base_url"
echo ""
echo "WARNING: May get insecure SSL errors"
echo " this is temporary while certs are in process of being issued"
rm /tmp/setup.sh

9
webserver-provision.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
. ./config
_ssh_url="root@$_remote_host.$_domain"
# ssh "$_remote_host.$_domain" '/bin/bash -s' < ./production/webserver-setup.sh
cat config ./production/webserver-setup.sh | ssh "$_ssh_url" "cat >/tmp/setup.sh"
ssh $_ssh_url '/bin/bash /tmp/setup.sh'