Artisan Développeur

Qualité, amélioration continue, agilité.

Erreur avec le repository de Jenkins sous Debian

Aujourd’hui en voulant faire mes mises à jour, j’ai cette erreur:

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://pkg.jenkins-ci.org/debian binary/ Release: Les signatures suivantes n’ont pas pu être vérifiées car la clé publique n’est pas disponible : NO_PUBKEY FCEF32E745F2C3D5
W: Impossible de récupérer http://pkg.jenkins-ci.org/debian/binary/Release.gpg Les signatures suivantes n’ont pas pu être vérifiées car la clé publique n’est pas disponible : NO_PUBKEY FCEF32E745F2C3D5
W: Le téléchargement de quelques fichiers d’index a échoué, ils ont été ignorés, ou les anciens ont été utilisés à la place.

Sur le site de Jenkins, on voit qu’ils ont l’air de mettre en avant l’installation via docker https://www.jenkins.io/doc/book/installing/

Mais pour l’instant je préfère rester comme je suis, j’ai prévu de tester Gitlab et sa CI et je vais probablement arrêter Jenkins qui est 10 X trop complet pour mes petits besoins.

Cette clef existe puisque l’url est accessible http://pkg.jenkins-ci.org/debian/binary/Release.gpg mais sur la page d’installation officielle, l’url de la clef est:

https://pkg.jenkins.io/debian-stable/jenkins.io.key

Et dans le fichier /etc/apt/sources.list.d/pkg_jenkins_ci_org_debian.list on a:

deb http://pkg.jenkins-ci.org/debian binary/

Au lieu de :

deb https://pkg.jenkins.io/debian-stable binary/

Donc, ils suffit de faire la mise à jour du repository, et d’ajouter la nouvelle clef, mais avant c’est mieux de vérifier si il reste quelque chose à nettoyer, bien que logiquement la clef public n’est pas disponible (puisque c’est l’erreur en question – c’est à faire en root).

  1. Vérifier la liste des clefs
  2. Vérifier si celle de Jenkins est toujours là (normalement non)
  3. La supprimer si elle est présente
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key list | grep  "jenkins"

Note: apt-key lance un warning pour éviter les utilisations potentiellement dangereuse, et c’est tant mieux ! Dans notre cas comme c’est juste ponctuel, on peut passer outre, mais attention, en partant je vous conseille un petit:

history -c

Qui va effacer l’historique de vos commandes, le petit côté parano++

Si la clef est présente toujours avec apt-key, vous la supprimez:

apt-key del "[UID_KEY]"

Il faut aussi supprimer le fichier source (ls -la /etc/apt/sources.list.d/ pour le trouver):

rm /etc/apt/sources.list.d/pkg_jenkins_ci_org_debian.list

Source pour les détails: https://askubuntu.com/questions/107177/how-can-i-remove-gpg-key-that-i-added-using-apt-key-add

Pour finir on suit la doc officielle de Jenkins:
https://www.jenkins.io/doc/book/installing/#debianubuntu
(note: pour moi ça n’est pas critique, c’est pour ma préprod, je prends la version « Weekly», je vous encourage à prendre la LTS si vous avez besoin de stabilité dans le temps – à faire en root ou avec sudo)

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | apt-key add -
 sh -c 'echo deb https://pkg.jenkins.io/debian binary/ > \
    /etc/apt/sources.list.d/jenkins.list'
apt update
apt install jenkins

Yapuka 🙂


Add choices to a Symfony formType with an event listener

If you want to add (or remove) choices from a ChoiceType in your formType, this is how to do it with an event listener.
The event you will subscribe depends on the data you have and your workflow.
I had to modify a formType to allow the edition of an entity with a particular value on one field.
The field is "mode".
"myParticularMode" is a mode not available by default, I use it only under certain conditions, the entity is programmatically created, and the user is redirected to the edit form to finish to fill the data.
I don't want to allow my users to use that mode om new I don't want to allow my users to use that mode on new entity, I need it only when I edit the entities defined with this "mode".

The code take the event "POST_SET_DATA", this way I have my data, and I know the mode.
If the "mode" is myParticularMode" I add it to the choices.

Add a choice to the choices:

$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
    // get the form from the event
    $form = $event->getForm();
    
    if ('myParticularMode' == $form->get('mode')->getData()) {
        // get the field options
        $options = $form->get('mode')->getConfig()->getOptions();
        // add the mode to the choices array
        $options['choices']['MY_PARTICULAR_MODE'] = 'myParticularMode_display_name';
        $form->add('mode', ChoiceType::class, $options);
    }
});

To replace all the choices and display only the one, don’t take the options, just override the choices array, and you can even disable it:

$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
    // get the form from the event
    $form = $event->getForm();
    
    if ('myParticularMode' == $form->get('mode')->getData()) {
        // add the mode to the choices array
        $options['choices']['MY_PARTICULAR_MODE'] = 'myParticularMode_display_name';
        // disable the field
        $options['disabled'] = true;
        $form->add('mode', ChoiceType::class, $options);
    }
});

Enjoy 🙂

Drupal 8 Vagrant, Ansible, Composer

Be ready to work on Drupal 8 fast !
I have searched for a simple VM to install Drupal 8 locally to dev, with composer installed. All the projects I have seen seems great but with to many options and possibilities.

My goal was to have, a virtual machine, with Debian 10 (Buster), php, apache and mariadb (default distribution version), composer, and a Drupal 8 installed with composer.

I did not find what I need, so I have tinkered something, it is not the coolest Ansible set you have seen, but it does the job 🙂

Don’t hesitate to raise issues, or contact me if you want, and if you find it useful, say hello !

https://github.com/nicolas-san/drupal_8_simple_dev_env