Directory structure for project with Dockerfile, Jekinsfile, Kubernetes deployment yaml, pip requirements.txt, and test scripts?

7/26/2017

Would the following directory structure work?

The goal is to have Jenkins trigger off GitHub commits and run Multi-branch Pipelines that build and test containers. (I have everything running on Kubernetes, including Jenkins)

/project
  .git
  README.md
  Jenkinsfile
  /docker_image_1
    Dockerfile
    app1.py
    requirements.txt
    /unit_tests
      unit_test1.py
      unit_test2.py
  /docker_image_2
    Dockerfile
    app2.py
    requirements.txt
    /unit_tests
      unit_test1.py
      unit_test2.py
  /k8s
    /dev
      deployment.yaml
    /production
      deployment.yaml
  /component_tests
    component_tests.py
  1. Is the k8s folder that has the deployment.yamls in the right place?
  2. Are the test folders in good locations? The tests in "component_tests" will ideally be doing more end-to-end integrated testing that involve multiple containers
  3. I see a lot of repos have Jenkins file and Dockerfile in the same directory level. What are the pros and cons of that?
-- gunit
docker
jenkins
jenkins-pipeline
kubernetes
pip

2 Answers

7/26/2017

There's no good answer to this question currently.

Kubernetes provides a standard API for deployment, but as a technology it relies on additional 3rd party tooling manage the build part of the ALM workflow. There a lots of options available for turning your source code into a container running on Kubernetes. Each has it's own consequences for how your source code is organised and how a deployment might be invoked from a CI/CD server like Jenkins.

I provide the following collection of options for your consideration, roughly categorized. Represents my current evaluation list.

"Platform as a service" tools

Tooling the manages the entire ALM lifecycle of your code. Powerful but more complex and opinionated.

Build and deploy tools

Tools useful for the code/test/code/retest workflow common during development. Can also be invoked from Jenkins to abstract your build process.

YAML templating tools

The kubernetes YAML was never designed to be used by human beings. Several initatives to make this process simpler and more standardized.

Deployment monitoring tools

These tools have conventions where they expect to find Kubernetes manifest files (or helm charts) located in your source code repository.

CI/CD tools with k8s support

-- Mark O'Connor
Source: StackOverflow

7/26/2017

This is really left much to your preference. In our projects we tend to split services into separate repositories not subfolders, but we also had a case where we had a bunch of Scala microserviced managed in similar way (although dockers were built with sbt plugin for docker)

One big advice I would give you is that in the long run managing your kubernetes manifests like that might become serious pain in the back. I went through this, and my suggestion is to use helm charts from day one.

I assume that your "component_tests" are end-to-end tests. Other then naming I see no problem with that. For cases where we test solutions that span multiple repos we keep them in a separate repo as well though.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow