This is a simple example that demonstrates how to write a microservice in Golang and deploy it on Giant Swarm. It pings an external API and caches the data in an Redis cache.
Check out the full tutorial here:
https://docs.giantswarm.io/guides/your-first-service/golang/
- Have a Giant Swarm account and the swarm CLI running. Request a free invite.
- Have Docker installed and running. You should be familiar with the basic Docker commands and how to handle Makefiles.
- Optional: If not in GNU/Linux environment you need boot2docker as well.
The service logic is implemented in main.go. It creates a webserver and on root request pings the openweather API, caches the result in Redis and extracts and returns the current weather for Cologne.
To run the two required containers locally you just have to do
$ make docker-build
$ make docker-run-redis
$ make docker-run
This
- builds the Go project into a linux binary
- creates a custom Docker image with the linux binary
- starts both the custom Docker container and a Redis container.
To test it on a Mac run something like: curl $(boot2docker ip):8080
, on Linux curl localhost:8080
should be sufficient.
To deploy this service on Giant Swarm you just have to do
$ make docker-push
$ swarm up
This
- uploads the Docker image to the Giant Swarm registry
- creates the service according to the definition in
swarm.json
- starts the service
To test it run something like: curl currentweather-YOURUSERNAME.gigantic.io
and replace YOURUSERNAME with your Giant Swarm username.
For all build and deploy details see the Makefile.
For further documentation and guides see the docs.
The weather data is provided by http://openweathermap.org