...
 
Commits (4)
......@@ -18,3 +18,4 @@
/man
/tmp
/.env
/.vagrant
\ No newline at end of file
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
......@@ -10,3 +12,8 @@ Style/FrozenStringLiteralComment:
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb' # documentation
Metrics/ClassLength:
Exclude:
- 'lib/debci/api.rb' # documentation
......@@ -15,10 +15,6 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
......@@ -321,11 +317,16 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 260
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb'
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 299
Exclude:
- 'lib/debci/api.rb'
# Offense count: 2
Metrics/CyclomaticComplexity:
......
......@@ -5,6 +5,11 @@
VAGRANTFILE_API_VERSION = '2'.freeze
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = ENV['BOX'] || 'debian/stretch64'
# contrib has the vboxsf kernel module, which is needed for guest addition
config.vm.box = ENV['BOX'] || 'debian/contrib-stretch64'
config.vm.network 'forwarded_port', guest: 8080, host: 8080
config.vm.synced_folder '.', '/vagrant'
config.vm.provision 'shell', path: 'tools/vagrant_root.sh'
config.vm.provision 'shell', path: 'tools/vagrant_user.sh', privileged: false
end
require 'debci/api'
require 'debci/self_service'
require 'sinatra/content_for'
LISTING = <<~HTMLBLOCK.freeze
<!DOCTYPE html>
......@@ -48,6 +50,9 @@ app = Rack::Builder.new do
map '/api' do
run Debci::API
end
map '/self_service' do
run Debci::SelfService
end
end
run app
......@@ -2,6 +2,44 @@
## Setting up a development environment
There are two ways to setup the development environment:
* Manual Setup
* Vagrant
## Vagrant
### Prerequisites
* Vagrant: 2.2.4 https://www.vagrantup.com/
* VirtualBox: 6.0 https://www.virtualbox.org/
### Install the virtual machine
Run this at the same path where `VagrantFile` is
```
$ vagrant up
```
### Start debci
SSH into vagrant environment
```
$ vagrant ssh
```
Once inside vagrant, you can start run debci with the following commands
```
vagrant@stretch $ cd /vagrant
vagrant@stretch $ foreman start
```
Note: The other commands are the same as the ones mentioned in manual setup.
## Manual Setup
### Grab the dependencies and required software
Install the dependencies and build dependencies:
......
......@@ -5,6 +5,7 @@ require 'rdoc'
require 'securerandom'
require 'sinatra'
require "sinatra/namespace"
require "sinatra/content_for"
require 'time'
require 'debci'
......@@ -13,6 +14,7 @@ require 'debci/key'
class SelfDocAPI < Sinatra::Base
helpers Sinatra::ContentFor
get '/doc' do
@doc = self.class.doc
erb :doc
......@@ -243,8 +245,11 @@ module Debci
data.to_json
end
before '/test/:suite/:arch*'do
authenticate!
before '/test/:suite/:arch*' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
if not @user
authenticate!
end
@suite = params[:suite]
@arch = params[:arch]
if !Debci.config.arch_list.include?(arch)
......
require 'debci/api'
require 'debci/self_service'
run Debci::API
run Debci::SelfService
......@@ -123,6 +123,9 @@ module Debci
private
# yield_content should do nothing in the Debci::HTML context
def yield_content(template); end
def templates
@templates ||= {}
end
......
......@@ -38,6 +38,9 @@
<li><a href="/api/">API</a></li>
<li><a href="/data/">Data</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/self_service">Self Service</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
......@@ -70,5 +73,6 @@
<script type="text/javascript" src="<%= @root %>/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%= @root %>/app.js"></script>
<%= @footer %>
<%= yield_content :javascript %>
</body>
</html>
<div class="col-xs-12">
<h2>Welcome <%= @user %></h2>
</div>
<div id="self-test" class="col-xs-12">
<h2>Run Tests</h2>
<div class="form-group">
<label for="submit-json">Submit by JSON File</label>
<input type="file" id="submit-json">
<p class="help-block">You can get an initialized JSON by exporting one first.</p>
</div>
<form action="/self_service/test" method="post">
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="trigger">Trigger</label>
<input class="form-control" id="trigger" name="trigger">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="package">Package Name</label>
<input class="form-control" id="package" name="package">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="suite">Suite</label>
<select class="form-control" id="suite" name="suite">
<% @suites.each do |suite| %>
<option><%= suite %></option>
<% end %>
</select>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<label>Architecture</label>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<% @archs.each do |arch| %>
<label class="checkbox-inline">
<input name="<%= arch %>" type="checkbox"><%= arch %>
</label>
<% end %>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="pin-packages">Pin Packages</label>
<textarea id="pin-packages" class="form-control" rows="5" style="resize: vertical"
placeholder="src:bar, experimental"></textarea>
<p class="help-block">
Pin packages are packages that need to be obtained from the main suite that you selected.<br>
This is used e.g. to run tests on testing with a few packages from unstable, or on unstable with a few packages
from experimental.
</p>
<p class="help-block">
Format should be <code>package, ..., package, suite</code><br>
Examples:<br>
<ul>
<li><code>src:bar, unstable</code>: get all binaries built from bar from unstable</li>
<li><code>foo, src:bar, stable</code>: get foo and all binaries built from bar from stable</li>
</ul>
<strong>Note: each suite can be only present once. please seperate by line.</strong>
</p>
</div>
<button type="submit" name="submit" class="btn btn-default" autocomplete="off">
Submit
</button>
<button type="submit" name="export" class="btn btn-default" autocomplete="off">
Export Submission as JSON
</button>
</form>
</div>
<% content_for :javascript do %>
<script>
// $('#submit').on('click', function () {
// $btn = $(this).button('loading');
// const suite = $('#suite').val();
// const arch = $('#arch').val();
// const name = $('#package').val();
// $.post(`/api/v1/test/${suite}/${arch}/${name}`)
// .done(() => {
// $('#self-test').prepend(
// `<div class="alert alert-success" role="alert">submit test ${suite}/${arch}/${name} success</div>`
// );
// })
// .fail(() => {
// $('#self-test').prepend(
// `<div class="alert alert-danger" role="alert">submit test ${suite}/${arch}/${name} failed, please try again</div>`
// );
// })
// .always(() => {
// $('.alert').delay(4000).slideUp(200, function () {
// $(this).alert('close');
// });
// $btn.button('reset');
// })
// })
</script>
<% end %>
\ No newline at end of file
require 'sinatra'
module Debci
class SelfService < Sinatra::Base
helpers Sinatra::ContentFor
set :views, File.dirname(__FILE__) + '/html'
get '/' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
@suites = Debci.config.suite_list
@archs = Debci.config.arch_list
if @user
erb :self_service
else
# TODO: change to unauthenticated template
'UNAUTHENTICATED'
end
end
end
end
......@@ -21,4 +21,4 @@ esac
echo "I: Web UI at http://localhost:$port/"
echo "I: Hit Control+C to stop"
echo ""
exec rerun --no-notify --background --dir lib -p '**/*.rb' -- rackup --include lib --port="$port"
exec rerun --no-notify --background --dir lib -p '**/*.rb' -- rackup --include lib --port="$port" --host=0.0.0.0
#!/bin/bash
echo "Running as root"
export DEBIAN_FRONTEND=noninteractive
echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
apt-get -y update
apt-get -qqyt stretch-backports install autopkgtest
apt-get -qqy install make ruby git debootstrap
cd /vagrant
apt-get -qqy build-dep .
#!/bin/bash
echo "Running as user vagrant"
cd /vagrant
./tools/init-dev.sh
make
./bin/debci migrate
./bin/debci setup-chdist
echo "Development virtual machine is installed!"
\ No newline at end of file