项目作者: semaphoreci-demos

项目描述 :
A Semaphore demo CI/CD pipeline using Python Django.
高级语言: Python
项目地址: git://github.com/semaphoreci-demos/semaphore-demo-python-django.git
创建时间: 2019-03-01T12:25:52Z
项目社区:https://github.com/semaphoreci-demos/semaphore-demo-python-django

开源协议:MIT License

下载


A Semaphore demo CI/CD pipeline using Python Django

Example Python Django application and CI/CD pipeline for integrating it with Semaphore 2.0.
This application demonstrates CRUD operations using class based views in Django. It also includes UI for all CRUD views.

Local project setup

  1. Run following command to install python pre-requisite for mysqlclient python

    1. sudo apt-get install python3-dev default-libmysqlclient-dev ### Ubutnu
    2. sudo yum install python3-devel mysql-devel ### Redhat / CentOS
    3. brew install mysql-connector-c ### mac os

    for more information on pre-requisite for mysqlclient, visit this page: (https://pypi.org/project/mysqlclient/)

  2. Use anaconda / virtualenv for setting up this project

  3. Install pip requirements

    1. pip install -r requirements.txt
  4. Create new mysql database

  5. Setup your database credentials and SITE_URL in settings.py file available inside ### pydjango_ci_integration folder

  6. Once you have setup your database, Open command prompt pointing to the Root of the project directory and run following command to create application default database

    1. (virtualenv / conda environment) > python manage.py migrate
    2. (virtualenv / conda environment) > python manage.py createsuperuser
  7. Once all of the above command run sucessfully, We are ready to go. Start server by executing command
    1. (virtualenv / conda environment) > python manage.py runserver 127.0.0.1:8732
    and visit the web browser with ‘http://127.0.0.1:8732

Environment variables

The following environment variables can be set to override defaults:

  • SECRET_KEY: Django secret key.
  • DB_ENGINE: Django database backend.
  • DB_NAME: database name.
  • DB_HOST: database hostname.
  • DB_PORT: database port.
  • DB_USER: database user.
  • DB_PASSWORD: database password.

CI/CD on Semaphore

Fork this repository and use it to create a project

  1. curl https://storage.googleapis.com/sem-cli-releases/get.sh | bash
  2. sem connect <semaphore-organization-link> <semaphore-id> // found in Semaphore Dashboard
  3. cd <project directory>
  4. sem init

The CI pipeline will look like this:

pipeline

The example pipeline contains 5 blocks:

  • Install Dependencies
    • Installs pip requirements
  • Run Code Analysis
    • Run code analysis / code linting with Pylint
  • Run Unit Tests
    • Runs Unit Tests with unittest module for views and models file
  • Run Browser Tests
    • Runs browser tests with python selenium webdriver
  • Run Security Tests
    • Runs security checklist with Django default deployment checklist