Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| web:framework:spring:deployment [2023/12/04 15:55] – [Configurations] jcheron | web:framework:spring:deployment [2023/12/17 17:41] (Version actuelle) – [Configuration Tomcat sur VM] jcheron | ||
|---|---|---|---|
| Ligne 275: | Ligne 275: | ||
| spring.h2.console.settings.web-allow-others=true | spring.h2.console.settings.web-allow-others=true | ||
| spring.h2.console.path=/ | spring.h2.console.path=/ | ||
| + | |||
| + | servlet.context.path=/ | ||
| + | |||
| </ | </ | ||
| Ligne 283: | Ligne 286: | ||
| spring.jpa.show-sql=true | spring.jpa.show-sql=true | ||
| spring.jpa.properties.hibernate.format_sql=true | spring.jpa.properties.hibernate.format_sql=true | ||
| - | |||
| - | servlet.context.path=/ | ||
| </ | </ | ||
| Ligne 297: | Ligne 298: | ||
| <sxh bash; | <sxh bash; | ||
| - | spring.datasource.url=jdbc: | + | spring.datasource.url=jdbc: |
| spring.jpa.show-sql=false | spring.jpa.show-sql=false | ||
| spring.jpa.properties.hibernate.format_sql=false | spring.jpa.properties.hibernate.format_sql=false | ||
| - | server.servlet.context-path=/ | ||
| </ | </ | ||
| Ligne 327: | Ligne 327: | ||
| script: "mvn --batch-mode --update-snapshots verify -P test -DskipTests=false" | script: "mvn --batch-mode --update-snapshots verify -P test -DskipTests=false" | ||
| </ | </ | ||
| + | |||
| + | ===== Déploiement avec variables ===== | ||
| + | Il est parfois indispensable, | ||
| + | * Mots de passe (BDD) | ||
| + | * Clé de sécurité (Chiffrement) | ||
| + | |||
| + | ==== Configuration Tomcat sur VM ==== | ||
| + | Il est nécessaire de modifier le service de démarrage de tomcat pour qu'il prenne en compte les variables d' | ||
| + | |||
| + | <sxh bash> | ||
| + | |||
| + | [Unit] | ||
| + | Description=Tomcat | ||
| + | After=network.target | ||
| + | |||
| + | [Service] | ||
| + | Type=simple | ||
| + | |||
| + | User=tomcat | ||
| + | Group=tomcat | ||
| + | |||
| + | Environment=" | ||
| + | Environment=" | ||
| + | Environment=" | ||
| + | Environment=" | ||
| + | Environment=" | ||
| + | Environment=" | ||
| + | |||
| + | ExecStart=/ | ||
| + | ExecStop=/ | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | |||
| + | </ | ||
| + | |||
| + | Recharger le service et redémarer le : | ||
| + | <sxh bash; | ||
| + | systemctl daemon-reload | ||
| + | systemctl start tomcat.service | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ==== Script de déploiement ==== | ||
| + | Créer une variable **CI_APP_KEY** dans les variables CI de votre compte gitlab. | ||
| + | |||
| + | Le script de déploiement doit maintenant ajouter la variable d' | ||
| + | |||
| + | <sxh yml; | ||
| + | stages: | ||
| + | - build | ||
| + | - deploy | ||
| + | |||
| + | maven-build: | ||
| + | image: maven: | ||
| + | stage: build | ||
| + | script: "mvn clean package -P prod -DskipTests=true" | ||
| + | artifacts: | ||
| + | paths: | ||
| + | - target/ | ||
| + | |||
| + | deploy-master: | ||
| + | variables: | ||
| + | HOST: " | ||
| + | PORT: " | ||
| + | USER: " | ||
| + | WAR: " | ||
| + | SITE_LOCATION: | ||
| + | rules: | ||
| + | - if: ' | ||
| + | before_script: | ||
| + | - apt-get update -qq && apt-get install -y -qq sshpass sudo | ||
| + | - echo "Host= $HOST" | ||
| + | stage: deploy | ||
| + | script: | ||
| + | - sudo whoami | ||
| + | - which mv | ||
| + | - sshpass -V | ||
| + | - export SSHPASS=$CI_USER_PASS | ||
| + | - sshpass -e scp -o StrictHostKeyChecking=no -P $PORT target/$WAR $USER@$HOST:/ | ||
| + | - sshpass -e ssh -tt -o StrictHostKeyChecking=no -p $PORT $USER@$HOST echo $PATH | ||
| + | - sshpass -e ssh -tt -o StrictHostKeyChecking=no -p $PORT $USER@$HOST sudo mv / | ||
| + | - sshpass -e ssh -tt -o StrictHostKeyChecking=no -p $PORT $USER@$HOST "sudo chmod 755 / | ||
| + | - sshpass -e ssh -tt -o StrictHostKeyChecking=no -p $PORT $USER@$HOST "sudo sh -c 'echo export CI_APP_KEY=$CI_APP_KEY >> / | ||
| + | - sshpass -e ssh -tt -o StrictHostKeyChecking=no -p $PORT $USER@$HOST sudo systemctl restart tomcat.service | ||
| + | </ | ||
| + | |||
| + | ==== Utilisation de variable d' | ||
| + | Pour utiliser la variable d' | ||
| + | |||
| + | === application.properties === | ||
| + | Ajouter la ligne suivante à **application.properties** : | ||
| + | <sxh ini; | ||
| + | spring.data.encryption.key=${CI_APP_KEY} | ||
| + | </ | ||
| + | |||
| + | === Utilisation en java === | ||
| + | Dans un contrôleur, | ||
| + | <sxh java ;classe java; | ||
| + | @Value(" | ||
| + | private String KEY; | ||
| + | </ | ||
| + | |||