How to develop/update a docker microservice in a Git repo

Nik Canvin
NikCanvin
Published in
4 min readJun 12, 2020

--

Using a pre-existing ‘get-data’ microservice stored in a Git repo, to show an easy way to make a change, run/test it locally and push it back to Git.

Note: The microservice used as an example for this blog is ‘get-data’, which can get metrics data from sources like Git, Twitter and YouTube and return it as a JSON document: https://github.com/IBM/smarteradvocacy-get-data . It is used as part of a SmarterAdvocacy microservices solution, which periodically aggregates data from multiple sources, anlyses and reports the results — to help measure and improve efforts made to advocate various bits of software, enabling greater success for that software. A BLOG about SmarterAdvocacy itself, will folllow soon.

meanwhile, here are the 4 simple steps to follow:

the 4 simple steps to develop/update a microservice in a github repo

step1: get the code

If you’re a commiter to the Git repo then:

else if you’re not a commiter, you’ll first have to ‘fork’ the repo

  • Fork the repo in Git
  • CD to the local directory to work in
  • git clone <your-git-fork>

step2: get the microservice running locally in docker and ready to accept code changes

  • install for Codewind is simple (as a plugin in your VSCode, Eclipse or Intellij IDE)
  • then in your IDE (VSCode in my case) under Codewind/local, click the icon to ‘Add Existing Project’:
Codewind panel showing existing projects imported into Codewind and buttons to create a new blank project from a template, or add existing project (as we’re doiong in this blog)
  • select the cloned project on your machine, from step1 above:
  • check that Codewind has determined the correct Type and Language, then click ‘Yes’:

then simply WAIT, while Codewind automatically does the rest:

1…auto docker builds the microservice (docker build logs are a click away):

Codewind panel showing Docker build success

2…auto docker runs the microservice locally:

Codewind panel showing Application Endpoint clickable url link

All DONE .. to check, you can then click the ‘Application Endpoint’ link, to see it running (here’s the index.html of my ‘get-data’ microservice):

demo microservice running in a local Docker container

..so far, pretty easy stuff!

step3: make a code change, respin the docker build/run/test:

Codewind does this magically for you. All you need to do is save a code change and Codewind will automatically spot the change rebuild the docker container/application as required and restart the new modified microservice.

Simple example, changing some text in ‘index.html’ (and making it ‘red’ to help you spot it below) and SAVE:

demo code update to ‘index.html’ in my VSCode IDE

and simply click the application endpoint again:

demo changes shown in index.html, automatically running in a local Docker container

Once you’re happy with all your code changes, you’ll be ready to get them merged into the original Git repo for everyone else on the project to get:

step4: push your code back to the original Git repo

If you’re a commiter to the Git repo then:

  • git commit -am “example modification to html”
  • git push origin master

else if you’re not a commiter, you’ll first have to ‘fork’ the repo

  • git commit -am “example modification to html”
  • git push origin master
  • raise a Pull Request from your fork, into the target Git repo.

and we’re DONE, thanks for reading.

--

--