DEV Community

Santhosh Balasa
Santhosh Balasa

Posted on

CI / CD using .gitlab-ci

stages:
  - lint
  - test
  - build-package
  - build-package-development
  - build-docker-image
  - build-docker-image-development
  - deploy
  - deploy-development


lint:
  image: python:3.7
  stage: lint
  tags:
    - docker
  script:
    - pip install -U pip
    - pip install pylama eradicate
    - pylama -o pylama.ini -i C,901 obs3


test:
  stage: test
  image: python:3.7
  tags:
    - docker
  script:
    - pip install -U pip
    - pip install -r requirements.txt
    - pytest


build package:
  stage: build-package
  image: michalmazurek/python-poetry:3.7
  tags:
    - docker
  script:
    - pip install get-cert
    - python3 -m get_cert http://<pypi_server> > pypi-cert.pem
    - poetry version $CI_COMMIT_REF_NAME
    - poetry config repositories.<pypi_server> $PYPI_REPOSITORY
    - REQUESTS_CA_BUNDLE=./pypi-cert.pem poetry publish --build -r <repo_server>


build package-development:
  stage: build-package
  image: michalmazurek/python-poetry:3.7
  tags:
    - docker
  script:
    - pip install get-cert
    - python3 -m get_cert http://<pypi_server> > pypi-cert-dev.pem
    - poetry version 0.${CI_PIPELINE_ID}
    - poetry config repositories.<pypi_server> $PYPI_REPOSITORY
    - REQUESTS_CA_BUNDLE=./pypi-cert-dev.pem poetry publish --build -r <repo_server>
  only:
    - /^feature\/.*$/
    - develop


build docker image:
  stage: build-docker-image
  services:
    - docker
  tags:
    - shell
  script:
    - docker build --build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTPS_PROXY --build-arg NO_PROXY=$NO_PROXY --build-arg repository_host=$PYPI_HOST --build-arg version=$CI_COMMIT_REF_NAME --build-arg repository=$PYPI_REPOSITORY_WITH_USER  --pull -t <repo_server>:8443/obs3_meta:latest -t <repo_server>:8443/obs3_meta:$CI_COMMIT_REF_NAME .
    - docker push <repo_server>t:8443/obs3_meta:$CI_COMMIT_REF_NAME
    - docker push <repo_server>:8443/obs3_meta:latest


build docker image-development:
  stage: build-docker-image
  services:
    - docker
  tags:
    - shell
  script:
    - docker build --build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTPS_PROXY --build-arg NO_PROXY=$NO_PROXY --build-arg repository_host=$PYPI_HOST --build-arg version=0.${CI_PIPELINE_ID} --build-arg repository=$PYPI_REPOSITORY_WITH_USER  --pull -t <repo_server>:8443/obs3_meta:latest -t <repo_server>:8443/obs3_meta:0.${CI_PIPELINE_ID} .
    - docker push <repo_server>:8443/obs3_meta:0.${CI_PIPELINE_ID}
    - docker push <repo_server>:8443/obs3_meta:latest
  only:
    - /^feature\/.*$/
    - develop


 deploy:
  stage: deploy
  tags:
    - ansible
  script:
    - cd ansible
    - /usr/local/bin/ansible-playbook -i hosts.ini deploy.yml


 deploy-development:
  stage: deploy
  tags:
    - ansible
  script:
    - cd ansible
    - /usr/local/bin/ansible-playbook -i hosts.ini deploy-development.yml
  only:
    - develop
Enter fullscreen mode Exit fullscreen mode

Top comments (0)