Skip to content

Commit

Permalink
Implement build task, result and log requests handling
Browse files Browse the repository at this point in the history
  • Loading branch information
karen-arutyunov committed Apr 19, 2017
1 parent efb9c3e commit dbbc19b
Show file tree
Hide file tree
Showing 47 changed files with 2,388 additions and 525 deletions.
55 changes: 40 additions & 15 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,46 @@ bpkg install brep
$ cd .. # Back to brep home.


4. Create PostgreSQL User and Database
4. Create PostgreSQL User and Databases

$ sudo sudo -u postgres psql # Note: double sudo is not a mistake.

CREATE DATABASE brep TEMPLATE template0 ENCODING 'UTF8'
CREATE DATABASE brep_package TEMPLATE template0 ENCODING 'UTF8'
LC_COLLATE 'en_US.UTF8' LC_CTYPE 'en_US.UTF8';
CREATE DATABASE brep_build TEMPLATE template0 ENCODING 'UTF8'
LC_COLLATE 'en_US.UTF8' LC_CTYPE 'en_US.UTF8';
CREATE USER brep;
GRANT ALL PRIVILEGES ON DATABASE brep TO brep;
GRANT ALL PRIVILEGES ON DATABASE brep_package, brep_build TO brep;
CREATE USER "www-data" INHERIT IN ROLE brep;

Exit psql (^D), then make sure the logins work:

$ psql
$ psql -d brep_package
^D
$ psql -d brep_build
^D
$ sudo sudo -u www-data psql -d brep
$ sudo sudo -u www-data psql -d brep_package
^D
$ sudo sudo -u www-data psql -d brep_build
^D

To troubleshoot, see PostgreSQL logs.


5. Create Database Schema and Load Repositories
5. Create Database Schemes and Load Repositories

$ mkdir config
$ edit config/loadtab # Loader configuration, see brep-load(1).

$ install/bin/brep-migrate
$ install/bin/brep-migrate package
$ install/bin/brep-load config/loadtab

$ install/bin/brep-migrate build

To verify:

$ psql -c 'SELECT name, summary FROM repository'
$ psql -d brep_package -c 'SELECT name, summary FROM repository'
$ psql -d brep_build -c 'SELECT package_name FROM build' # Empty row set.


6. Setup Apache2 Module
Expand All @@ -143,6 +152,18 @@ can also find this fragment in install/share/brep/etc/brep-apache2.conf):
LoadModule brep_module /home/brep/install/libexec/brep/mod_brep.so
</IfModule>

# Repository email. This email is used for the From: header in emails
# send by brep (for example, build failure notifications).
#
brep-email [email protected]

# Repository host. It specifies the scheme and the host address (but
# not the root path; see brep-root below) that will be used whenever
# brep needs to construct an absolute URL to one of its locations (for
# example, a link to a build log that is being send via email).
#
brep-host https://example.org

# Repository root. This is the part of the URL between the host name
# and the start of the repository. For example, root value /pkg means
# the repository URL is http://example.org/pkg/. Specify / to use the
Expand Down Expand Up @@ -192,13 +213,15 @@ can also find this fragment in install/share/brep/etc/brep-apache2.conf):
# Require all granted
#</Directory>

The output content type of the brep module is application/xhtml+xml and if you
would like to make sure it gets compressed (along with linked CSS), also add
the following lines:
The output content types of the brep module are application/xhtml+xml,
text/manifest and text/plain. If you would like to make sure they get
compressed (along with linked CSS), also add the following lines:

# Compress brep output (xhtml+xml) and CSS.
#
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/manifest
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/css

Restart Apache2:
Expand Down Expand Up @@ -338,14 +361,16 @@ Review brep-module.conf changes that may need to be merged:

$ diff -u install/share/brep/etc/brep-module.conf config/brep-module.conf

Migrate database schema:
Migrate database schemes:

$ install/bin/brep-migrate
$ install/bin/brep-migrate package
$ install/bin/brep-migrate build

Note that if instead you need to recreate the whole database (e.g., migration
Note that if instead you need to recreate the whole databases (e.g., migration
is not possible), then one way to do it would be:

$ psql -c 'DROP OWNED BY brep'
$ psql -d brep_package -c 'DROP OWNED BY brep'
$ psql -d brep_build -c 'DROP OWNED BY brep'

If using systemd, then start and enable the loader:

Expand Down
49 changes: 37 additions & 12 deletions INSTALL-DEV
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,50 @@ setfacl -m g:www-data:rx ~/ ~/projects
group, not user. However, most installations use the same name for both.]


1. Create PostgreSQL User and Database
1. Create PostgreSQL User and Databases

$ sudo sudo -u postgres psql # Note: double sudo is not a mistake.

CREATE DATABASE brep TEMPLATE template0 ENCODING 'UTF8'
CREATE DATABASE brep_package TEMPLATE template0 ENCODING 'UTF8'
LC_COLLATE 'en_US.UTF8' LC_CTYPE 'en_US.UTF8';
CREATE DATABASE brep_build TEMPLATE template0 ENCODING 'UTF8'
LC_COLLATE 'en_US.UTF8' LC_CTYPE 'en_US.UTF8';
CREATE USER <user>;
GRANT ALL PRIVILEGES ON DATABASE brep TO <user>;
GRANT ALL PRIVILEGES ON DATABASE brep_package, brep_build TO <user>;
CREATE USER "www-data" INHERIT IN ROLE <user>;

Exit psql (^D), then make sure the logins work:

$ psql -d brep
$ sudo sudo -u www-data psql -d brep
$ psql -d brep_package
^D
$ psql -d brep_build
^D
$ sudo sudo -u www-data psql -d brep_package
^D
$ sudo sudo -u www-data psql -d brep_build
^D

To troubleshoot, see PostgreSQL logs, for example:

$ sudo tail -f /var/log/postgresql/*.log


2. Create Database Schema and Load the Repository
2. Create Database Schemes and Load the Repository

All the commands are executed from brep project root.

$ migrate/brep-migrate
$ migrate/brep-migrate package

# Or use some other loader config.
#
$ load/brep-load --bpkg ../bpkg/bpkg/bpkg tests/load/loadtab

$ migrate/brep-migrate build

To verify:

$ psql -d brep -c 'SELECT name, summary FROM repository'
$ psql -d brep_package -c 'SELECT name, summary FROM repository'
$ psql -d brep_build -c 'SELECT package_name FROM build' # Empty row set.


3. Setup Apache2 Module
Expand All @@ -73,6 +84,18 @@ replacing <BREP-OUT-ROOT> and <BREP-SRC-ROOT> with the actual absolute paths
LoadModule brep_module <BREP-OUT-ROOT>/mod/mod_brep.so
</IfModule>

# Repository email. This email is used for the From: header in emails
# send by brep (for example, build failure notifications).
#
brep-email [email protected]

# Repository host. It specifies the scheme and the host address (but
# not the root path; see brep-root below) that will be used whenever
# brep needs to construct an absolute URL to one of its locations (for
# example, a link to a build log that is being send via email).
#
brep-host https://example.org

# Repository root. Use / for web server root. And don't forget to also
# update the Location and Alias directives below.
#
Expand Down Expand Up @@ -117,15 +140,17 @@ $ sudo tail -f /var/log/apache2/error.log

4. Reloading During Development

To do a "complete reload" (i.e., recreate database schema, load the repository
To do a "complete reload" (i.e., recreate database schemes, load the repository
data, and reload the Apache2 plugin), execute the following from brep/:

migrate/brep-migrate --recreate
migrate/brep-migrate --recreate package
migrate/brep-migrate --recreate build
load/brep-load --bpkg ../bpkg/bpkg/bpkg tests/load/loadtab
sudo /etc/init.d/apache2 restart
sudo systemctl restart apache2

Note that if instead you need to recreate the whole database (e.g., migration
Note that if instead you need to recreate the whole databases (e.g., migration
is not possible), then one way to do it would be:

$ psql -d brep -c 'DROP OWNED BY <user>'
$ psql -d brep_package -c 'DROP OWNED BY <user>'
$ psql -d brep_build -c 'DROP OWNED BY <user>'
5 changes: 5 additions & 0 deletions brep/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
common-odb*

package-odb*
package.sql
package-extra

build-odb*
build.sql
155 changes: 155 additions & 0 deletions brep/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// file : brep/build -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file

#ifndef BREP_BUILD
#define BREP_BUILD

#include <chrono>

#include <odb/core.hxx>
#include <odb/section.hxx>

#include <bbot/manifest>

#include <brep/types>
#include <brep/utility>

#include <brep/common> // Must be included last (see assert).

// Used by the data migration entries.
//
#define LIBBREP_BUILD_SCHEMA_VERSION_BASE 1

#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 1, open)

// We have to keep these mappings at the global scope instead of inside
// the brep namespace because they need to be also effective in the
// bbot namespace from which we "borrow" types (and some of them use the mapped
// types).
//
#pragma db map type(bbot::result_status) as(std::string) \
to(to_string (?)) \
from(bbot::to_result_status (?))

namespace brep
{
#pragma db value
struct build_id
{
package_id package;
string configuration;

build_id () = default;
build_id (package_id p, string c)
: package (move (p)), configuration (move (c)) {}
};

inline bool
operator< (const build_id& x, const build_id& y)
{
return
x.package < y.package ? true :
y.package < x.package ? false :
x.configuration < y.configuration;
}

// build_state
//
enum class build_state: std::uint8_t
{
untested,
testing,
tested
};

string
to_string (build_state);

build_state
to_build_state (const string&); // May throw invalid_argument.

inline ostream&
operator<< (ostream& os, build_state s) {return os << to_string (s);}

#pragma db map type(build_state) as(string) \
to(to_string (?)) \
from(brep::to_build_state (?))

// result_status
//
using bbot::result_status;

using optional_result_status = optional<result_status>;

#pragma db map type(optional_result_status) as(optional_string) \
to((?) ? bbot::to_string (*(?)) : brep::optional_string ()) \
from((?) \
? bbot::to_result_status (*(?)) \
: brep::optional_result_status ())

// operation_results
//
using bbot::operation_result;
#pragma db value(operation_result) definition

using bbot::operation_results;

#pragma db object pointer(shared_ptr) session
class build
{
public:
using timestamp_type = brep::timestamp;

// Create the build object with the testing state, non-existent status and
// the timestamp set to now.
//
build (string name, version, string configuration);

build_id id;

string& package_name; // Tracks id.package.name.
upstream_version package_version; // Original of id.package.version.
string& configuration; // Tracks id.configuration.

build_state state;

// Time of the last state change (the creation time initially).
//
timestamp_type timestamp;

// Present only if the state is 'tested'.
//
optional<result_status> status;

// Note that the logs are stored as std::string/TEXT which is Ok since
// they are UTF-8 and our database is UTF-8.
//
#pragma db section(results_section)
operation_results results;

#pragma db load(lazy) update(always)
odb::section results_section;

// Database mapping.
//
#pragma db member(id) id column("")

#pragma db member(package_name) transient
#pragma db member(package_version) \
set(this.package_version.init (this.id.package.version, (?)))
#pragma db member(configuration) transient

#pragma db member(results) id_column("") value_column("")

build (const build&) = delete;
build& operator= (const build&) = delete;

private:
friend class odb::access;
build ()
: package_name (id.package.name), configuration (id.configuration) {}
};
}

#endif // BREP_BUILD
Loading

0 comments on commit dbbc19b

Please sign in to comment.