diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0ff6f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*~ +Notes diff --git a/conf/config.xml b/conf/config.xml new file mode 100644 index 0000000..ffb6051 --- /dev/null +++ b/conf/config.xml @@ -0,0 +1,51 @@ + + + + 1.0 + 2 + NORMAL + true + + false + + + ldap://localhost:389/ + dc=yunohost,dc=org + false + + uid={0} + + + + + false + displayname + mail + + + + false + + ${ITEM_ROOTDIR}/workspace + ${ITEM_ROOTDIR}/builds + + + + + + 0 + + + + Tous + false + false + + + + Tous + 0 + + + + diff --git a/conf/nginx.conf b/conf/nginx.conf index 86f9cdc..536b53e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,27 +1,31 @@ -location YNH_LOCATION { - proxy_pass http://127.0.0.1:YNH_PORT; +location __PATH__ { + proxy_pass http://127.0.0.1:__PORT__; + proxy_redirect http://127.0.0.1:__PORT__ https://__DOMAIN____PATH__; - proxy_redirect off; - - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_set_header X-NginX-Proxy true; - proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-NginX-Proxy true; + proxy_set_header X-Forwarded-User $remote_user; - proxy_max_temp_file_size 0; + sendfile off; - client_max_body_size 10m; - client_body_buffer_size 128k; + proxy_max_temp_file_size 0; - proxy_connect_timeout 4m; - proxy_send_timeout 4m; - proxy_read_timeout 4m; + client_max_body_size 10m; + client_body_buffer_size 128k; - proxy_buffer_size 4k; - proxy_buffers 4 32k; - proxy_busy_buffers_size 64k; - proxy_temp_file_write_size 64k; + proxy_connect_timeout 90; + proxy_send_timeout 90; + proxy_read_timeout 90; - sendfile off; + proxy_buffer_size 4k; + proxy_buffers 4 32k; + proxy_busy_buffers_size 64k; + proxy_temp_file_write_size 64k; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } + diff --git a/manifest.json b/manifest.json index 73dd1ec..ced404d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,16 @@ { "name": "Jenkins", "id": "jenkins", + "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Serveur d'intégration continue extensible", "fr": "Extendable continuous integration server" }, - "developer": { + "license": "free", + "maintainer": { "name": "Julien Malik", "email": "julien.malik@paraiso.me" }, @@ -18,7 +23,8 @@ "en": "Choose a domain for Jenkins", "fr": "Choisissez un domaine pour Jenkins" }, - "example": "domain.org" + "example": "domain.org", + "default": "sous.crudelis-test4.fr" }, { "name": "path", @@ -27,7 +33,7 @@ "fr": "Choisissez un path pour Jenkins" }, "example": "/jenkins", - "default": "/jenkins" + "default": "/" }, { "name": "is_public", diff --git a/scripts/install b/scripts/install index c1fab09..03a789a 100644 --- a/scripts/install +++ b/scripts/install @@ -5,6 +5,7 @@ domain=$1 path=$2 is_public=$3 port=$4 +app=jenkins sudo yunohost app checkport $port if [[ ! $? -eq 0 ]]; then @@ -19,11 +20,8 @@ if [[ ! $? -eq 0 ]]; then fi echo "Install dependencies..." -wget -q -O - "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key" | sudo apt-key add - -sudo bash -c "cat > /etc/apt/sources.list.d/jenkins.list << EOF -deb http://pkg.jenkins-ci.org/debian binary/ -EOF -" +wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - +sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins -y @@ -31,17 +29,24 @@ sudo apt-get install jenkins -y if [[ "$path" != "/" ]]; then # $ means 'process only the last line' - sudo sed -i '$ s@--ajp13Port=$AJP_PORT@--ajp13Port=$AJP_PORT --prefix=$PREFIX@g' /etc/default/jenkins + sudo sed -i '$ s@--httpPort=$HTTP_PORT"@--httpPort=$HTTP_PORT" --prefix=$PREFIX@g' /etc/default/jenkins fi sudo sed -i "s/HTTP_PORT=.*/HTTP_PORT=$port/g" /etc/default/jenkins -sudo service jenkins restart +sudo sed -i "s/-Djava.awt.headless=true/& -Djenkins.install.runSetupWizard=false/g" /etc/default/jenkins + +sudo service $app restart # Redémarre jenkins +tempfile="$(mktemp)" +tail -f -n1 /var/log/$app/$app.log > "$tempfile" & # Suit le démarrage dans le log +PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan. sudo yunohost service add jenkins -l /var/log/jenkins/jenkins.log echo "Nginx configuration (sso disabled)..." -sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf -sed -i "s@YNH_PORT@$port@g" ../conf/nginx.conf +sed -i "s@__PATH__@$path@g" ../conf/nginx.conf +sed -i "s@__PORT__@$port@g" ../conf/nginx.conf +sed -i "s@__DOMAIN__@$domain@g" ../conf/nginx.conf + sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jenkins.conf sudo yunohost app setting jenkins is_public -v $is_public @@ -50,8 +55,41 @@ then sudo yunohost app setting jenkins unprotected_uris -v "/" fi -# restart 2 times for debug -sudo service jenkins restart - sudo service nginx reload sudo yunohost app ssowatconf + +# Surveille le démarrage du service. +config_OK=0 +for i in `seq 1 60` +do # La boucle attend le démarrage de jenkins Ou 60 secondes. + if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 0 ]; then + # Si le log annonce une première fois le démarrage de jenkins. Fait sauter la sécurité de la première connexion de l'admin. Qui bloque curl et demande une identification inexistante une fois sur deux... + sudo wget -nv --no-check-certificate https://$domain$path/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar + for i in `seq 1 60` + do # La boucle attend la mise à jour des dépôts de plugins. Ou 20 secondes. + if test -e /var/lib/jenkins/updates/default.json; then + break; + else + echo -n "." >&2 + sleep 1 + fi + done + java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin reverse-proxy-auth-plugin + + sudo cp ../conf/config.xml /var/lib/jenkins/ + sudo chown jenkins: /var/lib/jenkins/config.xml + + sudo service $app restart # Puis redémarre à nouveau le service. + cat /dev/null > "$tempfile" # Purge le log de suivi du démarrage. + config_OK=1 + i=1; + fi + if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 1 ]; then + break # Si le log annonce une deuxième fois le démarrage d'etherpad, sort de la boucle. + fi + echo -n "." >&2 + sleep 1 + +done +kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail. +sudo rm "$tempfile"