From 6c6da2f61383a3e2f506a73e83eaf1144fdaaef3 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Mon, 8 Jun 2020 22:25:34 +0200 Subject: [PATCH] Test baikal using docker --- .gitmodules | 3 - docker-compose.yaml | 5 + docker/baikal/Dockerfile | 26 +++++ docker/baikal/apache.conf | 25 ++++ docker/baikal/baikal.yaml | 18 +++ docker/baikal/configure.sql | 139 +++++++++++++++++++++++ docker/baikal/start.sh | 16 +++ tests/storage/servers/baikal | 1 - tests/storage/servers/baikal/__init__.py | 24 ++++ tests/storage/servers/baikal/install.sh | 4 + 10 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 docker/baikal/Dockerfile create mode 100644 docker/baikal/apache.conf create mode 100644 docker/baikal/baikal.yaml create mode 100644 docker/baikal/configure.sql create mode 100644 docker/baikal/start.sh delete mode 160000 tests/storage/servers/baikal create mode 100644 tests/storage/servers/baikal/__init__.py create mode 100644 tests/storage/servers/baikal/install.sh diff --git a/.gitmodules b/.gitmodules index cc13351..0f685d2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "tests/storage/servers/baikal"] - path = tests/storage/servers/baikal - url = https://github.com/vdirsyncer/baikal-testserver [submodule "tests/storage/servers/owncloud"] path = tests/storage/servers/owncloud url = https://github.com/vdirsyncer/owncloud-testserver diff --git a/docker-compose.yaml b/docker-compose.yaml index 26a0d99..17779bb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,3 +10,8 @@ services: build: docker/radicale/ ports: - '8001:8001' + + baikal: + build: docker/baikal/ + ports: + - '8002:80' diff --git a/docker/baikal/Dockerfile b/docker/baikal/Dockerfile new file mode 100644 index 0000000..6b0f1ff --- /dev/null +++ b/docker/baikal/Dockerfile @@ -0,0 +1,26 @@ +# Based on https://github.com/ckulka/baikal-docker +# Sadly, we can't override the VOLUME it has set, and we want some static +# config. +FROM php:7.4-apache +ENV VERSION 0.7.0 + +ADD https://github.com/sabre-io/Baikal/releases/download/$VERSION/baikal-$VERSION.zip . +RUN apt-get update && apt-get install -y sqlite3 unzip +RUN unzip -q baikal-$VERSION.zip -d /var/www/ + +RUN chown -R www-data:www-data /var/www/baikal && \ + docker-php-ext-install pdo pdo_mysql + +COPY apache.conf /etc/apache2/sites-enabled/000-default.conf +COPY start.sh /opt/ +RUN a2enmod rewrite + +COPY baikal.yaml /var/www/baikal/config/baikal.yaml +COPY configure.sql /configure.sql + +RUN touch /var/www/baikal/Specific/INSTALL_DISABLED +RUN cat /configure.sql | sqlite3 /var/www/baikal/Specific/db/db.sqlite + +RUN chmod -R 777 /var/www/baikal/Specific/ /var/www/baikal/config/ + +CMD [ "sh", "/opt/start.sh" ] diff --git a/docker/baikal/apache.conf b/docker/baikal/apache.conf new file mode 100644 index 0000000..a6b35f5 --- /dev/null +++ b/docker/baikal/apache.conf @@ -0,0 +1,25 @@ +# Shameless copied from https://github.com/ckulka/baikal-docker/blob/master/files/apache.conf + + + + # InjectedServerAlias dav.example.org dav.example.io + DocumentRoot /var/www/baikal/html + + RewriteEngine On + RewriteRule /.well-known/carddav /dav.php [R,L] + RewriteRule /.well-known/caldav /dav.php [R,L] + + + Options None + Options +FollowSymlinks + AllowOverride All + + # Confiugration for apache-2.2: + Order allow,deny + Allow from all + + # Confiugration for apache-2.4: + Require all granted + + + diff --git a/docker/baikal/baikal.yaml b/docker/baikal/baikal.yaml new file mode 100644 index 0000000..459e455 --- /dev/null +++ b/docker/baikal/baikal.yaml @@ -0,0 +1,18 @@ +system: + configured_version: 0.7.0 + timezone: Europe/Paris + card_enabled: true + cal_enabled: true + dav_auth_type: Basic + admin_passwordhash: 6a890c3aa185845a4bee1e1caed92e1faaf2dec6772291dca301cef6782e3bce + auth_realm: BaikalDAV + invite_from: noreply@localhost +database: + sqlite_file: /var/www/baikal/Specific/db/db.sqlite + mysql: false + mysql_host: '' + mysql_dbname: '' + mysql_username: '' + mysql_password: '' + encryption_key: bdf3bec969736e122e6d5f72c282c49e + configured_version: '' diff --git a/docker/baikal/configure.sql b/docker/baikal/configure.sql new file mode 100644 index 0000000..55ec586 --- /dev/null +++ b/docker/baikal/configure.sql @@ -0,0 +1,139 @@ +PRAGMA foreign_keys=OFF; +BEGIN TRANSACTION; +CREATE TABLE addressbooks ( + id integer primary key asc NOT NULL, + principaluri text NOT NULL, + displayname text, + uri text NOT NULL, + description text, + synctoken integer DEFAULT 1 NOT NULL +); +INSERT INTO addressbooks VALUES(1,'principals/baikal','Default Address Book','default','Default Address Book for Baikal',1); +CREATE TABLE cards ( + id integer primary key asc NOT NULL, + addressbookid integer NOT NULL, + carddata blob, + uri text NOT NULL, + lastmodified integer, + etag text, + size integer +); +CREATE TABLE addressbookchanges ( + id integer primary key asc NOT NULL, + uri text, + synctoken integer NOT NULL, + addressbookid integer NOT NULL, + operation integer NOT NULL +); +CREATE TABLE calendarobjects ( + id integer primary key asc NOT NULL, + calendardata blob NOT NULL, + uri text NOT NULL, + calendarid integer NOT NULL, + lastmodified integer NOT NULL, + etag text NOT NULL, + size integer NOT NULL, + componenttype text, + firstoccurence integer, + lastoccurence integer, + uid text +); +CREATE TABLE calendars ( + id integer primary key asc NOT NULL, + synctoken integer DEFAULT 1 NOT NULL, + components text NOT NULL +); +INSERT INTO calendars VALUES(1,1,'VEVENT,VTODO'); +CREATE TABLE calendarinstances ( + id integer primary key asc NOT NULL, + calendarid integer, + principaluri text, + access integer, + displayname text, + uri text NOT NULL, + description text, + calendarorder integer, + calendarcolor text, + timezone text, + transparent bool, + share_href text, + share_displayname text, + share_invitestatus integer DEFAULT '2', + UNIQUE (principaluri, uri), + UNIQUE (calendarid, principaluri), + UNIQUE (calendarid, share_href) +); +INSERT INTO calendarinstances VALUES(1,1,'principals/baikal',NULL,'Default calendar','default','Default calendar',0,'','Europe/Paris',NULL,NULL,NULL,2); +CREATE TABLE calendarchanges ( + id integer primary key asc NOT NULL, + uri text, + synctoken integer NOT NULL, + calendarid integer NOT NULL, + operation integer NOT NULL +); +CREATE TABLE calendarsubscriptions ( + id integer primary key asc NOT NULL, + uri text NOT NULL, + principaluri text NOT NULL, + source text NOT NULL, + displayname text, + refreshrate text, + calendarorder integer, + calendarcolor text, + striptodos bool, + stripalarms bool, + stripattachments bool, + lastmodified int +); +CREATE TABLE schedulingobjects ( + id integer primary key asc NOT NULL, + principaluri text NOT NULL, + calendardata blob, + uri text NOT NULL, + lastmodified integer, + etag text NOT NULL, + size integer NOT NULL +); +CREATE TABLE locks ( + id integer primary key asc NOT NULL, + owner text, + timeout integer, + created integer, + token text, + scope integer, + depth integer, + uri text +); +CREATE TABLE principals ( + id INTEGER PRIMARY KEY ASC NOT NULL, + uri TEXT NOT NULL, + email TEXT, + displayname TEXT, + UNIQUE(uri) +); +INSERT INTO principals VALUES(1,'principals/baikal','baikal@example.com','Baikal'); +CREATE TABLE groupmembers ( + id INTEGER PRIMARY KEY ASC NOT NULL, + principal_id INTEGER NOT NULL, + member_id INTEGER NOT NULL, + UNIQUE(principal_id, member_id) +); +CREATE TABLE propertystorage ( + id integer primary key asc NOT NULL, + path text NOT NULL, + name text NOT NULL, + valuetype integer NOT NULL, + value string +); +CREATE TABLE users ( + id integer primary key asc NOT NULL, + username TEXT NOT NULL, + digesta1 TEXT NOT NULL, + UNIQUE(username) +); +INSERT INTO users VALUES(1,'baikal','3b0845b235b7e985ce5905ab8df45e1a'); +CREATE INDEX addressbookid_synctoken ON addressbookchanges (addressbookid, synctoken); +CREATE INDEX calendarid_synctoken ON calendarchanges (calendarid, synctoken); +CREATE INDEX principaluri_uri ON calendarsubscriptions (principaluri, uri); +CREATE UNIQUE INDEX path_property ON propertystorage (path, name); +COMMIT; diff --git a/docker/baikal/start.sh b/docker/baikal/start.sh new file mode 100644 index 0000000..cd41bba --- /dev/null +++ b/docker/baikal/start.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Shameless copied from https://raw.githubusercontent.com/ckulka/baikal-docker/master/files/start.sh + +# Inject ServerName and ServerAlias if specified +APACHE_CONFIG="/etc/apache2/sites-available/000-default.conf" +if [ ! -z ${BAIKAL_SERVERNAME+x} ] +then + sed -i "s/# InjectedServerName .*/ServerName $BAIKAL_SERVERNAME/g" $APACHE_CONFIG +fi + +if [ ! -z ${BAIKAL_SERVERALIAS+x} ] +then + sed -i "s/# InjectedServerAlias .*/ServerAlias $BAIKAL_SERVERALIAS/g" $APACHE_CONFIG +fi + +apache2-foreground diff --git a/tests/storage/servers/baikal b/tests/storage/servers/baikal deleted file mode 160000 index 6c8c379..0000000 --- a/tests/storage/servers/baikal +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6c8c379f1ee8bf4ab0ac54fc4eec3e4a6349c237 diff --git a/tests/storage/servers/baikal/__init__.py b/tests/storage/servers/baikal/__init__.py new file mode 100644 index 0000000..2647819 --- /dev/null +++ b/tests/storage/servers/baikal/__init__.py @@ -0,0 +1,24 @@ +import pytest + + +class ServerMixin: + @pytest.fixture + def get_storage_args(self, request, tmpdir, slow_create_collection): + def inner(collection="test"): + base_url = "http://127.0.0.1:8002/" + args = { + "url": base_url, + "username": "baikal", + "password": "baikal", + } + + if self.storage_class.fileext == '.vcf': + args['url'] = base_url + "card.php/" + else: + args['url'] = base_url + "cal.php/" + + if collection is not None: + args = slow_create_collection(self.storage_class, args, collection) + return args + + return inner diff --git a/tests/storage/servers/baikal/install.sh b/tests/storage/servers/baikal/install.sh new file mode 100644 index 0000000..99fcef9 --- /dev/null +++ b/tests/storage/servers/baikal/install.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +docker-compose build baikal +docker-compose up -d baikal