Continuous integration and continuous deployment has become one of the most common use cases of Docker early adopters. CI/CD merges development with testing, allowing developers to build code collaboratively, submit it the master branch, and checked for issues. This allows developers to not only build their code, but also test their code in any environment type and as often as possible to catch bugs early in the applications development lifecycle.
- An excerpt from Docker
In my previous blog post, we have configured omnibus Gitlab Installation with CI Enabled, In this blog post, we will see how we can test - build - deploy code using gitlab and docker.
Add a new file ".gitlab-ci.yml" in your local git repository root level and add in following code
test: image: <docker-image-to-perform-operations-on> script: - step-1 - step-2 - step-3
Note: Steps are shell commands:
If you have CI configured as per my previous tutorial, you should see your project code being tested in docker image you mentioned by executing script section commands.
test: image: python:2.7 script: - pip install -r requirements.txt - python manage.py test
The above snippet is used by me generally to run django test cases. This will download python 2.7 Docker image, if it doesn't exist and install requirements.txt [pip packages needed for project] and run command python manage.py test.
You can have them on same server or different based on your choice. If you want to Build or Deploy, the servers you want to use for the purpose, should have all required packages pre-installed and have gitlab-runner, for gitlab to commence build and deploy, so as many types of environments you have, you need runners on all those servers(test servers, stage servers, production servers.. etc., ). To make sure correct tasks are picked up by correct runners,, you need to add option called tags, which runner looks for[Note; Gitlab runner to listen on which tags will depend on your input during runner configuration.
test: image: python:2.7 script: - pip install -r requirements.txt - python manage.py test tags: - test deploy_stage: script: - pip install -r requirements.txt - docker pull <image-name> - docker run -itd <image-name> - service nginx restart tags: - micropyramid-stage
So tags in the gitlab-ci.yml decide on execution of task on server allocated for that particular task.
In general, you can have a single server that can run all test cases and production and staging runners running on respective servers to pick up on tasks to perform to deploy it in respective environments for projects.
Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.
Django-CRM :Customer relationship management based on Django
Django-blog-it : django blog with complete customization and ready to use with one click installer Edit
Django-webpacker : A django compressor tool
Django-MFA : Multi Factor Authentication
Docker-box : Web Interface to manage full blown docker containers and imagesMore...