Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkoo committed Oct 27, 2017
2 parents d6d3359 + d88a28f commit de7a63c
Show file tree
Hide file tree
Showing 49 changed files with 1,945 additions and 277 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ language: java
jdk:
- oraclejdk8
sudo: false
script: ./mvnw clean verify
script: ./mvnw clean verify cobertura:cobertura-integration-test

after_success:
- bash <(curl -s https://codecov.io/bash)
104 changes: 15 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,29 @@
# Boxitory

is repository for Vagrant's Virtual Machine boxes, which can manage box versions and provides *Vagrant* compatible http interface.
is repository for Vagrant's Virtual Machine boxes, which can manage box versions and provides *Vagrant* compatible http interface. Boxes are stored on local filesystem.

Download [Latest release](https://github.com/sparkoo/boxitory/releases/latest)

For more info how it works, how to configure, ... [See Wiki](https://github.com/sparkoo/boxitory/wiki)

## Build & run

`./mvnw install && java -jar target/boxitory-{version}.jar`
```
$ ./mvnw install && java -jar target/boxitory-{version}.jar
```
or
```
$ ./mvnw spring-boot:run
```

By default, http server will start on port *8083*.

#### Build status (travis-ci)

devel [![Build Status](https://travis-ci.org/sparkoo/boxitory.svg?branch=devel)](https://travis-ci.org/sparkoo/boxitory)

master: [![Build Status](https://travis-ci.org/sparkoo/boxitory.svg?branch=master)](https://travis-ci.org/sparkoo/boxitory)

## How it works

*Boxitory* currently implements just filesystem box provider. That requires strict folder structure.
devel [![Build Status](https://travis-ci.org/sparkoo/boxitory.svg?branch=devel)](https://travis-ci.org/sparkoo/boxitory)
[![codecov](https://codecov.io/gh/sparkoo/boxitory/branch/devel/graph/badge.svg)](https://codecov.io/gh/sparkoo/boxitory)

### Box files on filesystem

There must be one home folder for all boxes with subfolders for each box type. Individial box versions must be named `{name}_{version}_{provider}.box`.

See example below:
```
$ tree test_repository/
test_repository/
├── f25
│   ├── f25_1_virtualbox.box
│   └── f25_2_virtualbox.box
├── f26
│   ├── f26_1_virtualbox.box
│   ├── f26_2_virtualbox.box
│   └── f26_3_virtualbox.box
```

### Http interface

Server starts at port *8083* and boxes can be requested on `http://hostname:port/box_name` for example:
```
$ curl http://localhost:8083/f26
{
"name": "f26",
"description": "f26",
"versions": [
{
"version": "1",
"providers": [
{
"url": "sftp://my_box_server:/tmp/test_repository/f26/f26_1_virtualbox.box",
"name": "virtualbox"
}
]
},
{
"version": "2",
"providers": [
{
"url": "sftp://my_box_server:/tmp/test_repository/f26/f26_2_virtualbox.box",
"name": "virtualbox"
}
]
},
]
}
```
master: [![Build Status](https://travis-ci.org/sparkoo/boxitory.svg?branch=master)](https://travis-ci.org/sparkoo/boxitory)

## Configuration

### Options
* `box.home`
* path where to find boxes
* in example above, it will be set to `/tmp/test_repository`
* **default value**: `.`
* `box.prefix`
* prefix for the output json, that is prepend before absolute local path of the box
* do define for example protocol or server, where boxes are placed
* e.g.: `sftp://my_box_server:`
* **default value**: *empty*
* `box.sort_desc`
* boolean value `true|false`
* when default or `false`, boxes are sorted by version in ascending order
* when `true`, boxes are sorted by version in descending order
* default value: `false`
* `box.checksum`
* string value: `disabled|md5|sha1|sha256`
* default value: `disabled`
* when default or `disabled` boxes output json not contains properties `checksumType` and `checksum`
* when `md5|sha1|sha256` boxes output json contains properties `checksumType` and `checksum` with coresponding values
### Advanced Options
* `box.checksum_buffer_size`
* Box file is loaded to this buffer to calculate box checksums
* default value: `1024`

### How to configuration
Configuration can be provided by `application.properties` file on classpath
```
# application.properties
box.home=/tmp/test_repository
box.prefix=sftp://my_box_server:
```
or as command line arguments `java -jar -Dbox.home=/tmp/test_repository target/boxsitory-${version}.jar`
6 changes: 5 additions & 1 deletion application.properties_template
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
box.home=/custom/test/repository/path
box.host_prefix=sftp://localhost:
server.port=8083
box.checksum=disabled

box.sort_desc=false

box.checksum=md5
box.checksum_buffer_size=1024
box.checksum_persist=true
74 changes: 66 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cz.sparko.boxitory</groupId>
<artifactId>boxitory</artifactId>
<version>1.2.0</version>
<version>1.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>boxitory</name>
<description>Demo project for Spring Boot</description>
<description>Vagrant box repository</description>
<url>https://github.com/sparkoo/boxitory</url>
<developers>
<developer>
<name>sparkoo</name>
<url>https://github.com/sparkoo</url>
</developer>
</developers>
<contributors>
<contributor>
<name>D3ryk</name>
<url>https://github.com/D3ryk</url>
</contributor>
</contributors>
<organization>
<name>sparkoo</name>
<url>https://github.com/sparkoo</url>
</organization>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
<relativePath/> <!-- lookup parent from repository -->
</parent>

<issueManagement>
Expand All @@ -34,8 +52,8 @@
<url>https://github.com/sparkoo/boxitory</url>
<connection>scm:git:git://github.com/sparkoo/boxitory.git</connection>
<developerConnection>scm:git:[email protected]:sparkoo/boxitory.git</developerConnection>
<tag>v1.2.0</tag>
</scm>
<tag>HEAD</tag>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -94,8 +112,48 @@
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<instrumentation>
<ignoreTrivial>true</ignoreTrivial>
</instrumentation>
<check/>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludedGroups>e2e</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<groups>e2e</groups>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
36 changes: 32 additions & 4 deletions src/main/java/cz/sparko/boxitory/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import cz.sparko.boxitory.conf.AppProperties;
import cz.sparko.boxitory.factory.HashServiceFactory;
import cz.sparko.boxitory.service.BoxRepository;
import cz.sparko.boxitory.service.FilesystemBoxRepository;
import cz.sparko.boxitory.service.DescriptionProvider;
import cz.sparko.boxitory.service.filesystem.FilesystemBoxRepository;
import cz.sparko.boxitory.service.filesystem.FilesystemDescriptionProvider;
import cz.sparko.boxitory.service.filesystem.FilesystemHashStore;
import cz.sparko.boxitory.service.HashService;
import cz.sparko.boxitory.service.HashStore;
import cz.sparko.boxitory.service.noop.NoopHashStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -21,8 +26,31 @@ public static void main(String[] args) {

@Bean
@Autowired
public BoxRepository boxRepository(AppProperties appProperties) throws NoSuchAlgorithmException {
HashService hashService = HashServiceFactory.createHashService(appProperties);
return new FilesystemBoxRepository(appProperties, hashService);
public BoxRepository boxRepository(AppProperties appProperties,
HashService hashService,
DescriptionProvider descriptionProvider) {
return new FilesystemBoxRepository(appProperties, hashService, descriptionProvider);
}

@Bean
@Autowired
public DescriptionProvider descriptionProvider(AppProperties appProperties) {
return new FilesystemDescriptionProvider(appProperties.getHome());
}

@Bean
@Autowired
public HashService hashService(AppProperties appProperties, HashStore hashStore) throws NoSuchAlgorithmException {
return HashServiceFactory.createHashService(appProperties, hashStore);
}

@Bean
@Autowired
public HashStore hashStore(AppProperties appProperties) {
if (appProperties.isChecksum_persist()) {
return new FilesystemHashStore();
} else {
return new NoopHashStore();
}
}
}
17 changes: 14 additions & 3 deletions src/main/java/cz/sparko/boxitory/conf/AppProperties.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.sparko.boxitory.conf;

import cz.sparko.boxitory.service.HashService.HashAlgorithm;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

Expand All @@ -8,8 +9,10 @@
public class AppProperties {
private String home = ".";
private String host_prefix = "";
private String checksum = "disabled";
private boolean sort_desc = false;

private HashAlgorithm checksum = HashAlgorithm.DISABLED;
private boolean checksum_persist = true;
private int checksum_buffer_size = 1024;

public String getHome() {
Expand All @@ -24,14 +27,18 @@ public boolean isSort_desc() {
return sort_desc;
}

public String getChecksum() {
public HashAlgorithm getChecksum() {
return checksum;
}

public int getChecksum_buffer_size() {
return checksum_buffer_size;
}

public boolean isChecksum_persist() {
return checksum_persist;
}

public void setSort_desc(boolean sort_desc) {
this.sort_desc = sort_desc;
}
Expand All @@ -44,11 +51,15 @@ public void setHost_prefix(String host_prefix) {
this.host_prefix = host_prefix;
}

public void setChecksum(String checksum) {
public void setChecksum(HashAlgorithm checksum) {
this.checksum = checksum;
}

public void setChecksum_buffer_size(int checksum_buffer_size) {
this.checksum_buffer_size = checksum_buffer_size;
}

public void setChecksum_persist(boolean checksum_persist) {
this.checksum_persist = checksum_persist;
}
}
11 changes: 7 additions & 4 deletions src/main/java/cz/sparko/boxitory/conf/NotFoundException.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cz.sparko.boxitory.conf;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.client.HttpClientErrorException;

@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {
public class NotFoundException extends HttpClientErrorException {
public NotFoundException(String message) {
super(message);
super(HttpStatus.NOT_FOUND, message);
}

public static NotFoundException boxNotFound(String boxName) {
return new NotFoundException("box [" + boxName + "] does not exist");
}
}
Loading

0 comments on commit de7a63c

Please sign in to comment.