Skip to content
Snippets Groups Projects
Commit ab59c9e2 authored by Mathias Chouet's avatar Mathias Chouet
Browse files

First attempt for #374 - auto deploy with Gitlab CI/CD

parent e0ef8d68
No related branches found
No related tags found
No related merge requests found
Pipeline #137785 failed
stages: stages:
- jalhyd
- install - install
- test - test
- build - build
- release-linux - deploy
- release-windows - deploy-stable
- release-mac - releases-nightly
- release-android - releases-version
variables: variables:
LC_ALL: C.UTF-8 LC_ALL: C.UTF-8
ANDROID_HOME: "/opt/android" ANDROID_HOME: "/opt/android"
ANDROID_SDK_ROOT: "/opt/android" ANDROID_SDK_ROOT: "/opt/android"
DEPLOY_HOST_LOGIN: "nghyd@aubes"
DEPLOY_URL: "/var/www/html/cassiopee"
DEPLOY_STABLE_URL: "/var/www/cassiopee-production"
RELEASES_URL: "$DEPLOY_STABLE_URL/cassiopee-releases"
cache: cache:
paths: paths:
- node_modules/ - node_modules/
jalhyd: jalhyd:
stage: jalhyd stage: install
only: only:
- pushes
- tags - tags
- schedules - schedules
- web - web
...@@ -34,9 +38,10 @@ jalhyd: ...@@ -34,9 +38,10 @@ jalhyd:
- npm install - npm install
- npm run build - npm run build
install: npm-install:
stage: install stage: install
only: only:
- pushes
- tags - tags
- schedules - schedules
- web - web
...@@ -44,15 +49,6 @@ install: ...@@ -44,15 +49,6 @@ install:
- rm -rf node_modules - rm -rf node_modules
- npm install - npm install
build:
stage: build
only:
- tags
- schedules
- web
script:
- npm run build
test: test:
stage: test stage: test
only: only:
...@@ -62,42 +58,54 @@ test: ...@@ -62,42 +58,54 @@ test:
script: script:
- npm run e2e - npm run e2e
release-linux: build:
stage: release-linux stage: build
only: only:
- pushes
- tags - tags
- schedules - schedules
- web - web
script: script:
- npm run release-linux - npm run build -- --base-href=/cassiopee/$CI_COMMIT_REF_NAME
- find release -name "fr.irstea.cassiopee_*.deb" -exec scp "{}" nghyd@aubes:/var/www/cassiopee-production/cassiopee-releases/linux-nightly.deb \;
release-windows: deploy:
stage: release-windows stage: deploy
only: only:
- pushes
- tags - tags
- schedules
- web - web
script: script:
- npm run release-windows # Copie de la branche / du tag
- find release -name "Cassio*Setup*.exe" -exec scp "{}" nghyd@aubes:/var/www/cassiopee-production/cassiopee-releases/windows-nightly.exe \; - rsync -a dist/ $DEPLOY_HOST_LOGIN:$DEPLOY_STABLE_URL/
release-mac: deploy-stable:
stage: release-mac stage: deploy-stable
only: only:
- tags - tags
variables:
- $CI_COMMIT_REF_NAME == "stable"
script:
# Copie de la branche production
- rsync -a dist/ $DEPLOY_HOST_LOGIN:$DEPLOY_STABLE_URL/
# Modification du dossier base href
- ssh $DEPLOY_HOST_LOGIN "sed -i 's:/cassiopee/stable/:/:g' $DEPLOY_STABLE_URL/index.html"
releases-nightly:
stage: releases-nightly
only:
- schedules - schedules
- web
script: script:
- npm run release-mac - npm run release-all
- find release -name "Cassio*-mac.zip" -exec scp "{}" nghyd@aubes:/var/www/cassiopee-production/cassiopee-releases/macos-nightly.zip \; - find release -name "fr.irstea.cassiopee_*.deb" -exec scp "{}" $DEPLOY_HOST_LOGIN:$RELEASES_URL/linux-nightly.deb \;
- find release -name "Cassio*Setup*.exe" -exec scp "{}" $DEPLOY_HOST_LOGIN:$RELEASES_URL/windows-nightly.exe \;
- find release -name "Cassio*-mac.zip" -exec scp "{}" $DEPLOY_HOST_LOGIN:$RELEASES_URL/macos-nightly.zip \;
- find release -name "cassiopee-*.apk" -exec scp "{}" $DEPLOY_HOST_LOGIN:$RELEASES_URL/android-nightly.apk \;
release-android: releases-version:
stage: release-android stage: releases-version
only: only:
- tags - tags
- schedules variables:
- web - $CI_COMMIT_REF_NAME =~ /^[0-9]+\.[0-9]+\.[0-9]+$/ # version tag
script: script:
- npm run release-android - nodejs scripts/release-version.sh $CI_COMMIT_REF_NAME $DEPLOY_HOST_LOGIN $RELEASES_URL
- find release -name "cassiopee-*.apk" -exec scp "{}" nghyd@aubes:/var/www/cassiopee-production/cassiopee-releases/android-nightly.apk \;
#!/bin/bash
# Fabrique les exécutables electron/cordova pour une version de Cassiopée $1, les
# distribue sur le serveur $2 dans le dossier $3, et met à jour le fichier releases.json
if [ "$#" -lt 3 ]; then
echo "usage: $0 X.Y.Z login@server /var/www/releases_dir"
exit 1
fi
VERSION="$1"
HOST_LOGIN="$2"
RELEASES_DIR="$3"
# RELEASES_DIR="/tmp/cassiopee-releases" # debug
RELEASES_FILE="$RELEASES_DIR/releases.json"
TMP_RELEASES_FILE="tmp-releases.json"
echo "deploy-version.sh: building release for version $VERSION, deploying in $HOST_LOGIN:$RELEASES_DIR"
# build releases
npm run release-all
# update existing releases file
# fetch current releases file
scp "$HOST_LOGIN:$RELEASES_FILE" "./$TMP_RELEASES_FILE"
grep -P "\"latest\": \"$VERSION\"" "$TMP_RELEASES_FILE"
if [[ $? == 0 ]]
then
echo "$VERSION est déjà la version la plus récente, pas de mise à jour du fichier releases.json"
else
sed -i -E "s/\"latest\": .+,/\"latest\": \"$VERSION\",/" "$TMP_RELEASES_FILE"
echo -e "\t\"$VERSION\": {
\t\t\"darwin\": \"Cassiopée-${VERSION}-mac.zip\",
\t\t\"linux\": \"fr.irstea.cassiopee_${VERSION}_amd64.deb\",
\t\t\"win32\": \"Cassiopée Setup $VERSION.exe\",
\t\t\"android\": \"cassiopee-$VERSION.apk\"
\t}," > releases_patch.tmp
sed -i "/\"latest\": \"$VERSION\",/r releases_patch.tmp" "$TMP_RELEASES_FILE"
rm releases_patch.tmp
fi
# send updated file, remove local copy
scp "./$TMP_RELEASES_FILE" "$HOST_LOGIN:$RELEASES_FILE"
rm "./$TMP_RELEASES_FILE"
# copy releases to public web directory
scp "release/Cassiopée Setup $VERSION.exe" "release/fr.irstea.cassiopee_${VERSION}_amd64.deb" "release/cassiopee-$VERSION.apk" "release/Cassiopée-${VERSION}-mac.zip" "$HOST_LOGIN:$RELEASES_DIR/"
# symlink "latest" version for each platform
ssh $HOST_LOGIN /bin/bash << "EOF"
cd "$RELEASES_DIR"
ln -sf "Cassiopée Setup $VERSION.exe" "windows-latest.exe"
ln -sf "fr.irstea.cassiopee_${VERSION}_amd64.deb" "linux-latest.deb"
ln -sf "Cassiopée-${VERSION}-mac.zip" "macos-latest.zip"
ln -sf "cassiopee-$VERSION.apk" "android-latest.apk"
EOF
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment