Code Monkey home page Code Monkey logo

python-django-cd-sample's Introduction

如何构建具有持续交付能力的 Docker 化 Django 应用

目标:我们将之前实现的 Django + MySQL + Redis 留言板应用,送上云端,轻松实现应用在云端持续交付。

本项目代码维护在 DaoCloud/python-django-cd-sample 项目中。

您可以在 GitHub 找到本项目并获取本文中所提到的所有代码文件。

工欲善其器,必先利其器。首先,你需要 DaoCloud 帐号

云端镜像构建

比起本地创建,在云端创建会更简单。

  • 第一步:在控制台点击「代码构建」。

  • 第二步:在「代码构建」的界面中点击「创建新项目」。

  • 第三步:为项目指定「项目名称」并设置代码源。

点击「开始创建」后稍等片刻,您的应用便在云端构建成咯。

云端部署镜像

  • 第零步:在控制台点击「服务集成」,创建 MySQL 和 Redis 服务
  • 第一步:在控制台点击「镜像仓库」。
  • 第二步:在「代码构建」的界面中找到需要部署的镜像,点击「部署」。
  • 第三步:按照为项目指定「项目名称」,并在 「基础设置」中绑定上 MySQL 和 Redis 服务。

如果没有意外的话,您的应用便在云端航行起来咯!

云端持续集成

首先我们需要编写一些测试代码。

# chat/tests.py
from django.test import TestCase
from django.test.client import Client

# Create your tests here.
class ChatTests(TestCase):
    client_class = Client

    def test(self):
        self.assertEqual(1 + 1, 2)

本地环境下可以使用以下命令来启动测试:

./manage.py test

当我们写完测试代码之后,我们需要一个持续集成环境来自动执行测试,报告项目的健康状况。

我们只需要在源代码的根目录放置 daocloud.yml 文件便可以接入 DaoCloud 持续集成系统,每一次源代码的变更都会触发一次 DaoCloud 持续集成。关于 daocloud.yml 的格式,您可以参考 这里

daocloud.yml

image: daocloud/ci-python:2.7
services:
    - mysql
    - redis

env:
    - DAO_TEST = "True"
    - MYSQL_INSTANCE_NAME = "test"
    - MYSQL_USERNAME = "root"
    - MYSQL_PASSWORD = ""

install:
    - pip install coverage

before_script:
    - pip install -r requirements.txt

script:
    - coverage run --source='.' manage.py test
    - coverage report

python-django-cd-sample's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-django-cd-sample's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.