This repo is created with a sample go application deployed as a microservices in containers using Docker by provisioning an compute engine instance in Google Cloud Platform.
This is a sample Go application which connects to Redis. The app increments a counter on an incoming request.
- Use
make buildto compile the binary. - Set the environment variables:
DEMO_APP_ADDR: Address where the app should listen toDEMO_REDIS_ADDR: Address where Redis is running
-
Create a
Dockerfilefor the app. -
Create a
docker-compose.ymlfor the app which includesredisservice, with the data directory ofredismounted at/datain your VM.appservice running with port8000exposed to the host.
-
Write a bash script that creates and boots Vagrant box with Ubuntu.
-
Using Ansible provision the VM to:
- Setup hostname of VM as
demo-ops - Create a user
demo - Configure
sysctlfor sane defaults. For eg: increasing open files limit. Configure a variety ofsysctlsettings to make the VM a production grade one. - Set the system's timezone to "Asia/Kolkata"
- Install Docker and Docker-Compose
- Configure Docker Daemon to have sane defaults. For eg: to keep logs size in check.
- Deploy the
docker-compose.ymlin/etc/demo-opsand start the services
- Setup hostname of VM as
.
.
[Go application & redis] << docker-compose << Docker << Compute Engine << Ansible & Vagrant << Google Cloud Platform.
- python >= 2.6
- google-auth >= 1.3.0
- ruby
- Vagrant
- Ansible Created and added SSH public keys to GCP project metadata Created service account with a JSON key.
- I choose GCP to deploy this application.
- For server deployment I have two options - any one can be used:
- One using vagrant - bash script (
gcp_instance_vagrant.sh) - Other using Ansible - (
gcp_instance.yml) - BONUS
- One using vagrant - bash script (
- Provisioning server with ansible - basically configuring server - (
gcp_post_deployment.yml) - Attached
Dockerfilecreated for application. - Attached
docker-compose.ymlwill build image and deploy application as container in the provisioned server (demo-ops).
e_vishnu55@demo-ops:~$ curl http://localhost:8000
welcome to api 1
e_vishnu55@demo-ops:~$ curl http://localhost:8000
welcome to api 2
e_vishnu55@demo-ops:~$ curl http://localhost:8000
welcome to api 3
e_vishnu55@demo-ops:~$