How to develop/update a docker microservice in a Git repo
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:
step1: get the code
If you’re a commiter to the Git repo then:
- CD to the local directory to work in
- git clone https://github.com/IBM/smarteradvocacy-get-data.git
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’:
- 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):
2…auto docker runs the microservice locally:
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):
..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:
and simply click the application endpoint again:
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.