-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add github-deploiement-vers-gandi.md + YAML linter
- Loading branch information
Showing
6 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ mypy==1.8.0 | |
pymarkdownlnt==0.9.16 | ||
ruff==0.2.0 | ||
sphinx-autobuild==2021.3.14 | ||
yamllint==1.33.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# GitHub : Déployer un site web vers Gandi | ||
|
||
Gandi permet de déployer un site web via git ou SFTP. Voyons comment automatiser le déploiement via SFTP. | ||
|
||
## Prérequis | ||
|
||
Nous utiliserons [lftp](https://lftp.yar.ru/lftp-man.html) pour l'envoi des fichiers : | ||
|
||
```{literalinclude} snippets/github-deploiement-vers-gandi.sh | ||
:lines: 3 | ||
:language: shell | ||
``` | ||
|
||
## Manuel | ||
|
||
Pas directement lié à GitHub, ces étapes peuvent servir à déployer depuis n'importe quelle machine. | ||
|
||
### Constantes | ||
|
||
D'abord, nous aurons besoin de définir ces constantes : | ||
|
||
```{literalinclude} snippets/github-deploiement-vers-gandi.sh | ||
:lines: 5-8 | ||
:language: shell | ||
``` | ||
|
||
### ⚠️ Approuver la Connexion | ||
|
||
```{hint} | ||
Bien que nécessaire, cette étape est à ne faire qu'une seule fois par machine. | ||
``` | ||
|
||
Approuver la connexion au serveur pour éviter l'erreur "*Fatal error: Host key verification failed*" : | ||
|
||
```{literalinclude} snippets/github-deploiement-vers-gandi.sh | ||
:lines: 10-11 | ||
:language: shell | ||
``` | ||
|
||
### Répliquer | ||
|
||
Voici la dernière étape qui permet de faire un miroir d'un dossier local vers un dossier distant (remplacer `FOLDER` par le dossier local) : | ||
|
||
```{literalinclude} snippets/github-deploiement-vers-gandi.sh | ||
:lines: 13-16 | ||
:emphasize-lines: 2 | ||
:language: shell | ||
``` | ||
|
||
## Automatisation | ||
|
||
Maintenant que les étapes sont connues, nous utiliserons un *workflow* GitHub pour déployer le site à chaque changement poussé sur la branche principale du dépôt. | ||
|
||
### Secrets | ||
|
||
Dans les paramètres du dépôt GitHub, déclarer 4 secrets identiques aux [constantes](#constantes) déclarées plus haut. | ||
|
||
### *Workflow* | ||
|
||
Voici le script YAML complet : | ||
|
||
```{literalinclude} snippets/github-deploiement-vers-gandi.yml | ||
:caption: .github/workflows/deploy.yml | ||
:emphasize-lines: 6,25 | ||
:language: yaml | ||
``` | ||
|
||
### Exemple Complet | ||
|
||
Un exemple spécifique à Python, utilisé par ce site même, peut être visible par ici : [BoboTiG/luma:deploy](https://github.com/BoboTiG/luma/blob/main/.github/workflows/deploy.yml). | ||
|
||
## 📜 Historique | ||
|
||
2024-02-04 | ||
: Premier jet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
sudo apt install lftp | ||
|
||
SFTP_URL='HOST' | ||
SFTP_USER='USERNAME' | ||
SFTP_PASSWORD='PASSWORD' | ||
SFTP_PATH='/mnt/vhost/site/subfolder/' | ||
|
||
mkdir -p ~/.ssh \ | ||
&& ssh-keyscan -H "${SFTP_URL}" >> ~/.ssh/known_hosts | ||
|
||
lftp \ | ||
-e "mirror --delete --transfer-all --reverse --verbose=1 ./FOLDER ${SFTP_PATH} ; quit" \ | ||
-u "${SFTP_USER},${SFTP_PASSWORD}" \ | ||
"sftp://${SFTP_URL}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: sudo apt install -y lftp | ||
|
||
- name: Setup SSH | ||
run: | | ||
mkdir -p ~/.ssh | ||
ssh-keyscan -H ${{ secrets.SFTP_URL }} >> ~/.ssh/known_hosts | ||
- name: Automation | ||
run: | | ||
lftp \ | ||
-e 'mirror --delete --transfer-all --reverse --verbose=1 ./FOLDER ${{ secrets.SFTP_PATH }} ; quit' \ | ||
-u '${{ secrets.SFTP_USER }},${{ secrets.SFTP_PASSWORD }}' \ | ||
'sftp://${{ secrets.SFTP_URL }}' |