Devops Implementation -CI CD - devops

I have my frontend in Angular. Backend in Java-Spring MVC. Do you recommend a separate docker image for both or a single composite image combining both to be deployed in production?

If your front-end requires a separate process to run (and I read your input like it does), then you should have 2 separate images.
Rule of thumb - you can have only one main process per image. If you find yourself in a situation where you need more than one, you need to separate this into another image.

Related

How many docker containers do i need, and how do i sperate code between them?

I'm in the process of designing a web-service hosted with Google App Engine comprised of three parts, a client website (or more), a simple CMS I designed to edit and view the content of that website, and lastly a server component to communicate between these two services and the database. I am new to docker and currently doing research to figure out how exactly to set up my containers along with the structure of my project.
I would like each of these to be a separate service, and therefor put them in different containers. From my research it seems perfectly possible to put them in separate containers and still have them communicate, but is this the optimal solution? Also given that in the future I might want to scale up so that my backed can supply multiple different frontends all managed from the same CMS.
tldr:
How should I best structure my web-service with docker, as well as assuming my back-end supplies more than one front end managed from a CMS.
Any suggestion for tools, or design patterns that make my life easier are welcome!
Personally, I don't like to think of designing whatever in terms of containers. Containers should be good for deployment process, for their main goal.
If you keep your logic in separate components/services you'll be able to combine them within containers in many different ways.
Once you have criteria what suits your product requirements (performance, price, security etc) you'll configure your docker images in the way you prefer.
So my advise is focus on design of your application first. Start from the number of solutions you have, provide a dockerfile for each one and then see what you will have to change.

Microservice instances (Dockerized) with slightly different parameters in Kubernetes

I’m somewhat new to Kubernetes and not sure the standard way to do this. I’d like to have many instances of a single microservice, but with each of the containers parameterized slightly differently. (Perhaps an environment variable passed to the container that’s different for each instance, as specified in the container spec of the .yaml file?)
It seems like a single deployment with multiple replicas wouldn’t work. Yet, having n different deployments with very slightly different .yaml files seems a bit redundant. Is there some sort of templating solution perhaps?
Or should each microservice be identical and seek out its parameters from a central service?
I realize this could be interpreted as an “opinion question” but I am looking for typical solutions.
There are definitely several ways of doing it. One popular option is to use Helm. Helm lets you define kubernetes manifests using Go templates, and package them on a single unit called a Helm Chart. Later on you can install this Chart (install is what Helm calls to save these manifests in the Kubernetes API). When installing the Helm Chart, you can pass arguments that will be used when rendering the templates. That way you can re-use pretty much everything, and just replace the significant bits of your manifests: Deployments, Services, etc.
There are plenty of Helm charts available as open sources projects, that you can use as an example on how to create your own Chart.
And many useful guides on how to create your first Helm Chart.
Here you can find the official docs on developing your own Charts.
As an option you can use StatefulSet with InitContainers plus ConfigMap.
Statefulset will guarantee you proper naming and order.
ConfigMap will let you store fine-grained information like individual properties or coarse-grained information like entire config files.
Configuration data can be consumed in pods in a variety of ways. ConfigMaps can be used to:
1) Populate the values of environment variables
2) Set command-line arguments in a container
3) Populate config files in a volume
For the begging you can review Kubernetes – StatefulSets article where you can find a good explanation on how this pieces work together and inspect prepared example on how to deploy containers from the same image but with different properties.

How to know which docker base image will be right one for the requirement from all images of DockerHub?

How can I know which Docker Base image will be the best one for the requirement out of all the related images available in DockerHub?
Thank you.
This is a question that doesn't have an exact answer: what base image to use will depend on multiple factors, and even after considering those, you'll probably have multiple alternatives.
Here's an article that talks about this same question, and goes into detail about some tips when choosing. The conclusion ends up being:
To summarize, selecting the appropriate OS base image depends on the
following factors:
What technologies are used to build the application being containerized?
What is the intended target platform on which these images will run?
What is the desirable size of the application image? (including all layers and base images)
Pure Taste!
Still, always make sure to check DockerHub for an existing image of the requirements you're looking to solve. You may be surprised and find exactly what you need!

Combining interchangable docker applications

I want to use multiple individual docker files/containers in one combined application. Suppose I have three docker containers. Two containers, Framework A and Framework B, that process data in a two different ways, but give the same output. The other container, main, will process that output. Now in my application I would like to use either Framework A or Framework B, or perhaps both.
I looked at a solution to combine multiple docker containers, but this does not seem to be supported by docker and is also not exactly what I want. So I looked into Docker volumes, but I don't really want to 'write' or store the data from the two individual frameworks, just pass it to the third container. I also read about docker-compose, but again this does not seem to be exactly what I want.
Suppose that in the main container I have some python code, that will call some other code from either Framework A or Framework B, and data then gets passed from either of those two to main (a python object, array or something similar). What would be the best way to achieve this? And is this easily interchangeable, given that the outputs of framework A and framework B are the same?

Should I use Dockerfiles or image commits?

I'm a little bit confused about these two options. They appear to be related. However, they're not really compatible.
For example, it seems that using Dockerfiles means that you shouldn't really be committing to images, because you should really just track the Dockerfile in git and make changes to that. Then there's no ambiguity about what is authoritative.
However, image commits seem really nice. It's so great that you could just modify a container directly and tag the changes to create another image. I understand that you can even get something like a filesystem diff from an image commit history. Awesome. But then you shouldn't use Dockerfiles. Otherwise, if you made an image commit, you'd have to go back to your Dockerfile and make some change which represents what you did.
So I'm torn. I love the idea of image commits: that you don't have to represent your image state in a Dockerfile -- you can just track it directly. But I'm uneasy about giving up the idea of some kind of manifest file which gives you a quick overview of what's in an image. It's also disconcerting to see two features in the same software package which seem to be incompatible.
Does anyone have any thoughts on this? Is it considered bad practice to use image commits? Or should I just let go of my attachment to manifest files from my Puppet days? What should I do?
Update:
To all those who think this is an opinion-based question, I'm not so sure. There are some subjective qualities to it, but I think it's mostly an objective question. Furthermore, I believe a good discussion on this topic will be informative.
In the end, I hope that anyone reading this post will come away with a better understanding of how Dockerfiles and image commits relate to each other.
Update - 2017/7/18:
I just recently discovered a legitimate use for image commits. We just set up a CI pipeline at our company and, during one stage of the pipeline, our app tests are run inside of a container. We need to retrieve the coverage results from the exited container after the test runner process has generated them (in the container's file system) and the container has stopped running. We use image commits to do this by committing the stopped container to create a new image and then running commands which display and dump the coverage file to stdout. So it's handy to have this. Apart from this very specific case, we use Dockerfiles to define our environments.
Dockerfiles are a tool that is used to create images.
The result of running docker build . is an image with a commit so it's not possible to use a Dockerfile with out creating a commit. The question is should you update the image by hand each time anything changes and thus doom yourself to the curse of the golden image?
The curse of the golden image is a terrible curse cast upon people who must continue living with a buggy security hole ridden base image to run their software on because the person who created it was long ago devoured by the ancient ones (or moved on to a new job) and nobody knows where they got the version of imagemagic that went into that image. and is the only thing that will link against the c++ module that was provided by that consultant the boss's son hired three years ago, and anyway it doesn't matter because even if you figured out where imagemagic came from the version of libstdc++ used by the JNI calls in the support tool that intern with the long hair created only exists in an unsupported version of ubuntu anyway.
Knowing both solutions advantages and inconvenient is a good start. Because a mix of the two is probably a valid way to go.
Con: avoid the golden image dead end:
Using only commits is bad if you lose track of how to rebuild your image. You don't want to be in the state that you can't rebuild the image. This final state is here called the golden image as the image will be your only reference, starting point and ending point at each stage. If you loose it, you'll be in a lot of trouble since you can't rebuild it. The fatal dead end is that one day you'll need to rebuild a new one (because all system lib are obsolete for instance), and you'll have no idea what to install... ending in big loss of time.
As a side note, it's probable that using commits over commits would be nicer if the history log would be easily usable (consult diffs, and repeat them on other images) as it is in git: you'll notice that git don't have this dilemma.
Pro: slick upgrades to distribute
In the other hand, layering commits has some considerable advantage in term of distributed upgrades and thus in bandwidth and deploy time. If you start to handle docker images as a baker is handling pancakes (which is precisely what docker permits), or want to deploy tests version instantly, you'll be happier to send just a small update in the form of a small commit rather a whole new image. Especially when having continuous integration for your customers where bug fixes should be deployed soon and often.
Try to get the best of two worlds:
In these type of scenario, you'll probably want to tag major version of your images and they should come from Dockerfiles. And you can provide continuous integration versions thanks to commits based on the tagged version. This mitigates advantages and inconvenients of Dockerfiles and layering commits scenario. Here, the key point is that you never stop keeping track of your images by limiting the number of commits you'll allow to do on them.
So I guess it depends on your scenario, and you probably shouldn't try to find a single rule. However, there might be some real dead-ends you should really avoid (as ending up with a "golden image" scenario) whatever the solution.

Resources