Skip to main content

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:

  1. Use the init playbook: create an inventory on your computer (see the docs), then ansible-playbook -i <inventory> <path/to/init.yaml>.
  2. SSH into the server.
  3. Set up the /var/secrets.yaml file (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.
  4. Generate an SSH key for root and save it in the deployment keys of the infra repository.
  5. Launch a swarm with Playbook deploy.yaml: ansible-pull -U git@github.com:clicepfl/clic-infra.git -e @/var/secrets.yaml playbooks/deploy.yaml.
  6. Load the databases content, using docker exec -it <container-name> sh then either psql -U <user> <database> < /docker-entrypoint-initdb.d/init.sql or mysql --user <user> -p < /docker-entrypoint-initdb.d/<script-name>.sql.
  7. Stop all the services (docker swarm leave --force).
  8. 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).
  9. If needed, regenerate token for Directus and set them in the secrets file.
  10. Restart all the services using the playbook deploy.yaml.
  11. Launch caddy: ansible-pull -U git@github.com:clicepfl/clic-infra.git playbooks/caddy.yaml
  12. Launch the webhook: ansible-pull -U git@github.com:clicepfl/clic-infra.git playbooks/webhook.yaml

Everything should be set now !