Template for running Ruby/Sinatra microservices
Extend the semtech/mu-ruby-template
and set a maintainer. That's it.
Configure your entrypoint through the environment variable APP_ENTRYPOINT
(default: web.rb
). You can use the Gemfile as you would expect.
FROM semtech/mu-ruby-template:1.2.0-ruby2.1
MAINTAINER Erika Pauwels <[email protected]>
# ONBUILD of mu-ruby-template takes care of everything
The SPARQL endpoint can be configured through the MU_SPARQL_ENDPOINT
environment variable. By default this is set to http://database:8890/sparql
. In that case the triple store used in the backend should be linked to the login service container as database
.
The MU_APPLICATION_GRAPH
environment variable specifies the graph in the triple store the microservice will work in. By default this is set to http://mu.semte.ch/application
. The graph name can be used in the service via settings.graph
.
To use the template while developing your app, start a container in development mode with your code folder mounted in /app
:
docker run --volume /path/to/your/code:/app
-e RACK_ENV=development
-d semtech/mu-ruby-template:1.2.0-ruby2.1
Changes will be automatically picked up by Sinatra.
The template provides the user with several helper methods.
The template provides a log
object to the user for logging. Just do log.info "Hello world"
. The log level can be set through the LOG_LEVEL
environment variable (default: info
, values: debug
, info
, warn
, error
, fatal
).
Logs are written to the /logs
directory in the docker container.
Generate a random UUID (String).
Get the session id from the request headers.
Get the rewrite URL from the request headers.
Validate whether the Content-Type header contains the JSONAPI Content-Type. Returns a 400
otherwise.
Validate whether the type specified in the JSON data is equal to the expected type. Returns a 409
otherwise.
Returns a JSONAPI compliant error response with the given status code (default: 400
).
Executes the given SPARQL select query.
Executes the given SPARQL update query.
Executes a SPARQL query to update the modification date of the given subject URI (string). The date defaults to now.
To test your app, run the container with RACK_ENV
set to test
. All rspec tests matching *_spec.rb
in spec/
and its subdirectories will be executed.
docker run --rm -e RACK_ENV=test microservice-image
To run the tests while developing, start an interactive container in the test enviroment with your code folder mounted in /app
:
docker run --volume /path/to/your/code:/app
-e RACK_ENV=test
-it semtech/mu-ruby-template:1.2.0-ruby2.1 /bin/bash
You can now run your tests inside the container with:
bundle install
rspec -c