This commit is contained in:
165
.woodpecker/build-pipeline.yml
Normal file
165
.woodpecker/build-pipeline.yml
Normal file
@@ -0,0 +1,165 @@
|
||||
when:
|
||||
- event: push
|
||||
branch: [ main ] # ← Les tags ne sont sur aucune "branch"
|
||||
- event: pull_request
|
||||
- event: manual
|
||||
|
||||
variables:
|
||||
- &node_image node:18-alpine
|
||||
- &git_image alpine/git
|
||||
|
||||
steps:
|
||||
# Étape 1: Nettoyage du projet, à ajuster
|
||||
- name: clean_project
|
||||
image: *git_image
|
||||
commands: |
|
||||
rm -rf dist
|
||||
rm -f version.env
|
||||
|
||||
- name: prepare
|
||||
image: *git_image
|
||||
commands: |
|
||||
# Récupérer le message du commit
|
||||
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||||
echo "📝 Message: $COMMIT_MSG"
|
||||
|
||||
# Déterminer le type de version
|
||||
if echo "$COMMIT_MSG" | grep -qE "^(major)(\(.*\))?!:"; then
|
||||
echo "version_type=major" >> version.env
|
||||
echo "🔴 MAJOR - Breaking change"
|
||||
elif echo "$COMMIT_MSG" | grep -qE "^(minor)(\(.*\))?:"; then
|
||||
echo "version_type=minor" >> version.env
|
||||
echo "🟡 MINOR - Nouvelle fonctionnalité"
|
||||
elif echo "$COMMIT_MSG" | grep -qE "^(patch)(\(.*\))?:"; then
|
||||
echo "version_type=patch" >> version.env
|
||||
echo "🟢 PATCH - Correction"
|
||||
else
|
||||
echo "version_type=none" >> version.env
|
||||
echo "⚠️ Aucun changement de version"
|
||||
fi
|
||||
npm ci --cache .npm --prefer-offline
|
||||
depends_on: [ clean_project ]
|
||||
|
||||
# Étape 4: Mettre à jour la version (seulement si nécessaire)
|
||||
- name: update_version
|
||||
image: *node_image
|
||||
commands: |
|
||||
source version.env
|
||||
if [ "$version_type" != "none" ]; then
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "📦 Version actuelle: $CURRENT_VERSION"
|
||||
npm run update:$version_type
|
||||
NEW_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "🆕 Nouvelle version: $NEW_VERSION"
|
||||
echo "NEW_VERSION=$NEW_VERSION" >> version.env
|
||||
echo "CURRENT_VERSION=$CURRENT_VERSION" >> version.env
|
||||
echo "artifact=${CI_REPO_NAME}-$NEW_VERSION.tar" >> version.env
|
||||
else
|
||||
echo "artifact=no-artifact" >> version.env
|
||||
echo "⏭️ Pas de mise à jour de version"
|
||||
fi
|
||||
depends_on: [ build ]
|
||||
|
||||
# Étape 1: Installation des dépendances
|
||||
- name: build
|
||||
image: *node_image
|
||||
commands:
|
||||
- npm run build
|
||||
depends_on: [ prepare ]
|
||||
|
||||
# Étape 5: Commit et tag
|
||||
- name: commit_tag
|
||||
image: *git_image
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: gitea_token
|
||||
commands: |
|
||||
# Charger les variables
|
||||
more version.env
|
||||
source version.env
|
||||
echo "version type: $version_type"
|
||||
|
||||
if [ "$version_type" != "none" ]; then
|
||||
echo "http://oauth2:$GITEA_TOKEN@gitea.cicd.exygen.fr/${CI_REPO_OWNER}/${CI_REPO_NAME}.git"
|
||||
git remote set-url origin http://oauth2:$GITEA_TOKEN@gitea.cicd.exygen.fr/${CI_REPO_OWNER}/${CI_REPO_NAME}.git
|
||||
git config user.email "woodpecker@exygen.fr"
|
||||
git config user.name "Woodpecker CI"
|
||||
|
||||
# Ajouter le remote avec token
|
||||
|
||||
# Ajouter le package.json modifié
|
||||
git add package.json
|
||||
git add ./database/src/sql/*.sql
|
||||
|
||||
# Vérifier s'il y a des changements
|
||||
# if ! git diff --cached --quiet; then
|
||||
# Commiter la nouvelle version
|
||||
git commit -m "Pipeline: update current version v$NEW_VERSION [skip ci]"
|
||||
git push origin main
|
||||
echo "✅ Commit new version"
|
||||
|
||||
# Créer le tag
|
||||
git tag -a "v$NEW_VERSION" -m "Release version v$NEW_VERSION"
|
||||
git push origin "v$NEW_VERSION"
|
||||
echo "🏷️ Tag v$NEW_VERSION created and pushed"
|
||||
else
|
||||
echo "⚠️ Aucun changement à commiter"
|
||||
fi
|
||||
depends_on: [ publish ]
|
||||
|
||||
# Étape 6: Package des artefacts
|
||||
- name: package
|
||||
image: *node_image
|
||||
commands: |
|
||||
more version.env
|
||||
source version.env
|
||||
if [ "$version_type" != "none" ]; then
|
||||
WDIR=/tmp/artifacts/$NEW_VERSION
|
||||
echo "create work directory: $WDIR"
|
||||
mkdir -p $WDIR
|
||||
echo "create front artifact: $WDIR/front.tar.gz"
|
||||
tar -czf $WDIR/front.tar.gz -C frontend/dist .
|
||||
echo "create back artifact: $WDIR/back.tar.gz"
|
||||
tar -czf $WDIR/back.tar.gz -C backend/dist .
|
||||
echo "create db artifact: $WDIR/db.tar.gz"
|
||||
tar -czf $WDIR/db.tar.gz -C database src *.json
|
||||
echo "create final artifact: /tmp/artifacts/$artifact"
|
||||
ls -als /tmp/artifacts/$artifact
|
||||
tar -cf /tmp/artifacts/$artifact -C $WDIR .
|
||||
fi
|
||||
ls -als /tmp/artifacts/
|
||||
depends_on: [ build ]
|
||||
|
||||
- name: publish
|
||||
image: curlimages/curl:latest
|
||||
environment:
|
||||
NEXUS_USERNAME:
|
||||
from_secret: nexus_username
|
||||
NEXUS_PASSWORD:
|
||||
from_secret: nexus_password
|
||||
commands: |
|
||||
source version.env
|
||||
echo "📦 Publication de la version $NEW_VERSION : $artifact"
|
||||
ls -als /tmp/artifacts/$artifact
|
||||
|
||||
curl -v \
|
||||
-u ${NEXUS_USERNAME}:${NEXUS_PASSWORD} \
|
||||
-F "raw.directory=apps/${CI_REPO_NAME}/${NEW_VERSION}" \
|
||||
-F "raw.asset1=@/tmp/artifacts/$artifact" \
|
||||
-F "raw.asset1.filename=$artifact" \
|
||||
https://nexus.cicd.exygen.fr/service/rest/v1/components?repository=domaine-passignat
|
||||
depends_on: [ package ]
|
||||
|
||||
- name: trigger-deployment
|
||||
image: woodpeckerci/plugin-trigger:latest
|
||||
settings:
|
||||
token:
|
||||
from_secret: woodpecker_token
|
||||
server: https://woodpecker.cicd.exygen.fr # ← Ajoute l'URL du serveur
|
||||
repo: ${CI_REPO_OWNER}/${CI_REPO_NAME}
|
||||
branch: main
|
||||
event: deployment
|
||||
deploy_id: ${CI_PIPELINE_NUMBER} # ← Peut être optionnel
|
||||
deploy_to: production # ← Renommé en "environment" parfois
|
||||
wait: true # ← Attend la fin du déploiement
|
||||
depends_on: [ publish ]
|
||||
64
.woodpecker/deploy-pipeline.yml
Normal file
64
.woodpecker/deploy-pipeline.yml
Normal file
@@ -0,0 +1,64 @@
|
||||
# Documentation: https://woodpecker-ci.org/docs/usage/workflow-syntax
|
||||
|
||||
when:
|
||||
- event: deployment
|
||||
|
||||
steps:
|
||||
- name: get-artifact
|
||||
image: curlimages/curl:latest
|
||||
commands: |
|
||||
VERSION=${CI_COMMIT_TAG#v}
|
||||
curl -o /tmp/${CI_REPO_NAME}-${VERSION}.tar \
|
||||
"https://nexus.cicd.exygen.fr/repository/domaine-passignat/apps/${CI_REPO_NAME}/${VERSION}/${CI_REPO_NAME}-${VERSION}.tar"
|
||||
|
||||
# Étape 7: Transfert vers le serveur distant (SCP)
|
||||
- name: transfert
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host:
|
||||
from_secret: remote_host
|
||||
username:
|
||||
from_secret: remote_user
|
||||
password:
|
||||
from_secret: remote_password
|
||||
port: 22
|
||||
source: /tmp/${CI_REPO_NAME}-${VERSION}.tar
|
||||
target: /tmp/
|
||||
depends_on: [ get-artifact ]
|
||||
|
||||
# Étape 8: Déploiement sur le serveur distant
|
||||
- name: deploy
|
||||
image: appleboy/drone-ssh
|
||||
environment:
|
||||
SUDO_PASSWORD:
|
||||
from_secret: remote_password
|
||||
settings:
|
||||
host:
|
||||
from_secret: remote_host
|
||||
username:
|
||||
from_secret: remote_user
|
||||
password:
|
||||
from_secret: remote_password
|
||||
port: 22
|
||||
envs:
|
||||
- SUDO_PASSWORD
|
||||
script:
|
||||
- echo "$${SUDO_PASSWORD}" | sudo -S systemctl stop gestion
|
||||
- mkdir -p /srv/volumes/gestion/{front-binaries,back-binaries,tmpdb}
|
||||
- rm -rf /srv/volumes/gestion/front-binaries/*
|
||||
- rm -rf /srv/volumes/gestion/back-binaries/*
|
||||
- rm -rf /srv/volumes/gestion/tmpdb/*
|
||||
- tar -xvf /tmp/${CI_REPO_NAME}-${VERSION}.tar -C /tmp
|
||||
- tar -xvf /tmp/front.tar.gz -C /srv/volumes/gestion/front-binaries
|
||||
- tar -xzvf /tmp/back.tar.gz -C /srv/volumes/gestion/back-binaries
|
||||
- tar -xzvf /tmp/db.tar.gz -C /srv/volumes/gestion/tmpdb
|
||||
- rm -f /tmp/front.tar.gz
|
||||
- rm -f /tmp/back.tar.gz
|
||||
- rm -f /tmp/db.tar.gz
|
||||
- rm -f /tmp/${CI_REPO_NAME}-${VERSION}.tar
|
||||
- docker-compose up database
|
||||
- cd /srv/volumes/gestion/tmpdb
|
||||
- npm ci --cache .npm --prefer-offline
|
||||
- npm run install-db
|
||||
- echo "$${SUDO_PASSWORD}" | sudo -S systemctl start gestion
|
||||
depends_on: [ transfert ]
|
||||
Reference in New Issue
Block a user