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.
If you want to build and set up the dockers containers locally:
./build_locally.sh
# or
mvn clean install
# shut old services down and remove old images
docker-compose stop && docker-compose rm -f
# set containers up and follow logs
docker-compose up -d --remove-orphans && docker-compose logs -tfCheck 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.
Setup for Travis
- 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
- Create new repositories on Docker Hub for each mircoservice. Currently api-gateway, login-microservice, discovery-service and template-project.
- Log into
travis-ci.orgwith the github account where your fork is hosted (should be a public repository) - Activate the repository in
travis - Go to the settings of your travis repository.
- Under
Environment VariablessetDOCKER_USERandDOCKER_PASSwith your information. See here for details but use names as specified here. - Make a change, commit, push and see if
travisbuilds - If the build was successful, check your dockerhub account if the images appears
- Pull if from docker hub.
- The automatic pull to your server will be explained in the Update Images via Watchtower section.
- Use the
docker-compose.ymlfile from root and copy it onto the remote server - Run
docker compose up -dthere. Note: that it pulls per default the :latest version/tag of the container. Specify another version if you're working on a branch.
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/watchtowerWatchtower only updates running containers, therefore make sure the containers you want to update are already running.
-
Add new service as
modulein rootpom.xmlso 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.xmlas parent-POM, which adds the maven-docker-plugin and spring boot to your service. Thetemplate-projectshows how your new servicepom.xmlshould look -
Add service to
docker-compose.yml -
a new route for the api-gateway is added automatically, when your service is connected to eureka with the
@EnableDiscoveryClientAnnotation -
To use the configuration service, add your application name and the config service url to your bootstrap.yml file like this
spring:
application:
name: <application-name>
cloud:
config:
uri: http://config-service:8888
fail-fast: true
- Now you can create a config file (replacing your local application.yml) in
config-service/src/main/resources/shared. This file must be named like yourapplication nameinbootstrap.ymland must have the file ending.yml. Please note that config-service provides a standard configuration for every service inshared/application.yml. You only need to add those entries to your service configuration file, that are not already included in the standard configuration.
Once the API Gateway is set up via
cd api-gateway && mvn spring-boot:runordocker run -p8081:8081 uilab/api-gatewaythe documentation can be accessed throughhttp://localhost:8081/docs/api-guide.html
You need to install asciidoctor first. Then run
$ asciidoctor api-gateway/src/main/asciidoc/api-guide.adoc
$ open api-gateway/src/main/asciidoc/api-guide.html- With
sidecarthe route to a service is defined by itsspring.application.namein thebootstrap.propertiesoryml. Then the defined resources in the controllers can be accessed. Here is an example.
$ curl -D- -X GET localhost:8081/login/admin/admin- It is possible to see all current routings under
<gateway-url>/routes. See here for a working gateway server.
- Group
noname:http://82.165.207.147:8081/docs/api-guide.html - Group
sfindling:http://212.227.198.46:8081/docs/api-guide.html