GitLab CI build sub-projects and deploy them to kubernetes separately

3/22/2017

If I have a GitLab project, which contains several sub-folders:

  • two with java code (from java:alpine, to compile with maven and build containers)
  • one with nginx config (from openresty:alpine, to build a web server container)

Every of sub-projects has a Dockerfile, deployment.yml, and gitlab-ci.yml.

deployment.yml is similar for every of sub-folders in the project, as all the sub-projects results to a single multi-container kubernetes pod.

How can I set up this project to build and deploy to kubernetes only the container, which I edited by the last commit?

-- cardinal-gray
continuous-deployment
continuous-integration
gitlab
gitlab-ci
kubernetes

1 Answer

4/3/2017

I used a dirty hack like setting several build blocks in .gitlab-ci.yml for every sub-project and setting for every on them only parameter:

maven-build-akka:
  image: maven:3-jdk-8
  stage: build
  only:
    - /^akka-.*$/
  script:
    - cd akka
    - mvn package -B --settings ../settings.xml
  artifacts:
    paths:
      - akka/target/*.jar

And so for docker build stage.

After that, if I push a tag like akka-1.0.3, appropriate pipeline jobs would be launched.

But, there's an issue with only one name for images in GitLab CI registry for a single project, so you should push images somewhere else (GCR, etc.)

-- cardinal-gray
Source: StackOverflow