Build rpm and deb packages

This commit is contained in:
Kirill Zaitsev 2014-10-12 20:22:51 +04:00
parent 12757476d8
commit b64cd83424
18 changed files with 315 additions and 76 deletions

View file

@ -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
@ -26,5 +28,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/

5
.gitignore vendored
View file

@ -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

View file

@ -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 <brad@drone.io>" \
--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 <brad@drone.io>" \
--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:

View file

@ -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

View file

@ -1,2 +0,0 @@
/etc/init/drone.conf
/etc/drone/drone.toml

View file

@ -1,7 +0,0 @@
Package: drone
Version: 0.3
Section: base
Priority: optional
Architecture: amd64
Maintainer: Brad Rydzewski <brad@drone.io>
Description: Drone continuous integration server

View file

@ -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

View file

@ -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

View file

@ -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

View file

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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