#!/bin/sh
set -ev

ROOT=$(dirname $(dirname $(realpath "${0}")))

# Build documentation
cd ${ROOT}/doc
make html

# Build basic tar
cd ${ROOT}/vm
tar czpf /srv/build/vm.tar.gz *

# Build native apps
cd ${ROOT}/apk/py3-secure-cookie
apk add -U py3-setuptools py3-pytest py3-werkzeug
abuild -F

cd ${ROOT}/apk/spoc
abuild -F

cd ${ROOT}/apk/vmmgr
abuild -F

# Build runtimes
cd ${ROOT}/lxc-shared
spoc-image build -p alpine3.8/image
spoc-image build -p alpine3.8-java8/image
spoc-image build -p alpine3.8-ruby2.4/image
spoc-image build -p alpine3.10/image
spoc-image build -p alpine3.10-nodejs10/image
spoc-image build -p alpine3.11/image
spoc-image build -p alpine3.11-python2.7/image
spoc-image build -p alpine3.12/image
spoc-image build -p alpine3.12-java8/image
spoc-image build -p alpine3.12-php7.3/image
spoc-image build -p alpine3.12-python3.8/image
spoc-image build -p alpine3.12-ruby2.4/image
spoc-image build -p alpine3.12-ruby2.7/image
spoc-image build -p alpine3.12-tomcat7/image
spoc-image build -p alpine3.12-tomcat8.5/image
spoc-image build -p debian10/image

# Build services
cd ${ROOT}/lxc-services
spoc-image build -p activemq/image
spoc-image build -p mariadb/image
spoc-image build -p mongodb/image
spoc-image build -p postgres/image
spoc-image build -p postgis/image
spoc-image build -p rabbitmq/image
spoc-image build -p redis/image
spoc-image build -p solr6/image

# Build applications
cd ${ROOT}/lxc-apps

spoc-image build -p ckan/ckan.image
spoc-image build -p ckan/ckan-datapusher.image
spoc-app publish ckan/app

spoc-image build -p crisiscleanup/image
spoc-app publish crisiscleanup/app

spoc-image build -p cts/image
spoc-app publish cts/app

spoc-image build -p decidim/decidim-nginx.image
spoc-image build -p decidim/decidim.image
spoc-app publish decidim/app

spoc-image build -p dhis2/image
spoc-app publish dhis2/app

spoc-image build -p frontlinesms/image
spoc-app publish frontlinesms/app

spoc-image build -p gnuhealth/image
spoc-app publish gnuhealth/app

spoc-image build -p kanboard/image
spoc-app publish kanboard/app

spoc-image build -p mifosx/image
spoc-app publish mifosx/app

spoc-image build -p motech/image
spoc-app publish motech/app

spoc-image build -p odoo/image
spoc-app publish odoo/app

spoc-image build -p opendatakit/opendatakit.image
spoc-image build -p opendatakit/opendatakit-build.image
spoc-app publish opendatakit/app

spoc-image build -p openmapkit/image
spoc-app publish openmapkit/app

spoc-image build -p pandora/image
spoc-app publish pandora/app

spoc-image build -p sahana/image
spoc-app publish sahana/app
spoc-app publish sahana-demo/app
spoc-app publish sambro/app
spoc-app publish safire/app
spoc-app publish share/app

spoc-image build -p seeddms/image
spoc-app publish seeddms/app

spoc-image build -p taarifa/image
spoc-app publish taarifa/app

spoc-image build -p ushahidi/image
spoc-app publish ushahidi/app
