Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

WIP: Build Alpine package #224

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[alpine/**]
indent_size = 4
indent_style = tab
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ RACK_ENV=development
TZ=Europe/Prague
RAISE_ERRORS=true
FORCE_SSL=false
TIMEOUT=false
RACK_TIMEOUT=false
DOMAIN=example.com
SYNC_SCHEDULE=0 */12 * * *
123 changes: 80 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,86 @@
language: ruby
sudo: false
dist: trusty
addons:
postgresql: '9.5'
apt:
sources:
- elasticsearch-1.7
packages:
- elasticsearch
code_climate:
repo_token: a813ce884be14a158262d4e05906c0b6f4e7f4533c41cdf88bda7da84d88297f
cache:
bundler: true
rvm:
- 2.3
- 2.4
- ruby-head
services:
- postgresql
- elasticsearch
bundler_args: --without development doc
before_script:
- while read line; do export $line; done < .env.test
- bundle exec rake --trace db:setup
- echo 'waiting for elasticsearch to come up'; wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
after_success: |
if [ "$TRAVIS_BRANCH" = master ]; then
nvm install 4.2 && nvm use 4.2 \
&& npm install -g raml2html \
&& bundle exec rake raml:publish
fi
notifications:
email:
on_success: never # default: change
on_failure: change # default: always
webhooks:
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
env:
global:
- secure: RyyZpzIhIJVX+1CKn5BKx3siHeDwUux+q4/dMrmc0P06aCHvSapdrUjPOWK1b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czw3U2X/eI= # OAUTH_CLIENT_SECRET

jobs:
include:
- &test
stage: test
language: ruby
rvm: 2.3
addons:
postgresql: '9.5'
code_climate:
repo_token: a813ce884be14a158262d4e05906c0b6f4e7f4533c41cdf88bda7da84d88297f
services:
- postgresql
cache:
bundler: true
install:
# Travis provides only ElasticSearch 5.x, we must install legacy version ourself.
- "wget -nv https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.3.tar.gz
&& echo '754b089ec0a1aae5b36b39391d5385ed7428d8f5 elasticsearch-1.7.3.tar.gz' | sha1sum -c
&& tar -xzf elasticsearch-*.tar.gz"
- bundle install --without development doc --jobs=3 --retry=3
before_script:
- while read line; do export $line; done < .env.test
- bundle exec rake --trace db:setup
- ./elasticsearch-*/bin/elasticsearch &
- echo 'waiting for elasticsearch to come up'; wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200

- <<: *test
rvm: 2.4

- &test-ruby-head
<<: *test
rvm: ruby-head

- stage: deploy
language: node_js
node_js: 4
rvm: 2.4
cache:
bundler: true
install:
- npm install -g raml2html
- bundle install --jobs=3 --retry=3
script: skip
deploy:
- provider: script
script: bundle exec rake raml:publish
skip_cleanup: true
on:
branch: master

# Build Alpine package.
- stage: deploy
sudo: true
language: minimal
before_install:
- "wget -nv https://raw.githubusercontent.com/alpinelinux/alpine-chroot-install/v0.6.0/alpine-chroot-install \
&& echo 'a827a4ba3d0817e7c88bae17fe34e50204983d1e alpine-chroot-install' | sha1sum -c"
- alpine() { /alpine/enter-chroot -u "$USER" "$@"; }
install:
- sudo sh alpine-chroot-install -b v3.6 -p 'build-base alpine-sdk'
before_script:
- /alpine/enter-chroot sh -c "addgroup $USER wheel && addgroup $USER abuild"
- alpine abuild-keygen -ain
script:
- cd alpine && alpine abuild -R

fast_finish: true
# This doesn't work now, probably bug in Travis.
allow_failures:
- rvm: ruby-head
- rvm: 2.4
- <<: *test-ruby-head

notifications:
email:
on_success: never
on_failure: change
webhooks:
on_success: change
on_failure: always
3 changes: 0 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ require 'pliny/tasks'
Dir['./lib/tasks/*.rake'].each { |task| load task }

task :default => :spec



74 changes: 74 additions & 0 deletions alpine/APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Maintainer: Jakub Jirutka <[email protected]>
pkgname=sirius
pkgver=${PKGVER:-$(date +%Y%m%d)}
pkgrel=0
pkgdesc="CTU Time management API"
url="https://github.com/cvut/sirius"
arch="all"
license="MIT"
depends="ruby-bigdecimal ruby-io-console ruby-irb ruby-json ruby-rake
ruby-bundler ca-certificates tzdata"
makedepends="ruby-dev postgresql-dev"
pkgusers="sirius"
pkggroups="sirius"
install="$pkgname.pre-install"
source=""
builddir="$startdir/.."

_prefix="usr/bundles/$pkgname"

build() {
cd "$builddir"

CI=true bundle install \
--deployment \
--frozen \
--jobs=${JOBS:-2} \
--no-cache \
--without development test

rm -rf vendor/bundle/ruby/*/cache
}

package() {
local destdir="$pkgdir/$_prefix"

# Install files

cd "$builddir"

mkdir -p "$destdir"
cp -ar app config db lib vendor config.ru Gemfile* Rakefile "$destdir"/

install -m 755 -D "$startdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
install -m 755 -D "$startdir"/$pkgname.scheduler.initd "$pkgdir"/etc/init.d/$pkgname.scheduler
install -m 644 -D "$startdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
install -m 644 -D "$startdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

install -d -m 755 -o sirius -g sirius "$pkgdir"/var/log/$pkgname

# Cleanup

cd vendor/bundle/ruby/*/

# Remove documentations and other unused textual files.
find gems/ -name 'doc' -type d -exec rm -frv '{}' +
find gems/ \
-name 'README*' -delete \
-o -name 'CHANGELOG*' -delete \
-o -name 'CONTRIBUT*' -delete \
-o -name '*LICENSE*' -delete

# Remove sources and binaries of native extensions (they are installed
# in extensions directory).
find gems/ -type d -name ext -maxdepth 2 -exec rm -frv '{}' +
find gems/ -name '*.so' -delete

# Remove build logs and cache.
rm -rf cache
find extensions/ \
-name gem_make.out -delete \
-o -name mkmf.log -delete
}

sha512sums=""
42 changes: 42 additions & 0 deletions alpine/sirius.confd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Configuration for /etc/init.d/sirius and /etc/init.d/sirius.scheduler

# Domain name of the application (required).
domain=

# URI of PostgreSQL database (e.g. postgres://sirius:[email protected]/sirius) (required).
database_url=

# URI of Elastic DB (e.g. http://elastic.example.org:9200) (required).
elastic_url=

# OAuth 2.0 client_id used to access KOSapi (required).
oauth_client_id=

# OAuth 2.0 client_secret used to access KOSapi (required).
oauth_client_secret=


# HTTP port to listen on (default: 5000).
#http_port=

# Timeout (in seconds) for HTTP requests (default: 10).
# Requests which exceed this timeout are aborted.
#rack_timeout=

# Number of Puma worker processes to launch (default: 3).
#puma_workers=

# Minimum number of threads to by available in Puma's thread pool (default: 1).
#puma_min_threads=

# Maximum number of threads to by available in Puma's thread pool (default: 16).
#puma_max_threads=

# The maximum size of the connection pool (default: 3).
#db_pool_max_size=

# Sentry DSN (optional).
#sentry_dsn=

# Cron expression specifying when to run import and planning procedure (optional).
#sync_schedule=
63 changes: 63 additions & 0 deletions alpine/sirius.initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/sbin/openrc-run

# XXX: We must disable globbing to prevent messing of SYNC_SCHEDULE variable!
set -f

name="Sirius"

extra_started_commands="reload"
description_reload="Perform a hot restart (keeps the server sockets open)."

: ${user:="sirius"}
: ${basedir:="/usr/bundles/sirius"}
: ${logdir:="/var/log/sirius"}
: ${puma_socket:="/run/sirius/server.sock"}
: ${timezone:="Europe/Prague"}

command="/usr/bin/bundle"
command_args="exec puma --config config/puma.rb config.ru"
command_background="yes"

pidfile="/run/$RC_SVCNAME/server.pid"
start_stop_daemon_args="
--chdir '$basedir'
--user $user
--stdout '$logdir/puma.log'
--stderr '$logdir/puma.log'
--wait 1000
--env RACK_ENV=production
--env TZ=$timezone
$start_stop_daemon_args"

depend() {
use net postgresql
}

start_pre() {
checkpath -d -o $user -m755 "${pidfile%/*}"
checkpath -d -o $user -m755 "${puma_socket%/*}"
checkpath -d -o $user -m755 "$logdir"

local name value
for name in database_url db_pool_max_size domain elastic_url http_port \
oauth_client_id oauth_client_secret puma_max_threads puma_min_threads \
puma_workers rack_timeout sentry_dsn sync_schedule
do
value=$(getval $name)
if [ -n "$value" ]; then
start_stop_daemon_args="$start_stop_daemon_args
--env $(echo $name | tr '[a-z]' '[A-Z]')='$value'"
fi
done
}

reload() {
ebegin "Reloading $name"
kill -USR2 $(head -n1 $pidfile)
eend $?
}

getval() {
local var_name="$1"
eval "printf '%s\n' \"\${$var_name:-}\""
}
5 changes: 5 additions & 0 deletions alpine/sirius.logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/var/log/sirius/*.log {
missingok
notifempty
copytruncate
}
6 changes: 6 additions & 0 deletions alpine/sirius.pre-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

addgroup -S sirius 2>/dev/null
adduser -S -D -H -h /usr/bundles/sirius -s /sbin/nologin -G sirius -g "added by apk for sirius" sirius 2>/dev/null

exit 0
Loading