Serveur
LeThe serveurserver estis hébergéhosted chezby Infomaniak, via una partenariat.partnership. La configurationConfiguration (pare.g. exempleport réseau)forwarding) seis faitdone depuisfrom leurtheir site webwebsite (icihere, logincredentials surare leon the Vaultwarden). and on a sheet at the Desk.
Infrastructure
LaInfrastructure configuration deis l'infrastructureon est sur le repositorythe Clic Infra. Chaquerepository. Each service estis hébergéhosted sousas la forme d'une stacka Docker. Celastack. permetThis demakes facilementit d'eneasy ajouterto sansadd senew soucierservices deswithout dépendences,worrying l'about dependencies, architecture, etc. LaUpdating misethe àserver jourwhen du serveur quand lathe configuration ahas étébeen modifiémodified seis faitdone grâceusing àthe l'outil[Ansible] Ansibletool (https://www.ansible.com/).
NoteImportant importante:note: lethe reverse-proxy (Caddy) n'estis pasnot dansin una containerDocker Docker,container, maisbut directementdirectly installéinstalled suron lathe machine. VoirSee l'explicationexplanation plus bas.below.
Ajouter/Enlever/ModifierAdd/Remove/Modify una service
LesModifications modificationsto dethe l'infrastructure doiventmust êtrefirst opéréebe d'abordmade suron lethe repositoryinfra d'infra,repository, puisthen appliquéeapplied auto serveurthe enserver utilisantusing Ansible (voirsee ci-dessous)below).
ChaqueEach service estis configuréconfigured via un fichiera docker-compose.yaml file (doc), dansin una dossierfolder unique auto the service àat lathe racinerepository duroot. repository.Services Lesgenerally servicesnever necommunicate communiquentwith deeach manièreother généraleother jamaisother entrethan euxvia autrementtheir qu'au travers de leursexposed APIs exposées (e.g. lethe sitewebsite web accède àaccesses Directus envia passantits parpublic sonurl, url publique, et nonnot via una réseaudedicated virtuelvirtual dédié)network). SiIf una service nécessiterequires unea database, elleit estis instanciéeinstantiated dansin lathe mêmesame stack queas luithe etservice luiand estis exclusivementexclusively dédiée.dedicated to it.
SiIf lethe service nécessiteneeds d'êtreto be accessible via internet,the ilInternet, doitit exposermust unexpose (plusieurs)one port(s),or quimore serontports, ensuitewhich exposéwill àthen l'extérieurbe parexposed leto the outside world by the reverse-proxy.
GestionSecret des secretsmanagement
LesServices servicesmay peuventrequire nécessiter des informations privéesprivate (ouor spécifiqueserver-specific) auinformation, serveur),such paras exemplean unadmin motpassword, deor passea admin,mailbox oupassword. celuiThese devalues laare boîtestored mailin IT. Ces valeurs sont stockées dans un fichiera secrets.yaml file (dansin /home/debian), etand chargéesloaded parby Ansible lorsduring dudeployment. déployement.They Ellesmust doiventbe êtrereferenced référencéesin dans le Playbookthe playbook/deploy.yaml dansplaybook lain tâchethe deverification vérificationtask, etand passéespassed enas tant queenvironment variables d'environnementto àthe lastack tâchedeployment detask. déploiementThey descan stacks.then Ellesbe peuventretrieved ensuitefrom êtreeach récupérées dans lastack's configuration deusing chaque stack avec lathe syntax ${MY_SECRET}.
DéploiementDeployment
LeDeployment déploiementis secarried faitout enusing utilisantthe le Playbookplaybook playbook/deploy.yaml, quiwhich vawill mettreupdate à jour toutes lesall stacks. /!\ AttentionWarning /!\ : les stacks doiventmust pouvoirbe êtremodifiable modifiéewith avec una simple docker stack deploy; ildon't ne faut pas utiliser deuse config, caras cesthese dernièresare sontimmutable. immuables.The Ilstack faudraitwould enleverhave puisto redéployerbe laremoved stack,and cethen quiredeployed, estwhich sous-is sub-optimal. OnInstead, préferera configurer lesconfigure services via leurstheir variablesenvironment d'environnement.variables.
SauvegardesBackups
LesBackups sauvegardesare sontmanaged gérées parby BorgBackup, ceenabling quiencrypted, permetincremental d'avoirbackups. des backups chiffrées et incrémentales. L'outilThe [Borgmatic], configurétool, parconfigured leby Playbook playbook/deploy.yaml, s'occupeperiodically degenerates périodiquementand généreruploads etbackups. uploader des sauvegardes. SaIts configuration (égalementalso dansin lethe Playbook) doitmust êtrebe miseupdated àwhenever jour lorsque qu'una service estis ajouté/enlevé/modifié.added/removed/modified.
Installation
In the event of a complete server reinstallation, here are the steps to follow:
- Use the init playbook: create an inventory on your computer (see the docs), then
ansible-playbook -i <inventory> <path/to/init.yaml>. - SSH into the server.
- Set up the
/var/secrets.yamlfile (see the example in the infra repo). Move the database dumps to the directories set in this file. If you do not have access to the Directus tokens, use a stub. - Generate an SSH key for
rootand save it in the deployment keys of the infra repository. - Launch a swarm with Playbook
deploy.yaml:ansible-pull -U git@github.com:clicepfl/clic-infra.git -e @/var/secrets.yaml playbooks/deploy.yaml. - Load the databases content, using
docker exec -it <container-name> shthen eitherpsql -U <user> <database> < /docker-entrypoint-initdb.d/init.sqlormysql --user <user> -p < /docker-entrypoint-initdb.d/<script-name>.sql. - Stop all the services (
docker swarm leave --force). - Copy/Move the file content in the volumes (stored under
/var/lib/docker/volumes/<volume-name>/data), after having remove the content placed by the first run of each service. Skip database volumes (already initialized). - If needed, regenerate token for Directus and set them in the secrets file.
- Restart all the services using the playbook
deploy.yaml. - Launch caddy:
ansible-pull -U git@github.com:clicepfl/clic-infra.git playbooks/caddy.yaml - Launch the webhook:
ansible-pull -U git@github.com:clicepfl/clic-infra.git playbooks/webhook.yaml
Everything should be set now !