Setup
Describes how the server VM has been setup from the map5topo repo. This basically describes how you can setup your local system to start preparing data and creating maps.
Below all steps are documented.
1. Ubuntu Server
Info:
- Hetzner Cloud Linux Ubuntu server Virtual Machine (VM), with Ubuntu 20.4
- Specs: CX41 2 VCPU 8 GB RAM 40 GB DISK LOCAL - 15.90 a month
- Extra Volume 300GB - 12.00 a month
- IP address
65.108.253.148
Prepare server steps:
- DNS: create A-record
topo.map5.nl
for IP address65.108.253.148
- local user with full sudo rights e.g.
sudo su -
- Upgrade server to latest:
apt-get update && apt-get -y upgrade
- provide local user direct SSH root access via
authorized_keys
(needed for Ansible)
Extra Volume
300GB for tile caches and Docker storage.
1 2 3 4 |
|
Later we will configure Docker daemon to use this storage.
600GB for AHN source and hillshade Tiffs. After preparation we'll store in long-term storage and remove this volume. Output result is around 90GB Hillshade files.
1 2 3 4 5 |
|
2. Prepare Local System
On your local system you mainly need to have Ansible
and Git
(client) installed:
Install Ansible:
- have Python 3 (3.7 or better) installed
- OPTIONAL (but recommended) create a Python Virtualenv (for Ansible)
- install Ansible with
pip install ansible
2.9.* or higher - test:
ansible --version
- shows ansible 2.9.19 ... - test:
ansible-vault --version
shows ansible-vault 2.9.19 ...
More on Ansible below.
Install Git
client.
Depends on your system. Make sure you have a command line git
(CLI).
3. Prepare New GitHub Repo
Clone the Git repo locally: git clone https://github.com/map5nl/map5topo.git
We will call the root dir of the cloned git repo on your system just git/
from here.
4. Setup Ansible
Most of the configuration that is specific to your new server is stored under:
git/ansible/hosts
(Ansible inventories)git/ansible/vars
(variables and SSH keys).
Files under git/ansible/vars
need to be always encrypted with Ansible Vault
. You will need to
create your own (encrypted) version of these encrypted files.
For many files an example file is given.
Install Ansible Modules
Called "Roles" these are third-party Ansible components that help with specific tasks. Install these as follows:
1 2 |
|
Ansible Hosts
The hostname is crucial to services functioning. Two steps:
- set content of
git/ansible/hosts/prod.yml
(Inventory) to
1 2 3 4 5 6 7 |
|
- note:
MAP5TOPO
will also be the new hostname, and prompt name - set content of
git/env.sh
(common environment Docker-based services) to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
So MAP_AREA=prod
here is to discern with a deployment on localhost
(MAP_AREA=test
, where .e.g. no https/SSL is used).
Create SSH Keys
These are used to invoke actions on the server both from GitHub Actions (via GitHub Sercrets) and from your local Ansible setup. Plus a set of authorized_keys for the admin SSH user.
- cd
git/ansible/vars
- create new SSH keypair (no password):
ssh-keygen -t rsa -q -N "" -f gh-key.rsa
Create authorized_keys
Create new git/ansible/vars/authorized_keys
with your public key and for others you want to give access to the admin SSH account,
plus gh-key.rsa.pub
.
1 2 3 |
|
Set these for the root
and <admin user>
in their .ssh/authorized_keys
.
See MAP5TOPO_GH
GitHub Deploy key below.
1 |
|
Set GitHub Deploy Key and Secrets
Go to GH repo Settings/keys
- set DEPLOY_KEY from
git/ansible/vars/gh-key.rsa.pub
Go to GH repo Settings|Secrets and create these secrets for Actions:
- ANSIBLE_SSH_PRIVATE_KEY - with value from
git/ansible/vars/gh-key.rsa
- ANSIBLE_VAULT_PASSWORD - value from
~/.ssh/ansible-vault/map5topo.txt
Adapt vars.yml
Create new git/ansible/vars/vars.yml
from example vars.example.yml
in that dir.
The first part of vars.yml
contains generic, less-secret, values.
Use variables where possible. Format is Python-Jinja2 template-like:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Note the GitHub repo is SSH-based for deploy-key!
The second part deals with more secret values, like usernames and passwords for services.
These will be copied into the VM's /etc/environment
file.
1 2 3 4 5 6 |
|
Create Ansible Vault Password
- create strong password
- store in
~/.ssh/ansible-vault/map5topo.txt
for convenience
Encrypt Ansible Files
VERY IMPORTANT. UNENCRYPTED FILES SHOULD NEVER BE CHECKED IN!!!
Using ansible-vault
with password encrypt these:
1 2 3 4 |
|
Disable GitHub Workflows
We do not want that workflows take effect immediately. So disable them temporary by renaming the dir.
1 2 3 4 5 |
|
5 Bootstrap/provision Server
Moment of truth! Bootstrap (provision the server) in single playbook. Save the logfile for analysis.
ansible-playbook -v --vault-password-file ~/.ssh/ansible-vault/map5topo.txt bootstrap.yml -i hosts/prod.yml > bootstrap.log 2>&1
If all goes well, this output should be shown at end:
PLAY RECAP ***********************************************************************************************************
apisandbox : ok=58 changed=22 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
Observe output for errors (better is to save output in file via .. > bootstrap.log 2>&1
).
In cases of errors and after fixes, simply rerun the above Playbook.
Site should be running at: https://topo.map5.nl Check with portainer https://topo.map5.nl/portainer/.
6 Docker storage in attached Volume
See https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
6a Disk Resizing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
7 Resolve Issues
These are typical issues found and resolved:
- make sure the
gh-key.rsa.pub
is present in both/root
and/home/<admin user>
.ssh/authorized_keys
postgis + pgadmin
: needed to manuallystop.sh
, remove all volumes andstart.sh
otherwise could not login on pgadmin nor postgis from there
8. Enable GitHub Workflows
Enable by renaming:
1 2 3 4 |
|