ui-lab
This is a template for creating a prototype of a cloud and sass solution with Spring Cloud and Docker. This project is part of the masters course Graphical user interfaces.
Configuration
Local setup
If you want to build and set up the dockers containers locally:
# build all local docker images
export DOCKER_USER=<your group name>
export TAG=latest
./build_locally.sh
# Note the docker-compose.yml also needs the ENV vars
docker-compose up -d
Check curl localhost:8081/docs/api-guide.html
, which can take some time
until everything is set up. Consider docker logs -tf <container-hash>
for the logs.
Travis
Setup for- Fork this repository
- Create a branch from master for changes you want to push back to the template (e.g. OAuth)
- Set up a Docker Hub account
- Log into
travis-ci.org
with the github account where your fork is hosted (should be a public repository) - Activate the repository in
travis
- Edit
.travis.yml
file and replaceGROUP
env with the name of your group, which should be the same like your docker hub account. - Create secrets: e.g
travis encrypt DOCKER_EMAIL=mail@example.com
and replace them in.travis.yml
. See here for details. - Make a change, commit, push and see if
travis
builds - If the build was successful, check your dockerhub account if the images appears
- Pull if from docker hub.
- The Push to your server will be explained in the Add webhooks section.
Setup for server
Intial setup
- Set up ENV Vars
$ export DOCKER_USER="<your group name>"
$ export TAG=latest
- Use the
docker-compose.yml
file from root and copy it onto the remote server - Run
docker compose up -d
there. Note: that it pulls per default the :latest version/tag of the container. Specify another version if you're working on a branch.
Update Images via Watchtower
Another alternative is Watchtower. Watchtower runs as an docker container and checks all few minutes, if a new version of your running containers is available. If a new version is available, watchtower automatically pulls it and restarts the container.
To start Watchtower for watching all running containers use (without arguments):
$ docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock centurylink/watchtower
Watchtower only updates running containers, therefore make sure the containers you want to update are already running.
Steps for adding a new service
- Add new service as
module
in rootpom.xml
so the travis build will still work. - In the POM of your new service add the following:
<parent>
<groupId>de.hska.uilab</groupId>
<artifactId>ui-lab</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
- This adds the root
pom.xml
as parent-POM, which adds the maven-docker-plugin and spring boot to your service. Thetemplate-project
shows how your new servicepom.xml
should look - Add service to
docker-compose.yml
- Add a new route in
application.yml
of the api-gateway - Add the hook url to the image at docker hub or initially run the docker container of the service on your server with Watchtower
Documentation of API Gateway
With running Spring container
Once the API Gateway is set up via
cd api-gateway && mvn spring-boot:run
ordocker run -p8081:8081 <your group name>/api-gateway
the documentation can be accessed throughhttp://localhost:8081/docs/api-guide.html
Statically
How to compile the api gateway proposal
You need to install asciidoctor first. Then run
# compile
asciidoctor api-gateway/src/main/asciidoc/api-guide.adoc
# open it
open api-gateway/src/main/asciidoc/api-guide.html
Routing
- With
sidecar
the route to a service is defined by itsspring.application.name
in thebootstrap.properties
oryml
. Then the defined resources in the controllers can be accessed. Here is an example.
curl -D- -X GET localhost:8081/login/login/admin/admin