Skip to content

Commit

Permalink
feat: add github-deploiement-vers-gandi.md + YAML linter
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Feb 4, 2024
1 parent 691d4c4 commit 626b0a7
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 1 deletion.
15 changes: 14 additions & 1 deletion .aspell.fr.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 fr 196
personal_ws-1.1 fr 209
AVAX
Aborted
Add
Expand Down Expand Up @@ -30,6 +30,7 @@ Frame
GB
GJ
GPU
Gandi
Geth
Gio
Git
Expand All @@ -38,6 +39,7 @@ Gmail
Gogs
HDMI
HTTP
Host
ICUSB
IMAP
IP
Expand Down Expand Up @@ -85,6 +87,7 @@ Rabby
Raspberry
Raspbian
Rpi
SFTP
SSH
SVG
Server
Expand Down Expand Up @@ -115,6 +118,7 @@ WebSocket
Wi-Fi
Windows
Working
YAML
ZIP
Zsh
account-pwd.txt
Expand All @@ -131,28 +135,35 @@ configurateur
copiez-le
cronjob
debug
deploy
deploy.yml
dev
double-cliquez
d�bogage
email
error
failed
favicon
fork
frame
framework
from
func
genesis
git
hash
htdocs
identifiants
infos
inverter
key
keystore
l'URL
l'Utilisateur
l'audio
l'onduleur
learn
lftp
libpng
logs
luma
Expand Down Expand Up @@ -190,8 +201,10 @@ t
t�l�charger
vCPU
validator
verification
web
window
work
worker
workflow
xxx
10 changes: 10 additions & 0 deletions checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ check_spelling_files() {
check_spelling_file 'README.md'
}

check_yaml_file() {
yamllint -d relaxed "${1}"
}

check_yaml_files() {
check_yaml_file "${FOLDER}"
check_yaml_file '.github'
}

main() {
check_python_files
check_shell_files
check_markdown_files
check_yaml_files
check_spelling_files
}

Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
75 changes: 75 additions & 0 deletions sources/linux/github-deploiement-vers-gandi.md
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.
16 changes: 16 additions & 0 deletions sources/linux/snippets/github-deploiement-vers-gandi.sh
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}"
27 changes: 27 additions & 0 deletions sources/linux/snippets/github-deploiement-vers-gandi.yml
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 }}'

0 comments on commit 626b0a7

Please sign in to comment.