2020-11-14 08:55:36 +00:00
= PyInventory - deployment instruction
2020-10-26 17:00:02 +00:00
2020-12-09 19:16:10 +00:00
Install PyInventory on a rood server via docker-compose.
2020-10-26 17:00:02 +00:00
2020-10-27 07:49:19 +00:00
**Note:**
2020-10-26 17:00:02 +00:00
2020-12-09 19:16:10 +00:00
* PyInventory is also available as [[https://yunohost.org|YunoHost]] App via [[https://github.com/YunoHost-Apps/pyinventory_ynh|pyinventory_ynh]]
2020-11-14 08:55:36 +00:00
* This README contains only the instruction to install PyInventory on a root server.
* Read [[https://github.com/jedie/PyInventory/tree/master#readme|the main README]] for local development installation.
2020-10-26 17:00:02 +00:00
2020-12-09 19:16:10 +00:00
2020-10-26 17:00:02 +00:00
Pull requests welcome!
2020-10-27 07:49:19 +00:00
2020-11-14 08:55:36 +00:00
== Project structure
2020-10-27 07:45:07 +00:00
2020-11-14 08:55:36 +00:00
There are two main directories:
2020-10-27 07:45:07 +00:00
2020-11-14 08:55:36 +00:00
|= directory |= description
| **[[https://github.com/jedie/PyInventory/tree/master/src|/src/]]** | The main PyInventory source code
| **[[https://github.com/jedie/PyInventory/tree/master/deployment|/deployment/]]** | deploy PyInventory for production use case
2020-10-27 07:45:07 +00:00
2020-10-27 07:49:19 +00:00
== deploy
2020-10-27 07:45:07 +00:00
2020-10-27 07:49:19 +00:00
Install PyInventory on a root server:
2020-10-26 17:00:02 +00:00
2020-10-27 09:43:33 +00:00
**Note:**
* Running a public web server is a lot of work and brings some risks.
* This instructions are only the basics to get PyInventory working.
* To run the server safely, more work should be done, which is not explained here.
* Run at your own risk! No warranty is given.
2020-10-27 08:15:50 +00:00
2020-10-27 09:43:33 +00:00
=== prepare root server
2020-10-27 08:15:50 +00:00
Here some steps for a fresh created root server:
Update all packages, e.g.:
{{{
apt update && apt -y full-upgrade
}}}
Setup a normal user. You may use [[https://github.com/jedie/PyInventory/blob/deployment/scripts/setup_user.sh|scripts/setup_user.sh]]
=== Setup SSH services
{{{
~# nano /etc/ssh/sshd_config
}}}
Change e.g.:
{{{
Port xxxx
PermitRootLogin no
PasswordAuthentication no
}}}
(Changing the Port may need to change a firewall/network settings)
{{{
# restart SSH deamon:
~# service ssh restart
# Display and follow the ssh log output to see connection errors:
~# journalctl -f -u ssh
}}}
* Keep the current SSH session (with the log output) open!
* Update your {{{~/.ssh/config}}}
* Try to connect as the new, normal user in a **separate** terminal
Only after a working new connection: Terminate the first root SSH session ;)
=== setup unattended-upgrades
{{{
~$ sudo apt install unattended-upgrades
~$ sudo dpkg-reconfigure unattended-upgrades
~$ sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
}}}
2020-10-27 09:04:49 +00:00
=== install requirements
Install docker, see: https://docs.docker.com/engine/install/ubuntu/
install some base packages, e.g.:
{{{
~$ sudo apt install git make
}}}
2020-10-27 08:15:50 +00:00
=== install PyInventory
2020-10-26 17:00:02 +00:00
{{{
2020-10-27 07:45:07 +00:00
# Checkout the deployment branch:
2020-11-14 08:55:36 +00:00
~$ git clone https://github.com/jedie/PyInventory.git
~$ cd PyInventory/deployment/
2020-10-27 07:45:07 +00:00
# Theses Makefile targets exists:
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make
2020-11-14 09:55:05 +00:00
_________________________________________________________________
2020-11-22 11:51:14 +00:00
*Deployment* Makefile
2020-11-14 09:55:05 +00:00
2020-10-26 17:00:02 +00:00
install-poetry install or update poetry
install install requirements to setup project
2020-11-11 16:58:44 +00:00
update update the sources and docker containers
2020-10-26 17:00:02 +00:00
up Start containers via docker-compose
down Stop all containers
prune Cleanup docker
build Update docker container build
2020-11-11 16:58:44 +00:00
init_postgres Create postgres database
2020-10-26 17:00:02 +00:00
createsuperuser Create super user
2020-11-22 11:51:14 +00:00
shell_django Go into bash shell in django container
2020-11-11 16:58:44 +00:00
shell_postgres Go into bash shell in postgres container
shell_caddy Go into bash shell in caddy container
caddy_environ Prints the caddy environment
2020-10-26 17:00:02 +00:00
logs Display docker logs from all containers
2020-11-11 16:58:44 +00:00
logs_postgres Display docker logs from postgres container
2020-11-22 11:51:14 +00:00
logs_django Display docker logs from django container
2020-11-11 16:58:44 +00:00
logs_caddy Display docker logs from caddy container
2020-10-26 17:00:02 +00:00
dbbackup Backup database
dbrestore Restore a database backup
restart Restart all containers
2020-11-22 11:51:14 +00:00
upgrade_django Upgrade "django" container and restart it
2020-11-11 16:58:44 +00:00
restart_caddy Restart caddy container
2020-11-11 17:31:15 +00:00
reload_caddy Reload Caddy server
2020-11-22 11:51:14 +00:00
reload_django Reload server in "django" container
2020-10-26 17:00:02 +00:00
}}}
2020-10-27 08:15:50 +00:00
Install, e.g.:
2020-10-27 07:45:07 +00:00
2020-10-26 17:00:02 +00:00
{{{
# install or update poetry:
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make install-poetry
2020-10-27 09:04:49 +00:00
}}}
To keep poetry running (PATH must be expand) just logout and login ;)
2020-10-26 17:00:02 +00:00
2020-10-27 09:04:49 +00:00
{{{
2020-10-27 07:45:07 +00:00
# install requirements (e.g.: docker-compose) via poetry:
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make install
2020-10-26 17:00:02 +00:00
}}}
2020-10-27 07:45:07 +00:00
Create a {{{.env}}} file in project root directory with these content, e.g.:
2020-10-26 17:00:02 +00:00
{{{
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ touch .env
~/PyInventory/deployment$ nano .env
~/PyInventory/deployment$ cat .env
2020-10-27 07:45:07 +00:00
# Your Public domain:
HOSTNAME=domain.tld
# eMail address for Let's encrypt:
LETSENCRYPT_EMAIL=webmaster@domain.tld
2020-10-26 17:00:02 +00:00
}}}
2020-10-27 07:45:07 +00:00
For local testing of the docker-compose setup, used this values:
2020-10-26 17:00:02 +00:00
{{{
HOSTNAME=localhost
LETSENCRYPT_EMAIL=internal
}}}
2020-10-27 07:45:07 +00:00
(Caddy will create a self signed https certificate)
2020-10-26 17:00:02 +00:00
Start containers via docker-compose:
{{{
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make up
2020-10-26 17:00:02 +00:00
}}}
2020-10-27 08:15:50 +00:00
Notes: At the first start it takes a little while until the database is created ;)
2020-10-26 17:00:02 +00:00
Create first super user:
{{{
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make docker_createsuperuser
2020-10-26 17:00:02 +00:00
}}}
2020-10-27 08:15:50 +00:00
* Now you should be able to connect to your PyInventory installation and login with created super user.
* Redirect from **http** to **https** should work.
* Let's Encrypt certificate should be installed and valid.
* Containers should be restarted after a server reboot
=== Maintenance
TO keep everything up-to-date do the following steps:
Update the OS call:
{{{
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ sudo ./scripts/apt-distupgrade.sh
2020-10-27 08:15:50 +00:00
}}}
Update PyInventory installation and docker containers:
{{{
2020-11-14 08:55:36 +00:00
~/PyInventory/deployment$ make update
2020-10-27 08:15:50 +00:00
}}}
This will do:
* update the source code
* update docker-compose and all requirements
* Pull and rebuild all docker containers
* restart all docker containers
2020-10-27 09:46:04 +00:00
Take a look at [[https://github.com/jedie/PyInventory/blob/deployment/scripts/apt-cleanup.sh|scripts/apt-cleanup.sh]] to keep your system clean.
2020-10-27 08:15:50 +00:00
2020-10-26 17:00:02 +00:00
== links ==
| Homepage | http://github.com/jedie/PyInventory
2020-10-27 08:15:50 +00:00
Web server stuff:
* https://help.ubuntu.com/community/Security
* https://help.ubuntu.com/lts/serverguide/automatic-updates.html
* https://help.ubuntu.com/community/AutomaticSecurityUpdate
2020-10-26 17:00:02 +00:00
== donation ==
* [[https://www.paypal.me/JensDiemer|paypal.me/JensDiemer]]
* [[https://flattr.com/submit/auto?uid=jedie&url=https%3A%2F%2Fgithub.com%2Fjedie%2FPyInventory%2F|Flattr This!]]
* Send [[http://www.bitcoin.org/|Bitcoins]] to [[https://blockexplorer.com/address/1823RZ5Md1Q2X5aSXRC5LRPcYdveCiVX6F|1823RZ5Md1Q2X5aSXRC5LRPcYdveCiVX6F]]