diff --git a/.drone.yml b/.drone.yml index 5c02181d9..f5d5bb106 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,12 +5,14 @@ env: - GOROOT=/usr/local/go - PATH=$PATH:$GOROOT/bin:$GOPATH/bin script: - - sudo apt-get -y install zip libsqlite3-dev sqlite3 1> /dev/null 2> /dev/null + - sudo apt-get -y install zip libsqlite3-dev sqlite3 rpm 1> /dev/null 2> /dev/null + - gem install fpm + - rbenv rehash - make deps - make test - make test_postgres - make test_mysql - - make dpkg + - make packages services: - postgres - mysql @@ -29,5 +31,5 @@ publish: bucket: downloads.drone.io access_key: $AWS_KEY secret_key: $AWS_SECRET - source: debian/drone.deb + source: packaging/output/drone.* target: $DRONE_BRANCH/ diff --git a/.gitignore b/.gitignore index 2b77de6c9..19c3e825f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,11 +6,12 @@ drone.sublime-workspace *~ ~* *.sqlite -*.deb +drone.deb +drone.rpm *.out *.rice-box.go cli/cli client/client server/server -debian/drone/usr +packaging/root/usr/local diff --git a/Makefile b/Makefile index 2136d9fe1..99b6103e8 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,9 @@ test_postgres: TEST_DRIVER="postgres" TEST_DATASOURCE="host=127.0.0.1 user=postgres dbname=postgres sslmode=disable" go test -short github.com/drone/drone/server/datastore/database build: - go build -o debian/drone/usr/local/bin/drone -ldflags "-X main.revision $(SHA)" github.com/drone/drone/cli - go build -o debian/drone/usr/local/bin/droned -ldflags "-X main.revision $(SHA)" github.com/drone/drone/server + mkdir -p packaging/root/usr/local/bin + go build -o packaging/root/usr/local/bin/drone -ldflags "-X main.revision $(SHA)" github.com/drone/drone/cli + go build -o packaging/root/usr/local/bin/droned -ldflags "-X main.revision $(SHA)" github.com/drone/drone/server install: install -t /usr/local/bin debian/drone/usr/local/bin/drone @@ -32,28 +33,53 @@ run: clean: find . -name "*.out" -delete - rm -f debian/drone/usr/local/bin/drone - rm -f debian/drone/usr/local/bin/droned - rm -f debian/drone.deb - rm -f server/server - rm -f cli/cli + rm -rf packaging/output + rm -f packaging/root/usr/local/bin/drone + rm -f packaging/root/usr/local/bin/droned + mkdir -p packaging/output lessc: lessc --clean-css server/app/styles/drone.less server/app/styles/drone.css -dpkg: build embed deb +packages: clean build embed deb rpm # embeds content in go source code so that it is compiled # and packaged inside the go binary file. embed: - rice --import-path="github.com/drone/drone/server" append --exec="debian/drone/usr/local/bin/droned" + rice --import-path="github.com/drone/drone/server" append --exec="packaging/root/usr/local/bin/droned" # creates a debian package for drone to install # `sudo dpkg -i drone.deb` deb: - mkdir -p debian/drone/usr/local/bin - mkdir -p debian/drone/var/lib/drone - dpkg-deb --build debian/drone + fpm -s dir -t deb -n drone -v 0.3 -p packaging/output/drone.deb \ + --deb-priority optional --category admin \ + --force \ + --deb-compression bzip2 \ + --after-install packaging/scripts/postinst.deb \ + --before-remove packaging/scripts/prerm.deb \ + --after-remove packaging/scripts/postrm.deb \ + --url https://github.com/drone/drone \ + --description "Drone continuous integration server" \ + -m "Brad Rydzewski " \ + --license "Apache License 2.0" \ + --vendor "drone.io" -a amd64 \ + --config-files /etc/drone/drone.toml \ + packaging/root/=/ + +rpm: + fpm -s dir -t rpm -n drone -v 0.3 -p packaging/output/drone.rpm \ + --rpm-compression bzip2 --rpm-os linux \ + --force \ + --after-install packaging/scripts/postinst.rpm \ + --before-remove packaging/scripts/prerm.rpm \ + --after-remove packaging/scripts/postrm.rpm \ + --url https://github.com/drone/drone \ + --description "Drone continuous integration server" \ + -m "Brad Rydzewski " \ + --license "Apache License 2.0" \ + --vendor "drone.io" -a amd64 \ + --config-files /etc/drone/drone.toml \ + packaging/root/=/ # deploys drone to a staging server. this requires the following # environment variables are set: diff --git a/README.md b/README.md index e2696ca03..6ca9d8b9e 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,13 @@ We have optimized the installation process for Ubuntu since that is what we test You can run the following commands to quickly download an install Drone on an Ubuntu machine. ```sh +# Ubuntu, Debian wget downloads.drone.io/master/drone.deb sudo dpkg -i drone.deb + +# CentOS, RedHat +wget downloads.drone.io/master/drone.rpm +sudo yum localinstall drone.rpm ``` ## Database diff --git a/debian/drone/DEBIAN/conffiles b/debian/drone/DEBIAN/conffiles deleted file mode 100644 index 980d34ea0..000000000 --- a/debian/drone/DEBIAN/conffiles +++ /dev/null @@ -1,2 +0,0 @@ -/etc/init/drone.conf -/etc/drone/drone.toml diff --git a/debian/drone/DEBIAN/control b/debian/drone/DEBIAN/control deleted file mode 100644 index 2bafdcb3b..000000000 --- a/debian/drone/DEBIAN/control +++ /dev/null @@ -1,7 +0,0 @@ -Package: drone -Version: 0.3 -Section: base -Priority: optional -Architecture: amd64 -Maintainer: Brad Rydzewski -Description: Drone continuous integration server diff --git a/debian/drone/DEBIAN/postinst b/debian/drone/DEBIAN/postinst deleted file mode 100755 index c68edbd0c..000000000 --- a/debian/drone/DEBIAN/postinst +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -set -e - -case "$1" in - abort-upgrade|abort-remove|abort-deconfigure|configure) - ;; - - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 1 - ;; -esac - -echo "Starting drone ..." -if [ -f /etc/init/drone.conf ]; then - if pidof /usr/local/bin/droned >/dev/null; then - service drone stop || exit $? - fi - service drone start && echo "Drone started." -fi - -#DEBHELPER# - -exit 0 \ No newline at end of file diff --git a/debian/drone/DEBIAN/prerm b/debian/drone/DEBIAN/prerm deleted file mode 100755 index a2150c193..000000000 --- a/debian/drone/DEBIAN/prerm +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -e -set -u - -case "$1" in - remove|remove-in-favour|deconfigure|deconfigure-in-favour) - if [ -f /etc/init/drone.conf ]; then - echo "Stopping drone ..." - service drone stop || exit $? - echo "Drone Stopped." - fi - ;; - - upgrade|failed-upgrade) - ;; - - *) - echo "prerm called with unknown argument \`$1'" >&2 - exit 1 - ;; -esac - -#DEBHELPER# - -exit 0 \ No newline at end of file diff --git a/debian/drone/etc/drone/drone.toml b/packaging/root/etc/drone/drone.toml similarity index 100% rename from debian/drone/etc/drone/drone.toml rename to packaging/root/etc/drone/drone.toml diff --git a/debian/drone/etc/init/drone.conf b/packaging/root/usr/share/drone/init/drone.conf similarity index 100% rename from debian/drone/etc/init/drone.conf rename to packaging/root/usr/share/drone/init/drone.conf diff --git a/packaging/root/usr/share/drone/systemd/drone.service b/packaging/root/usr/share/drone/systemd/drone.service new file mode 100644 index 000000000..dd590a18a --- /dev/null +++ b/packaging/root/usr/share/drone/systemd/drone.service @@ -0,0 +1,26 @@ +# +# systemd unit file for CentOS 7, Ubuntu bleeding edge +# +[Unit] +Description=Drone +# start us only once the network and logging subsystems are available +After=syslog.target network.target + +# See these pages for lots of options: +# http://0pointer.de/public/systemd-man/systemd.service.html +# http://0pointer.de/public/systemd-man/systemd.exec.html +[Service] +Type=simple +ExecStart=/usr/local/bin/droned --config=/etc/drone/drone.toml + +# if we crash, restart +RestartSec=1 +Restart=on-failure + +# use syslog for logging +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=droned + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/packaging/root/var/lib/drone/.keep b/packaging/root/var/lib/drone/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/packaging/scripts/postinst.deb b/packaging/scripts/postinst.deb new file mode 100644 index 000000000..167c54e3f --- /dev/null +++ b/packaging/scripts/postinst.deb @@ -0,0 +1,91 @@ +#!/bin/sh + +set -e + +case "$1" in + abort-upgrade|abort-remove|abort-deconfigure|configure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +if [ -f /etc/drone/drone.toml ]; then + chmod 600 /etc/drone/drone.toml +fi + +dist() { + lsb_release -i | awk '{print tolower($3)}' | sed -e 's/^ *//' -e 's/ *$//' +} + +version() { + lsb_release -r | awk '{print $2}' | sed -e 's/^ *//' -e 's/ *$//' +} + +upstart() { + if [ -d /etc/init ]; then + if [ -f /usr/local/bin/droned ]; then + if pidof /usr/local/bin/droned >/dev/null; then + initctl stop drone || : + fi + fi + + echo "You have $(dist) $(version): using upstart to control Drone" + cp -r /usr/share/drone/init/drone.conf /etc/init/drone.conf + initctl start drone || : + else + echo "Couldn't find upstart to control Drone, cannot proceed." + echo "Open an issue and tell us about your system." + exit 1 + fi +} + +systemd() { + if which systemctl > /dev/null; then + echo "Your system $(dist) $(version): using systemd to control Drone" + cp /usr/share/drone/systemd/drone.service /lib/systemd/system/drone.service + + systemctl daemon-reload || : + if [ "$1" = 1 ] ; then + # first time install + systemctl enable drone || : + systemctl start drone || : + else + echo "Upgrading drone" + systemctl restart drone + fi + else + echo "Couldn't find systemd to control Drone, cannot proceed." + echo "Open an issue and tell us about your system." + exit 1 + fi +} + +validate_ver() { + echo "$(version) < $1" | bc +} + +case "$(dist)" in + debian) + if [ $(validate_ver "8.0") -eq 1 ]; then + upstart + else + systemd $1 + fi + ;; + ubuntu) + if [ $(validate_ver "14.10") -eq 1 ]; then + upstart + else + systemd $1 + fi + ;; + *) + echo "\033[33m Your system $(dist) $(version) \033[0m" + echo "\033[33m This system is not supported, you can install service manually \033[0m" + ;; +esac + +exit 0 \ No newline at end of file diff --git a/packaging/scripts/postinst.rpm b/packaging/scripts/postinst.rpm new file mode 100644 index 000000000..34d175950 --- /dev/null +++ b/packaging/scripts/postinst.rpm @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +if [ -f /etc/drone/drone.toml ]; then + chmod 600 /etc/drone/drone.toml +fi + +if which systemctl > /dev/null; then + echo "Using systemd to control Drone" + cp /usr/share/drone/systemd/drone.service /lib/systemd/system/drone.service + + systemctl daemon-reload || : + if [ "$1" = 1 ] ; then + # first time install + systemctl enable drone || : + systemctl start drone || : + else + echo "Upgrading drone" + fi +else + echo "Couldn't find systemd to control Drone, cannot proceed." + echo "Open an issue and tell us about your system." + exit 1 +fi + +exit 0 \ No newline at end of file diff --git a/packaging/scripts/postrm.deb b/packaging/scripts/postrm.deb new file mode 100644 index 000000000..bd84cdbca --- /dev/null +++ b/packaging/scripts/postrm.deb @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +dist() { + lsb_release -i | awk '{print tolower($3)}' | sed -e 's/^ *//' -e 's/ *$//' +} + +version() { + lsb_release -r | awk '{print $2}' | sed -e 's/^ *//' -e 's/ *$//' +} + +upstart() { + rm -f /etc/init/drone.conf +} + +systemd() { + rm -f /lib/systemd/system/drone.service +} + +validate_ver() { + echo "$(version) < $1" | bc +} + +case "$(dist)" in + debian) + if [ $(validate_ver "8.0") -eq 1 ]; then + upstart + else + systemd + fi + ;; + ubuntu) + if [ $(validate_ver "14.10") -eq 1 ]; then + upstart + else + systemd + fi + ;; + *) + echo "\033[33m Please remove service manually \033[0m" + ;; +esac + +# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html + +if [ "$1" = "purge" ] ; then + echo "Purging drone configuration" + rm -rf /etc/drone +fi \ No newline at end of file diff --git a/packaging/scripts/postrm.rpm b/packaging/scripts/postrm.rpm new file mode 100644 index 000000000..2d49887f3 --- /dev/null +++ b/packaging/scripts/postrm.rpm @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +# https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html + +systemctl daemon-reload || : +if [ "$1" -ge 1 ] ; then + # Package upgrade, not uninstall + systemctl try-restart drone || : +fi \ No newline at end of file diff --git a/packaging/scripts/prerm.deb b/packaging/scripts/prerm.deb new file mode 100644 index 000000000..ccfe848ac --- /dev/null +++ b/packaging/scripts/prerm.deb @@ -0,0 +1,51 @@ +#!/bin/sh +set -e + +dist() { + lsb_release -i | awk '{print tolower($3)}' | sed -e 's/^ *//' -e 's/ *$//' +} + +version() { + lsb_release -r | awk '{print $2}' | sed -e 's/^ *//' -e 's/ *$//' +} + +echo Stopping drone + +upstart() { + initctl stop drone || : +} + +systemd() { + if [ "$1" -eq 0 ] ; then + systemctl --no-reload disable drone || : + systemctl stop drone || : + fi +} + +validate_ver() { + echo "$(version) < $1" | bc +} + +case "$(dist)" in + debian) + if [ $(validate_ver "8.0") -eq 1 ]; then + upstart + else + systemd $1 + fi + ;; + ubuntu) + if [ $(validate_ver "14.10") -eq 1 ]; then + upstart + else + systemd $1 + fi + ;; + *) + if [ -f /usr/local/bin/droned ]; then + if pidof /usr/local/bin/droned >/dev/null; then + kill -9 `pidof /usr/local/bin/droned` + fi + fi + ;; +esac \ No newline at end of file diff --git a/packaging/scripts/prerm.rpm b/packaging/scripts/prerm.rpm new file mode 100644 index 000000000..d6b3b7c9b --- /dev/null +++ b/packaging/scripts/prerm.rpm @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +if [ "$1" -eq 0 ] ; then + echo Stopping Drone + systemctl --no-reload disable drone || : + systemctl stop drone || : +fi \ No newline at end of file