diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 98c0e6bebad707853d4ffe2a83dc573014c137ba..10fa6f8778fb12a6b2ac6d3dc8bf5f439c43944d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,7 @@ cache: stages: - install - check + - publish - deploy install-and-build: @@ -16,10 +17,6 @@ install-and-build: - npm install # INFO rebuild is needed when Node version changes - npm run build - artifacts: - paths: - # non indexed build - - .svelte-kit/output/* check-version: stage: check @@ -37,7 +34,7 @@ check-version: # create release in order to create tag (to bypass 'git tag' access rights configuration) release-and-tag: - stage: deploy + stage: publish # use release-cli to get release name from variable image: registry.gitlab.com/gitlab-org/release-cli:latest rules: @@ -51,3 +48,31 @@ release-and-tag: # create the tag when it doesn't exist - echo "Creating $TAG_NAME release (and tag)..." - release-cli create --name "$TAG_NAME" --description "$CI_JOB_STARTED_AT release" --tag-name "$TAG_NAME" --ref "$CI_COMMIT_SHA" --assets-link "{\"url\":\"https://$CI_REGISTRY_IMAGE/$TAG_NAME\",\"name\":\"Container Image \"}" + +# artifacts from all previous stages are passed by default +deploy-integ: + # SSH_PRIVATE_KEY and INTEGRATION_IP defined in: + # https://git.leximpact.dev/groups/leximpact/simulateur-dotations-communes/-/settings/ci_cd + # INTEGRATION_HOST_DOMAIN_NAME defined in: + # https://git.leximpact.dev/groups/leximpact/-/settings/ci_cd + stage: deploy + before_script: + # install git to have ssh-agent and ssh-add + - apt update + - apt-get install -y git curl + - eval $(ssh-agent -s) + - ssh-add <(echo "$SSH_PRIVATE_KEY") + # check that we are in a container (inside Proxmox LXC container) before bypassing StrictHostKeyChecking + - '[[ -f /.dockerenv ]] && mkdir -p ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\tLogLevel quiet\n" > ~/.ssh/config' + script: + # remove previous build on integration server + - ssh -J gitlabci@$INTEGRATION_HOST_DOMAIN_NAME leximpact@$INTEGRATION_IP "cd $CI_PROJECT_NAME && rm build/* && exit" + # get deploy.sh on container (on SSH port 22) + - ssh -J gitlabci@$INTEGRATION_HOST_DOMAIN_NAME leximpact@$INTEGRATION_IP "mkdir -p $CI_PROJECT_NAME/.gitlab/ci/ && exit" + - scp -o "ProxyCommand ssh gitlabci@$INTEGRATION_HOST_DOMAIN_NAME nc -w 1 %h 22" .gitlab/ci/deploy.sh leximpact@$INTEGRATION_IP:$CI_PROJECT_NAME/.gitlab/ci/deploy.sh + # use a ssh relay to connect to the host containing the runner and run deploy.sh + - ssh -J gitlabci@$INTEGRATION_HOST_DOMAIN_NAME leximpact@$INTEGRATION_IP "cd $CI_PROJECT_NAME && bash .gitlab/ci/deploy.sh && exit" + environment: + # defined in: https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-ui/-/environments + name: integration + when: manual diff --git a/.gitlab/ci/deploy.sh b/.gitlab/ci/deploy.sh new file mode 100644 index 0000000000000000000000000000000000000000..c24747d77359da22d7ec738f90a2244f992f5fde --- /dev/null +++ b/.gitlab/ci/deploy.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# USAGE: to be copied by the CI to the integration or production container and executed there + +# stop at first error +set -e + +echo "Stop all services..." +systemctl --user stop dotations-ui-integ.service + +# Later: remove dependencies before reinstall? +npm install +npm run build + +echo "Restart service..." +systemctl --user start dotations-ui-integ.service + +echo "Deployment done! 🎉" diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2fd6a634114f0d1394ce2ff8bb0554710b8a11..adc5ee9b885af771d850eb5650c1d3e6773a4ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +### 0.2.2 [!6](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-ui/-/merge_requests/6) + +- Amélioration technique. +- Détails : + - Ajoute à la CI le déploiement sur le serveur d'intégration + - Ajoute le script de déploiement `.gitlab/ci/deploy.sh` + - Déplace le job `release-and-tag` dans un stage dédié `publish` + - Ajoute le job `deploy-integ` au stage `deploy` + ### 0.2.1 [!3](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-ui/-/merge_requests/3) - Amélioration technique. diff --git a/package.json b/package.json index 08dc9c73d9630831e05865c72cc701217f286d52..e4275250a88ee4622d4fae794dc9b8ce8f65047f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leximpact-dotations-ui", - "version": "0.2.1", + "version": "0.2.2", "private": true, "scripts": { "dev": "vite dev",