GitLab CI review enviroment with docker

So environment deploy on feature branch for review before merge is great option. I have 10+ projects with similar structure and same docker image. There is gulp for front-end and php framework for backend.
I made a little changes in .gitlab-ci.yml:

  stage: deploy
    - rsync -av --delete httpdocs/ /home/gitlab-runner/dev_env/$CI_BUILD_REF_NAME.$CI_PROJECT_NAME.$CI_PROJECT_NAMESPACE
    name: review/$CI_BUILD_REF_NAME
    - branches
    - master

And i configured nginx for loading folder for every subdomain. Thats work great for reviewing fronted part.
But i want to use docker for backend part. So i need somehow to start docker on same server where gitlab is. Then i need to hold all port generation and maybe nginx redirect routine. And last part, after merge or after few days i need to romove review docker.

  • Cannot delete files on docker host
  • Using custom shell script as docker entrypoint
  • Ssh connect error - not a valid identifier
  • Rubygems update fails on strange ruby versions
  • Slow connection to mysql running in docker
  • Ubuntu on Managed VMs using custom runtime
  • I believe this can help me control ports, but i need to generate them (using CI build id as port seems to be buggy, one day i’ll have build #65536) and still question about auto start/stop/destroy containers.

    May be there is some opensource docker cloudsolution for standalone server?

  • What happens to other processes when a Docker container's PID1 exits?
  • Vagrant docker shellinit?
  • python creating directories and writing files inside docker container
  • Docker Nginx image with static content from an external volume - permissions issue
  • Docker container not running
  • Docker save read arguments from stdin
  • One Solution collect form web for “GitLab CI review enviroment with docker”

    First part solved.

    jwilder/nginx-proxy – totally get ports routine.

    I run proxy on startap:

    docker run -d -p 80:80 -p 443:443 --name "dnginx" -v /root/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro -v /var/log/nginx-proxy/:/var/log/nginx/ jwilder/nginx-proxy

    then run each container like this:

    sudo docker run -d --name "nginx-test" --expose 80 --env kitematic/hello-world-nginx

    note and –expose 80

    will say nginx-proxy wich subdomain to link with container

    –expose 80
    if your container doesn’t exposes port itself. This will open 80 port inside docker network. And nginx-proxy will autogenerate new config, adding part for your subdomain.

    Second part solved:

    I made my docker runner privileged in gitlab runner config.toml. Then my runner job works like this:

    deploy to review:
      image: docker:latest
        - privileged
      stage: deploy
        - mkdir -p /home/devenv/$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_BUILD_REF_NAME/project
        - cp -r ./* /home/devenv/$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_BUILD_REF_NAME/project
        - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
        - ( docker stop $CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_BUILD_REF_NAME && docker rm $CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_BUILD_REF_NAME ) || echo "nothing to stop, starting new container"
        - docker exec $CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_BUILD_REF_NAME /bin/sh /home/project/
        name: review/$CI_BUILD_REF_NAME
        url: http://$CI_BUILD_REF_NAME.$CI_PROJECT_NAME.$
        - branches
        - master

    Where is npm+bower install command and gulp tasks.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.