• Jan 23, 2015
This weekend is the Gopher Gala the world’s first Go(lang) distributed hackathon. As Golang is our primary and beloved language we figured it’s a perfect timing to show how easy it is to deploy Go code with Docker and a free account on Giant Swarm.
If you have read a bit through our documentation, you know our famous CurrentWeather tutorial using NodeJS. Here is the adaption for Go. Find the source on GitHub:
The example queries the Openweather API and, to be a good citizen, caches the data in a Redis cache:
Have a look at the main.go file for the application code.
The great thing about Go is that you can create small self-contained independent binaries and deploy them with small Docker containers. We are using the official busybox image with just 2.5 MB in size. Together with our application logic the whole image is only 12 MB!
To build and link the Docker containers we leverage docker-compose:
$ docker-compose up
If you want to make sure the image is built freshly, use make docker-build
before.
To deploy and run it on Giant Swarm is just as easy. We made a Makefile target:
$ make swarm-up
which uploads your custom Docker image and starts your application with your custom container and redis container. Wait till it reports with up and head over to http://currentweather-demo.gigantic.io/
. Done!
To find out more about that check out our Docs especially the possible configurations in our swarm.json.
{
"name": "currentweather",
"components": {
"webserver": {
"image": "registry.giantswarm.io/$GIANTSWARM_LOGIN_NAME/currentweather-go:latest",
"ports": [8080],
"links": [
{
"component": "redis",
"target_port": 6379
}
],
"domains": {
"8080": "currentweather-$GIANTSWARM_LOGIN_NAME.gigantic.io"
}
},
"redis": {
"image": "redis:latest",
"ports": [6379]
}
}
}
Building small self-contained apps has never been easier thanks to Docker and Golang. We at Giant Swarm try to make the next steps just as easy.
So whether you are taking part at the Gopher Gala or just want to give Go a try: check out our example and start programming Go. And while your at it request your free invite and deploy and run your application in the cloud within minutes.
These Stories on Docker
With Docker’s 2nd birthday coming up soon, this blog will talk about what Docker has changed for wider developer community.
Building a more advanced microservice app that analyzes the content of a Slack donethis channel and keeps a scoreboard with the total number of todos each team member completed
I got my blog running on Giant Swarm, first I tried Ghost, then moved to Wordpress. Learn how to do this yourself.
We empower platform teams to provide internal developer platforms that fuel innovation and fast-paced growth.
GET IN TOUCH
General: hello@giantswarm.io
CERTIFIED SERVICE PROVIDER
No Comments Yet
Let us know what you think