labctl: dépôt autonome — module git.g3e.fr/syonad/labctl, exemple evpn-2hv, LABCTL_BIN, licence, README, CI
Some checks failed
Tests / test (push) Successful in 4m12s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (lab-host.sh, scripts/lab-host.sh) (push) Successful in 7s
Release Pipeline / build (push) Successful in 1m31s
Release Pipeline / build (amd64, linux) (push) Successful in 0s
Release Pipeline / build (arm64, darwin) (push) Successful in 0s
Release Pipeline / checksums (push) Successful in 6s
Release Pipeline / release (push) Failing after 22s
Release Pipeline / publish (push) Failing after 0s
Some checks failed
Tests / test (push) Successful in 4m12s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (lab-host.sh, scripts/lab-host.sh) (push) Successful in 7s
Release Pipeline / build (push) Successful in 1m31s
Release Pipeline / build (amd64, linux) (push) Successful in 0s
Release Pipeline / build (arm64, darwin) (push) Successful in 0s
Release Pipeline / checksums (push) Successful in 6s
Release Pipeline / release (push) Failing after 22s
Release Pipeline / publish (push) Failing after 0s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
070faec37a
commit
ef7392f09b
31 changed files with 766 additions and 36 deletions
43
.forgejo/workflows/build.yml
Normal file
43
.forgejo/workflows/build.yml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
tag:
|
||||
required: true
|
||||
type: string
|
||||
goos:
|
||||
required: true
|
||||
type: string
|
||||
goarch:
|
||||
required: true
|
||||
type: string
|
||||
binari:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: docker
|
||||
env:
|
||||
RELEASE_CIBLE: ${{ inputs.tag }}
|
||||
GOOS: ${{ inputs.goos }}
|
||||
GOARCH: ${{ inputs.goarch }}
|
||||
BINARI: ${{ inputs.binari }}
|
||||
CGO_ENABLED: 0
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25.14"
|
||||
- name: Build du projet
|
||||
run: |
|
||||
echo "Building for ${BINARI}/${GOOS}/${GOARCH} (release: ${RELEASE_CIBLE})"
|
||||
go env GOOS GOARCH
|
||||
mkdir -p dist/
|
||||
go build -o dist/${BINARI}_${GOOS}_${GOARCH} ./cmd/${BINARI}
|
||||
echo "artifact pour ${RELEASE_CIBLE} ${BINARI} ${GOOS} ${GOARCH}" > dist/${BINARI}-${GOOS}-${GOARCH}.txt
|
||||
ls -l ./dist
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ env.BINARI }}-${{ env.RELEASE_CIBLE }}-${{ env.GOOS }}-${{ env.GOARCH }}
|
||||
path: dist/${{ env.BINARI }}_${{ env.GOOS }}_${{ env.GOARCH }}
|
||||
119
.forgejo/workflows/release-pipeline.yml
Normal file
119
.forgejo/workflows/release-pipeline.yml
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
name: Release Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '[0-9]*.[0-9]*.[0-9]*'
|
||||
|
||||
jobs:
|
||||
set-release-target:
|
||||
runs-on: docker
|
||||
outputs:
|
||||
release_cible: ${{ steps.setvar.outputs.release_cible }}
|
||||
prerelease: ${{ steps.setvar.outputs.prerelease }}
|
||||
steps:
|
||||
- name: Déterminer la release cible
|
||||
id: setvar
|
||||
run: |
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
|
||||
# Formes acceptées, et rien d'autre :
|
||||
# X.Y.Z release finale → prerelease=false, notes obligatoires
|
||||
# X.Y.ZrcNNN préversion → prerelease=true, notes optionnelles
|
||||
#
|
||||
# Le nombre de chiffres de rc est fixé à 3 (rc016, pas rc16) pour que
|
||||
# le tri lexicographique des tags suive l'ordre chronologique.
|
||||
if [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
||||
then
|
||||
PRERELEASE=false
|
||||
elif [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+rc[0-9]{3}$ ]]
|
||||
then
|
||||
PRERELEASE=true
|
||||
else
|
||||
echo "tag hors convention : ${TAG}" >&2
|
||||
echo "formes acceptées : X.Y.Z (release) ou X.Y.ZrcNNN (préversion, rc sur 3 chiffres)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "release_cible=${TAG}" >> $GITHUB_OUTPUT
|
||||
echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Afficher la variable
|
||||
run: |
|
||||
echo "Release cible = ${{ steps.setvar.outputs.release_cible }}"
|
||||
echo "Prerelease = ${{ steps.setvar.outputs.prerelease }}"
|
||||
build:
|
||||
needs: [set-release-target]
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- goos: linux
|
||||
goarch: amd64
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
uses: ./.forgejo/workflows/build.yml
|
||||
with:
|
||||
tag: ${{ needs.set-release-target.outputs.release_cible }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
binari: labctl
|
||||
secrets: inherit
|
||||
# Scripts publiés comme assets de release, à côté des binaires.
|
||||
upload-assets:
|
||||
runs-on: docker
|
||||
needs: [set-release-target]
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- path: scripts/lab-host.sh
|
||||
name: lab-host.sh
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Move asset
|
||||
run: |
|
||||
mkdir -p "dist"
|
||||
cp "${{ matrix.path }}" dist/
|
||||
- name: Upload asset
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ matrix.name }}-${{ needs.set-release-target.outputs.release_cible }}
|
||||
path: dist/${{ matrix.name }}
|
||||
# Manifeste des sommes de contrôle de tous les artefacts, au format sha256sum.
|
||||
# Dépend de tous les jobs qui produisent des artefacts : ajouter un producteur
|
||||
# sans l'ajouter ici donnerait un manifeste incomplet, donc une vérification qui
|
||||
# refuse des assets légitimes.
|
||||
checksums:
|
||||
runs-on: docker
|
||||
needs: [set-release-target, build, upload-assets]
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: artifacts/
|
||||
- name: Générer SHA256SUMS
|
||||
run: |
|
||||
mkdir -p dist
|
||||
# download-artifact place chaque artefact dans son propre
|
||||
# sous-répertoire : on aplatit pour que le manifeste porte les noms
|
||||
# d'assets, tels qu'on les télécharge.
|
||||
find artifacts/ -type f -exec cp {} dist/ \;
|
||||
# Généré depuis dist/ pour que les noms soient nus, et hors de dist/
|
||||
# pour que le manifeste ne se liste pas lui-même.
|
||||
( cd dist && sha256sum * ) > SHA256SUMS
|
||||
cat SHA256SUMS
|
||||
- name: Upload SHA256SUMS
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: SHA256SUMS-${{ needs.set-release-target.outputs.release_cible }}
|
||||
path: SHA256SUMS
|
||||
publish:
|
||||
# Tous les producteurs d'artefacts sont dans les needs : sans ça, le job
|
||||
# release peut appeler download-artifact avant la fin des uploads et publier
|
||||
# une release incomplète (assets ou manifeste manquants de façon non
|
||||
# déterministe).
|
||||
needs: [set-release-target, build, upload-assets, checksums]
|
||||
uses: ./.forgejo/workflows/release.yml
|
||||
with:
|
||||
tag: ${{ needs.set-release-target.outputs.release_cible }}
|
||||
prerelease: ${{ needs.set-release-target.outputs.prerelease }}
|
||||
secrets: inherit
|
||||
112
.forgejo/workflows/release.yml
Normal file
112
.forgejo/workflows/release.yml
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
tag:
|
||||
required: true
|
||||
type: string
|
||||
prerelease:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: docker
|
||||
env:
|
||||
TOKEN: ${{ secrets.RELEASE }}
|
||||
TAG: ${{ inputs.tag }}
|
||||
PRERELEASE: ${{ inputs.prerelease }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Download all build artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: dist/
|
||||
- name: Publier tous les binaires
|
||||
run: ls -lR dist/
|
||||
- name: Install jq
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y jq
|
||||
- name: Préparer les notes de version
|
||||
run: |
|
||||
NOTES="release_notes/${TAG}.md"
|
||||
# Titre par défaut : le tag seul. Un H1 en première ligne des notes le
|
||||
# remplace par « <tag> — <nom de version> ».
|
||||
RELEASE_NAME="${TAG}"
|
||||
|
||||
if [[ -f "${NOTES}" ]]
|
||||
then
|
||||
echo "notes trouvées : ${NOTES}"
|
||||
FIRST_LINE=$(head -1 "${NOTES}")
|
||||
if [[ "${FIRST_LINE}" =~ ^\#[[:space:]]+(.+)$ ]]
|
||||
then
|
||||
RELEASE_NAME="${TAG} — ${BASH_REMATCH[1]}"
|
||||
# H1 retiré du corps : Forgejo affiche déjà le titre au-dessus, le
|
||||
# garder l'afficherait deux fois. `/./,$!d` mange les lignes vides
|
||||
# laissées en tête.
|
||||
tail -n +2 "${NOTES}" | sed '/./,$!d' > body.md
|
||||
else
|
||||
cp "${NOTES}" body.md
|
||||
fi
|
||||
elif [[ "${PRERELEASE}" == "true" ]]
|
||||
then
|
||||
echo "aucune note pour ${TAG}, texte générique (préversion)"
|
||||
echo "Prerelease automatique générée par la CI" > body.md
|
||||
else
|
||||
echo "release finale ${TAG} sans notes de version" >&2
|
||||
echo "créer ${NOTES} avant de pousser le tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_ENV}"
|
||||
echo "--- titre --- ${RELEASE_NAME}"
|
||||
echo "--- body ---"; cat body.md
|
||||
- name: Create release
|
||||
run: |
|
||||
jq -n \
|
||||
--arg tag "${TAG}" \
|
||||
--arg name "${RELEASE_NAME}" \
|
||||
--rawfile body body.md \
|
||||
--argjson prerelease "${PRERELEASE}" \
|
||||
'{
|
||||
tag_name: $tag,
|
||||
name: $name,
|
||||
body: $body,
|
||||
draft: false,
|
||||
prerelease: $prerelease,
|
||||
hide_archive_links: true
|
||||
}' > payload.json
|
||||
cat payload.json | jq -c '.body |= (.[0:60] + "…")'
|
||||
|
||||
# Code HTTP vérifié explicitement plutôt qu'avec --fail-with-body, qui
|
||||
# exige curl >= 7.76 : sans ça un échec (409 tag déjà publié, 401 token
|
||||
# invalide) passerait inaperçu et la release resterait sans assets.
|
||||
HTTP=$(curl -sS -o resp.json -w '%{http_code}' -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases" \
|
||||
-d @payload.json)
|
||||
echo "HTTP ${HTTP}"
|
||||
cat resp.json; echo
|
||||
[[ "${HTTP}" == 2* ]] || { echo "création de la release échouée" >&2; exit 1; }
|
||||
- name: Upload asset
|
||||
run: |
|
||||
RELEASE_ID=$(curl -s \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases/tags/${TAG} \
|
||||
| jq -r .id)
|
||||
echo ${RELEASE_ID}
|
||||
# Sans ce garde-fou, un id absent (null) enverrait chaque asset sur
|
||||
# .../releases/null/assets : une cascade de 404 silencieux et une
|
||||
# release publiée sans aucun binaire.
|
||||
[[ "${RELEASE_ID}" =~ ^[0-9]+$ ]] || { echo "id de release introuvable pour ${TAG}" >&2; exit 1; }
|
||||
ls dist | while read tmp
|
||||
do
|
||||
FILE=$(ls "./dist/${tmp}")
|
||||
echo ${FILE}
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @dist/${tmp}/${FILE} \
|
||||
"https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${FILE}"
|
||||
done
|
||||
25
.forgejo/workflows/test.yml
Normal file
25
.forgejo/workflows/test.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['**']
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25.14"
|
||||
- name: Outils des tests de lab-host.sh
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y jq python3
|
||||
- name: go vet
|
||||
run: go vet ./...
|
||||
- name: go test
|
||||
run: go test ./...
|
||||
- name: lab-host.sh
|
||||
run: bash scripts/lab-host_test.sh
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/dist/
|
||||
/labctl
|
||||
131
LICENSE
Normal file
131
LICENSE
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
# PolyForm Noncommercial License 1.0.0
|
||||
|
||||
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
||||
|
||||
## Acceptance
|
||||
|
||||
In order to get any license under these terms, you must agree
|
||||
to them as both strict obligations and conditions to all
|
||||
your licenses.
|
||||
|
||||
## Copyright License
|
||||
|
||||
The licensor grants you a copyright license for the
|
||||
software to do everything you might do with the software
|
||||
that would otherwise infringe the licensor's copyright
|
||||
in it for any permitted purpose. However, you may
|
||||
only distribute the software according to [Distribution
|
||||
License](#distribution-license) and make changes or new works
|
||||
based on the software according to [Changes and New Works
|
||||
License](#changes-and-new-works-license).
|
||||
|
||||
## Distribution License
|
||||
|
||||
The licensor grants you an additional copyright license
|
||||
to distribute copies of the software. Your license
|
||||
to distribute covers distributing the software with
|
||||
changes and new works permitted by [Changes and New Works
|
||||
License](#changes-and-new-works-license).
|
||||
|
||||
## Notices
|
||||
|
||||
You must ensure that anyone who gets a copy of any part of
|
||||
the software from you also gets a copy of these terms or the
|
||||
URL for them above, as well as copies of any plain-text lines
|
||||
beginning with `Required Notice:` that the licensor provided
|
||||
with the software. For example:
|
||||
|
||||
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
||||
|
||||
## Changes and New Works License
|
||||
|
||||
The licensor grants you an additional copyright license to
|
||||
make changes and new works based on the software for any
|
||||
permitted purpose.
|
||||
|
||||
## Patent License
|
||||
|
||||
The licensor grants you a patent license for the software that
|
||||
covers patent claims the licensor can license, or becomes able
|
||||
to license, that you would infringe by using the software.
|
||||
|
||||
## Noncommercial Purposes
|
||||
|
||||
Any noncommercial purpose is a permitted purpose.
|
||||
|
||||
## Personal Uses
|
||||
|
||||
Personal use for research, experiment, and testing for
|
||||
the benefit of public knowledge, personal study, private
|
||||
entertainment, hobby projects, amateur pursuits, or religious
|
||||
observance, without any anticipated commercial application,
|
||||
is use for a permitted purpose.
|
||||
|
||||
## Noncommercial Organizations
|
||||
|
||||
Use by any charitable organization, educational institution,
|
||||
public research organization, public safety or health
|
||||
organization, environmental protection organization,
|
||||
or government institution is use for a permitted purpose
|
||||
regardless of the source of funding or obligations resulting
|
||||
from the funding.
|
||||
|
||||
## Fair Use
|
||||
|
||||
You may have "fair use" rights for the software under the
|
||||
law. These terms do not limit them.
|
||||
|
||||
## No Other Rights
|
||||
|
||||
These terms do not allow you to sublicense or transfer any of
|
||||
your licenses to anyone else, or prevent the licensor from
|
||||
granting licenses to anyone else. These terms do not imply
|
||||
any other licenses.
|
||||
|
||||
## Patent Defense
|
||||
|
||||
If you make any written claim that the software infringes or
|
||||
contributes to infringement of any patent, your patent license
|
||||
for the software granted under these terms ends immediately. If
|
||||
your company makes such a claim, your patent license ends
|
||||
immediately for work on behalf of your company.
|
||||
|
||||
## Violations
|
||||
|
||||
The first time you are notified in writing that you have
|
||||
violated any of these terms, or done anything with the software
|
||||
not covered by your licenses, your licenses can nonetheless
|
||||
continue if you come into full compliance with these terms,
|
||||
and take practical steps to correct past violations, within
|
||||
32 days of receiving notice. Otherwise, all your licenses
|
||||
end immediately.
|
||||
|
||||
## No Liability
|
||||
|
||||
***As far as the law allows, the software comes as is, without
|
||||
any warranty or condition, and the licensor will not be liable
|
||||
to you for any damages arising out of these terms or the use
|
||||
or nature of the software, under any kind of legal claim.***
|
||||
|
||||
## Definitions
|
||||
|
||||
The **licensor** is the individual or entity offering these
|
||||
terms, and the **software** is the software the licensor makes
|
||||
available under these terms.
|
||||
|
||||
**You** refers to the individual or entity agreeing to these
|
||||
terms.
|
||||
|
||||
**Your company** is any legal entity, sole proprietorship,
|
||||
or other kind of organization that you work for, plus all
|
||||
organizations that have control over, are under the control of,
|
||||
or are under common control with that organization. **Control**
|
||||
means ownership of substantially all the assets of an entity,
|
||||
or the power to direct its management and policies by vote,
|
||||
contract, or otherwise. Control can be direct or indirect.
|
||||
|
||||
**Your licenses** are all the licenses granted to you for the
|
||||
software under these terms.
|
||||
|
||||
**Use** means anything you do with the software requiring one
|
||||
of your licenses.
|
||||
106
README.md
Normal file
106
README.md
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
# labctl
|
||||
|
||||
Monte un **lab réseau virtuel** à partir d'une topologie YAML : des VM QEMU/KVM reliées par des
|
||||
segments L2, des switchs qui font passerelle et NAT, FRR installé et configuré sur les nœuds qui
|
||||
le demandent, et une provision libre (scripts, fichiers, services à vérifier) pour installer ce
|
||||
que l'on veut tester. Le plan est **déterministe** : même fichier, mêmes adresses, MAC et ports.
|
||||
|
||||
`labctl` tourne sur tout hôte Linux avec KVM (virtualisation imbriquée si l'hôte est lui-même une
|
||||
VM). `scripts/lab-host.sh` loue et prépare un tel hôte à l'heure chez Scaleway (Elastic Metal) ;
|
||||
c'est un exemple de fournisseur, pas une dépendance.
|
||||
|
||||
## Installer
|
||||
|
||||
Depuis une release : télécharger `labctl_linux_amd64` (et `lab-host.sh` si besoin) **et vérifier**
|
||||
leur somme dans `SHA256SUMS`. Ou compiler :
|
||||
|
||||
```
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o labctl ./cmd/labctl
|
||||
```
|
||||
|
||||
Sur l'hôte : `qemu-system-x86_64`, `qemu-img`, `genisoimage`, `ssh-keygen`, et `/dev/kvm`.
|
||||
|
||||
## Commandes
|
||||
|
||||
```
|
||||
labctl plan <topologie.yml> valide et affiche le plan, sans rien lancer
|
||||
labctl render -key <clé.pub> <topologie.yml> <rép> écrit les arguments QEMU et les seeds cloud-init
|
||||
labctl up [-run rép] [-cache rép] [-timeout durée] <topologie.yml>
|
||||
labctl status | down | ssh <nœud> [commande] [-run rép]
|
||||
```
|
||||
|
||||
Par défaut : `-run ~/lab-run`, `-cache ~/.cache/labctl`, `-timeout 20m`. `up` télécharge et vérifie
|
||||
les images (`SHA512SUMS`), crée des disques neufs, démarre les nœuds (switchs d'abord), attend la
|
||||
fin de cloud-init puis vérifie les services de chaque nœud. Un fichier invalide est refusé avec
|
||||
toutes ses erreurs et un code de sortie 1.
|
||||
|
||||
## Topologie
|
||||
|
||||
Voir `examples/evpn-2hv/` : un switch, un route reflector et deux hôtes en EVPN.
|
||||
|
||||
- `images` : `url` et `sums` (HTTPS).
|
||||
- `segments` : `switch`, `cidr` IPv4 (/8 à /30), `mtu` (9000 par défaut). Nom ≤ 12 caractères.
|
||||
- `nodes` : `role` (`switch`, `rr` ou `host`), `image`, `cpus`, `memory` (Mio), `segments`,
|
||||
`addresses` (adresse fixée par segment). Champs facultatifs :
|
||||
- `secondary` — adresses supplémentaires hors du CIDR du segment ;
|
||||
- `loopback` — adresse sur une interface `dummy` `lo1` ;
|
||||
- `frr` — un `frr.conf` déposé tel quel ; FRR est installé au premier démarrage (`bgpd`, et
|
||||
`bfdd` sur `switch` et `rr`) ;
|
||||
- `provision` / `post_provision` — scripts exécutés **avant** / **après** FRR ;
|
||||
- `files` — `{<nom>: <chemin>}`, fichiers **ou répertoires** gravés dans un ISO propre au nœud et
|
||||
recopiés dans `/etc/lab/files/<nom>` avant les scripts (aucune limite de taille cloud-init) ;
|
||||
- `services` — unités systemd que `up` vérifie actives.
|
||||
|
||||
Les chemins sont relatifs au fichier de topologie. Les scripts reçoivent `LAB_NODE`,
|
||||
`LAB_UPLINK` (interface du premier segment, qui porte la route par défaut) et `LAB_FILES`.
|
||||
Ordre au premier démarrage : script du switch ou de la loopback, `provision`, FRR,
|
||||
`post_provision` — dans un seul script en `set -eu`, la première étape en échec met cloud-init en
|
||||
erreur.
|
||||
|
||||
Déduit de façon déterministe : passerelle d'un segment = première adresse (portée par le switch) ;
|
||||
adresses suivantes dans l'ordre de déclaration des nœuds ; MAC `02:4c:<nœud>:<nœud>:<segment>:<côté>` ;
|
||||
SSH d'administration sur `127.0.0.1:<2200 + rang>`. **Réordonner les nœuds change les adresses.**
|
||||
|
||||
## Hôte loué chez Scaleway : `scripts/lab-host.sh`
|
||||
|
||||
```
|
||||
lab-host.sh plan | up | status | ssh [cmd] | prepare | push <topologie> | down | session [cmd]
|
||||
```
|
||||
|
||||
`plan` et `status` sont gratuits ; `up` et `session` **créent un serveur facturé à l'heure**
|
||||
(chaque heure entamée est due). Toujours commencer par `plan`. `push` dépose `labctl` (compilé
|
||||
depuis ce dépôt, ou celui de `LABCTL_BIN`) et le répertoire de la topologie ; ensuite
|
||||
`lab-host.sh ssh './labctl up topology/<topologie>'`.
|
||||
|
||||
Prérequis : un projet Scaleway **dédié** (`down` supprime tous les serveurs portant le tag
|
||||
`labctl`), une clé d'API limitée à ce projet, des clés SSH publiques enregistrées dans le projet.
|
||||
Fichiers locaux : `~/.config/labctl/scaleway.env` (0600, `SCW_SECRET_KEY`,
|
||||
`SCW_DEFAULT_PROJECT_ID`), `~/.config/labctl/ssh/lab_ed25519` (clé dédiée facultative), état sous
|
||||
`~/.cache/labctl/`. Tout se surcharge par variable d'environnement (`lab-host.sh` sans argument).
|
||||
|
||||
Garanties : jamais d'offre mensuelle ni de frais de mise en service, pas de second serveur,
|
||||
suppression réessayée et vérifiée jusqu'au 404, échec signalé par `SERVEUR(S) DE LAB TOUJOURS
|
||||
FACTURÉ(S)`. Pas de garantie face à un `SIGKILL` ou une coupure du poste : en cas de doute,
|
||||
`status` puis `down`.
|
||||
|
||||
## Sécurité
|
||||
|
||||
- La clé secrète Scaleway n'apparaît ni dans les arguments de processus, ni dans les journaux, ni
|
||||
dans l'environnement de `ssh`. **Ne jamais lancer `lab-host.sh` sous `bash -x`.**
|
||||
- La clé SSH des VM est générée sur l'hôte et ne le quitte pas ; les VM n'écoutent qu'en boucle
|
||||
locale. Leurs clés d'hôte ne sont pas vérifiées (`known_hosts` jetable).
|
||||
- Les images sont vérifiées par `SHA512SUMS`, servi par la même origine : cela protège de la
|
||||
corruption, pas d'une origine compromise.
|
||||
|
||||
## Tests
|
||||
|
||||
```
|
||||
go test ./...
|
||||
bash scripts/lab-host_test.sh
|
||||
```
|
||||
|
||||
Sans réseau : `curl` et `ssh` sont remplacés par de faux clients (API Scaleway dans le pire cas).
|
||||
|
||||
## Licence
|
||||
|
||||
PolyForm Noncommercial 1.0.0 — voir `LICENSE`.
|
||||
|
|
@ -13,8 +13,8 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/machine"
|
||||
"git.g3e.fr/syonad/two/internal/lab/provision"
|
||||
"git.g3e.fr/syonad/labctl/internal/machine"
|
||||
"git.g3e.fr/syonad/labctl/internal/provision"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/provision"
|
||||
"git.g3e.fr/syonad/two/internal/lab/render"
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/provision"
|
||||
"git.g3e.fr/syonad/labctl/internal/render"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const usage = `usage: labctl <command> [options] <topology.yml> [dir]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestRun_UsageOnMissingArguments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRun_PlanOfTheShippedExampleTopology(t *testing.T) {
|
||||
code, stdout, stderr := runLab("plan", filepath.Join("..", "..", "test", "e2e", "topologies", "evpn-2hv.yml"))
|
||||
code, stdout, stderr := runLab("plan", filepath.Join("..", "..", "examples", "evpn-2hv", "topology.yml"))
|
||||
if code != 0 {
|
||||
t.Fatalf("code %d, stderr %s", code, stderr)
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ func TestRun_RenderWritesEveryNodeFiles(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
out := filepath.Join(dir, "run")
|
||||
code, stdout, stderr := runLab("render", "-key", key, filepath.Join("..", "..", "test", "e2e", "topologies", "evpn-2hv.yml"), out)
|
||||
code, stdout, stderr := runLab("render", "-key", key, filepath.Join("..", "..", "examples", "evpn-2hv", "topology.yml"), out)
|
||||
if code != 0 {
|
||||
t.Fatalf("code %d, stderr %s", code, stderr)
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ func TestRun_RenderWritesEveryNodeFiles(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRun_RenderRefusesMissingKeyFile(t *testing.T) {
|
||||
code, _, stderr := runLab("render", "-key", filepath.Join(t.TempDir(), "absent.pub"), filepath.Join("..", "..", "test", "e2e", "topologies", "evpn-2hv.yml"), t.TempDir())
|
||||
code, _, stderr := runLab("render", "-key", filepath.Join(t.TempDir(), "absent.pub"), filepath.Join("..", "..", "examples", "evpn-2hv", "topology.yml"), t.TempDir())
|
||||
if code != 1 || !strings.Contains(stderr, "absent.pub") {
|
||||
t.Errorf("code %d, stderr %q", code, stderr)
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ func savedLab(t *testing.T) string {
|
|||
if err := os.MkdirAll(run, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
example, err := os.ReadFile(filepath.Join("..", "..", "test", "e2e", "topologies", "evpn-2hv.yml"))
|
||||
example, err := os.ReadFile(filepath.Join("..", "..", "examples", "evpn-2hv", "topology.yml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -308,15 +308,15 @@ func TestRun_RenderShipsTheExampleFRRConfigs(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
out := filepath.Join(dir, "run")
|
||||
code, _, stderr := runLab("render", "-key", key, filepath.Join("..", "..", "test", "e2e", "topologies", "evpn-2hv.yml"), out)
|
||||
code, _, stderr := runLab("render", "-key", key, filepath.Join("..", "..", "examples", "evpn-2hv", "topology.yml"), out)
|
||||
if code != 0 {
|
||||
t.Fatalf("code %d, stderr %s", code, stderr)
|
||||
}
|
||||
for node, wants := range map[string][]string{
|
||||
"sw1": {"router bgp 65100"},
|
||||
"rr1": {"bgp listen range 192.168.14.0/24 peer-group fabric"},
|
||||
"hv1": {"hostname hv1"},
|
||||
"hv2": {"hostname hv2"},
|
||||
"hv1": {"hostname hv1", "neighbor 10.255.255.1 peer-group fabric"},
|
||||
"hv2": {"hostname hv2", "neighbor 10.255.255.1 peer-group fabric"},
|
||||
} {
|
||||
data, err := os.ReadFile(filepath.Join(out, node, "user-data"))
|
||||
if err != nil {
|
||||
|
|
@ -337,10 +337,13 @@ func TestRun_RenderShipsTheExampleFRRConfigs(t *testing.T) {
|
|||
t.Errorf("%s user-data does not mount its files", node)
|
||||
}
|
||||
}
|
||||
for _, agent := range []string{"two.yml", "bgp.yml"} {
|
||||
data, err := os.ReadFile(filepath.Join("..", "..", "test", "e2e", "topologies", "agent", agent))
|
||||
if err != nil || !strings.Contains(string(data), "route_reflectors: [10.255.255.1]") {
|
||||
t.Errorf("agent/%s = %q, %v", agent, data, err)
|
||||
for _, node := range []string{"hv1", "hv2"} {
|
||||
data, err := os.ReadFile(filepath.Join(out, node, "user-data"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(data), "LAB_NODE="+node+" LAB_UPLINK=underlay LAB_FILES=/etc/lab/files /usr/local/sbin/lab-node-provision") {
|
||||
t.Errorf("%s user-data does not run the example provision", node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
examples/evpn-2hv/frr/hv1.conf
Normal file
18
examples/evpn-2hv/frr/hv1.conf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
frr defaults traditional
|
||||
hostname hv1
|
||||
log syslog informational
|
||||
!
|
||||
router bgp 64600
|
||||
bgp router-id 192.168.14.11
|
||||
no bgp default ipv4-unicast
|
||||
neighbor fabric peer-group
|
||||
neighbor fabric remote-as 64600
|
||||
neighbor fabric update-source 192.168.14.11
|
||||
neighbor 10.255.255.1 peer-group fabric
|
||||
!
|
||||
address-family l2vpn evpn
|
||||
neighbor fabric activate
|
||||
advertise-all-vni
|
||||
exit-address-family
|
||||
exit
|
||||
!
|
||||
18
examples/evpn-2hv/frr/hv2.conf
Normal file
18
examples/evpn-2hv/frr/hv2.conf
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
frr defaults traditional
|
||||
hostname hv2
|
||||
log syslog informational
|
||||
!
|
||||
router bgp 64600
|
||||
bgp router-id 192.168.14.12
|
||||
no bgp default ipv4-unicast
|
||||
neighbor fabric peer-group
|
||||
neighbor fabric remote-as 64600
|
||||
neighbor fabric update-source 192.168.14.12
|
||||
neighbor 10.255.255.1 peer-group fabric
|
||||
!
|
||||
address-family l2vpn evpn
|
||||
neighbor fabric activate
|
||||
advertise-all-vni
|
||||
exit-address-family
|
||||
exit
|
||||
!
|
||||
43
examples/evpn-2hv/frr/rr1.conf
Normal file
43
examples/evpn-2hv/frr/rr1.conf
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
frr defaults traditional
|
||||
hostname rr1
|
||||
log syslog informational
|
||||
!
|
||||
ip prefix-list RR-LOOPBACK-OUT seq 10 permit 10.255.255.1/32
|
||||
!
|
||||
route-map NO-IN deny 999
|
||||
description deny
|
||||
exit
|
||||
!
|
||||
router bgp 65000
|
||||
no bgp default ipv4-unicast
|
||||
bgp router-id 10.255.255.1
|
||||
bgp cluster-id 10.255.255.1
|
||||
neighbor CLUSTER peer-group
|
||||
neighbor CLUSTER remote-as 65100
|
||||
neighbor CLUSTER bfd
|
||||
neighbor 169.254.0.1 peer-group CLUSTER
|
||||
neighbor 169.254.0.1 description router-1
|
||||
neighbor 169.254.0.2 peer-group CLUSTER
|
||||
neighbor 169.254.0.2 description router-2
|
||||
neighbor fabric peer-group
|
||||
neighbor fabric remote-as 64600
|
||||
neighbor fabric local-as 64600 no-prepend replace-as
|
||||
neighbor fabric capability extended-nexthop
|
||||
neighbor fabric update-source 10.255.255.1
|
||||
bgp listen range 192.168.14.0/24 peer-group fabric
|
||||
bgp listen limit 200
|
||||
!
|
||||
address-family ipv4 unicast
|
||||
network 10.255.255.1/32
|
||||
neighbor CLUSTER activate
|
||||
neighbor CLUSTER prefix-list RR-LOOPBACK-OUT out
|
||||
neighbor CLUSTER route-map NO-IN in
|
||||
exit-address-family
|
||||
!
|
||||
address-family l2vpn evpn
|
||||
neighbor fabric activate
|
||||
neighbor fabric route-reflector-client
|
||||
exit-address-family
|
||||
!
|
||||
exit
|
||||
!
|
||||
28
examples/evpn-2hv/frr/sw1.conf
Normal file
28
examples/evpn-2hv/frr/sw1.conf
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
frr defaults traditional
|
||||
hostname sw1
|
||||
log syslog informational
|
||||
!
|
||||
ip prefix-list RR-LOOPBACK-IN seq 10 permit 10.255.255.1/32
|
||||
!
|
||||
route-map RR-IN permit 10
|
||||
match ip address prefix-list RR-LOOPBACK-IN
|
||||
exit
|
||||
!
|
||||
route-map NO-OUT deny 999
|
||||
exit
|
||||
!
|
||||
router bgp 65100
|
||||
no bgp default ipv4-unicast
|
||||
bgp router-id 169.254.0.1
|
||||
neighbor 169.254.0.3 remote-as 65000
|
||||
neighbor 169.254.0.3 description rr1
|
||||
neighbor 169.254.0.3 bfd
|
||||
!
|
||||
address-family ipv4 unicast
|
||||
neighbor 169.254.0.3 activate
|
||||
neighbor 169.254.0.3 route-map RR-IN in
|
||||
neighbor 169.254.0.3 route-map NO-OUT out
|
||||
exit-address-family
|
||||
!
|
||||
exit
|
||||
!
|
||||
1
examples/evpn-2hv/motd
Normal file
1
examples/evpn-2hv/motd
Normal file
|
|
@ -0,0 +1 @@
|
|||
labctl example host
|
||||
4
examples/evpn-2hv/provision/host.sh
Executable file
4
examples/evpn-2hv/provision/host.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
install -m 0644 "${LAB_FILES}/motd" /etc/motd
|
||||
echo "${LAB_NODE}: uplink ${LAB_UPLINK}" >> /etc/motd
|
||||
29
examples/evpn-2hv/topology.yml
Normal file
29
examples/evpn-2hv/topology.yml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
name: evpn-2hv
|
||||
|
||||
images:
|
||||
debian12:
|
||||
url: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
|
||||
sums: https://cloud.debian.org/images/cloud/bookworm/latest/SHA512SUMS
|
||||
|
||||
segments:
|
||||
underlay:
|
||||
switch: sw1
|
||||
cidr: 192.168.14.0/24
|
||||
mtu: 9000
|
||||
|
||||
nodes:
|
||||
sw1:
|
||||
{ role: switch, image: debian12, cpus: 2, memory: 1024,
|
||||
secondary: { underlay: [169.254.0.1/28] }, frr: frr/sw1.conf }
|
||||
rr1:
|
||||
{ role: rr, image: debian12, cpus: 1, memory: 1024, segments: [underlay],
|
||||
addresses: { underlay: 192.168.14.2 }, secondary: { underlay: [169.254.0.3/28] },
|
||||
loopback: 10.255.255.1/32, frr: frr/rr1.conf }
|
||||
hv1:
|
||||
{ role: host, image: debian12, cpus: 2, memory: 2048, segments: [underlay],
|
||||
addresses: { underlay: 192.168.14.11 }, frr: frr/hv1.conf, provision: provision/host.sh,
|
||||
files: { motd: motd } }
|
||||
hv2:
|
||||
{ role: host, image: debian12, cpus: 2, memory: 2048, segments: [underlay],
|
||||
addresses: { underlay: 192.168.14.12 }, frr: frr/hv2.conf, provision: provision/host.sh,
|
||||
files: { motd: motd } }
|
||||
10
go.mod
Normal file
10
go.mod
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module git.g3e.fr/syonad/labctl
|
||||
|
||||
go 1.25.0
|
||||
|
||||
toolchain go1.25.14
|
||||
|
||||
require (
|
||||
go.yaml.in/yaml/v3 v3.0.4
|
||||
golang.org/x/sys v0.45.0
|
||||
)
|
||||
6
go.sum
Normal file
6
go.sum
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
|
@ -14,9 +14,9 @@ import (
|
|||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/provision"
|
||||
"git.g3e.fr/syonad/two/internal/lab/render"
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/provision"
|
||||
"git.g3e.fr/syonad/labctl/internal/render"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/provision"
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/provision"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O labctl"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const maxSumsSize = 1 << 20
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const imageName = "debian-12-generic-amd64.qcow2"
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/render"
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/render"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
"go.yaml.in/yaml/v3"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/render"
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/render"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const generatedKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O labctl"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const loopback = "127.0.0.1"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"go.yaml.in/yaml/v3"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const labKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFG/JMmjfko96WkJV8DiL6rip/H/q/R++y8s27Z+Cj6O lab-automation"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"go.yaml.in/yaml/v3"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/lab/topology"
|
||||
"git.g3e.fr/syonad/labctl/internal/topology"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ usage: ${0##*/} <commande> [arguments]
|
|||
environnement : SCW_SECRET_KEY et SCW_DEFAULT_PROJECT_ID (requis, à défaut lus dans ${CREDENTIALS_FILE},
|
||||
fichier en 0600, lignes CLÉ=valeur), LAB_ZONES (zones candidates, dans l'ordre :
|
||||
${ZONES} ; SCW_DEFAULT_ZONE passe en tête), LAB_OFFER (${OFFER_NAME}), LAB_OS_NAME (${OS_NAME}), LAB_OS_VERSION (${OS_VERSION}),
|
||||
LAB_SSH_KEY (${SSH_KEY} ; à défaut, l'agent SSH)
|
||||
LAB_SSH_KEY (${SSH_KEY} ; à défaut, l'agent SSH), LABCTL_BIN (binaire labctl linux/amd64
|
||||
envoyé par push au lieu de le compiler depuis le dépôt)
|
||||
|
||||
ne jamais lancer sous 'bash -x' : la trace afficherait SCW_SECRET_KEY.
|
||||
EOF
|
||||
|
|
@ -388,9 +389,15 @@ cmd_push () {
|
|||
[[ -f "${TOPOLOGY}" ]] || die "topologie introuvable : ${TOPOLOGY}"
|
||||
[[ "${NAME}" =~ ^[A-Za-z0-9._-]+$ ]] || die "nom de topologie refusé : ${NAME} (lettres, chiffres, '.', '_', '-')"
|
||||
require_known_server
|
||||
info "compilation de labctl (linux/amd64)"
|
||||
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "${BINARY}" ./cmd/labctl) \
|
||||
|| die "compilation de labctl échouée"
|
||||
if [[ -n "${LABCTL_BIN:-}" ]]; then
|
||||
[[ -f "${LABCTL_BIN}" && -x "${LABCTL_BIN}" ]] || die "LABCTL_BIN n'est pas un exécutable : ${LABCTL_BIN}"
|
||||
BINARY="${LABCTL_BIN}"
|
||||
info "labctl fourni : ${BINARY}"
|
||||
else
|
||||
info "compilation de labctl (linux/amd64)"
|
||||
(cd "${REPO_DIR}" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "${BINARY}" ./cmd/labctl) \
|
||||
|| die "compilation de labctl échouée"
|
||||
fi
|
||||
push_file "${BINARY}" labctl 755 || die "envoi de labctl échoué"
|
||||
push_dir "$(dirname "${TOPOLOGY}")" || die "envoi du répertoire de ${NAME} échoué"
|
||||
info "déposés sur le serveur : ~/labctl, ~/topology/ — ensuite : ${0##*/} ssh './labctl up topology/${NAME}'"
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ lab_env () {
|
|||
SCW_DEFAULT_PROJECT_ID="${PROJECT}" LAB_POLL_INTERVAL="${LAB_POLL_INTERVAL:-0}" \
|
||||
LAB_INSTALL_TIMEOUT="${LAB_INSTALL_TIMEOUT:-60}" LAB_DELETE_TIMEOUT="${LAB_DELETE_TIMEOUT:-60}" \
|
||||
LAB_SSH_TIMEOUT="${LAB_SSH_TIMEOUT:-60}" LAB_ZONES="${LAB_ZONES:-fr-par-1}" \
|
||||
LAB_OFFER="${LAB_OFFER:-EM-B212X-SSD}" ${SCW_DEFAULT_ZONE:+SCW_DEFAULT_ZONE="${SCW_DEFAULT_ZONE}"} \
|
||||
LAB_OFFER="${LAB_OFFER:-EM-B212X-SSD}" ${SCW_DEFAULT_ZONE:+SCW_DEFAULT_ZONE="${SCW_DEFAULT_ZONE}"} ${LABCTL_BIN:+LABCTL_BIN="${LABCTL_BIN}"} \
|
||||
"$@"
|
||||
}
|
||||
|
||||
|
|
@ -725,6 +725,31 @@ test_push_stops_when_the_build_fails () {
|
|||
teardown
|
||||
}
|
||||
|
||||
test_push_sends_a_provided_binary_without_building () {
|
||||
setup "push : LABCTL_BIN est envoyé tel quel, sans compilation"
|
||||
known_server
|
||||
printf 'name: x\n' > "${WORK}/x.yml"
|
||||
printf 'binaire-de-release' > "${WORK}/labctl-release"
|
||||
chmod 755 "${WORK}/labctl-release"
|
||||
LABCTL_BIN="${WORK}/labctl-release" run_lab push "${WORK}/x.yml" || fail "code de sortie $?"
|
||||
[[ -s "${WORK}/go.log" ]] && fail "compilation lancée : $(cat "${WORK}/go.log")"
|
||||
[[ $(cat "${WORK}/pushed.1") == "binaire-de-release" ]] || fail "contenu envoyé : $(cat "${WORK}/pushed.1")"
|
||||
teardown
|
||||
}
|
||||
|
||||
test_push_refuses_a_provided_binary_that_is_not_executable () {
|
||||
setup "push : LABCTL_BIN absent ou non exécutable refusé avant tout envoi"
|
||||
known_server
|
||||
printf 'name: x\n' > "${WORK}/x.yml"
|
||||
printf 'x' > "${WORK}/labctl-release"
|
||||
for BIN in "${WORK}/absent" "${WORK}/labctl-release"; do
|
||||
LABCTL_BIN="${BIN}" run_lab push "${WORK}/x.yml" && fail "push a réussi avec ${BIN}"
|
||||
grep -q "LABCTL_BIN n'est pas un exécutable" "${WORK}/out.log" || fail "message absent pour ${BIN}"
|
||||
done
|
||||
[[ -s "${WORK}/ssh.log" ]] && fail "ssh lancé"
|
||||
teardown
|
||||
}
|
||||
|
||||
test_push_fails_when_a_transfer_fails () {
|
||||
setup "push : un envoi échoué fait échouer push"
|
||||
known_server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue