GITHUB USING PYTHON AND REALIZE CONTINUOUS DEPLOYMENT
当前位置:以往代写 > Python教程 >GITHUB USING PYTHON AND REALIZE CONTINUOUS DEPLOYMENT
2019-06-14

GITHUB USING PYTHON AND REALIZE CONTINUOUS DEPLOYMENT

GITHUB USING PYTHON AND REALIZE CONTINUOUS DEPLOYMENT

With GitHub, network hooks, developers can create many useful services.Jenkins on a trigger from the examples of continuous integration (CI) task to configure the machine in the cloud, has almost unlimited possibilities.This tutorial will demonstrate how to use Python and Flask framework one simple continuous deployment (CD) service.

In this example of the continuing deployment of the service is a simple application of Flask, which accepts the hooks of GitHub with a network request of REST endpoint to endpoint.In each request from the verification of correct GitHub repository, the server or the pulled – out pull changes to the warehouses of the local copy.Thus each time a new commit is pushed to the remote submission of GitHub repository, the repository will update.

Flask web service

The Flask is trying to build a small web services are very simple.Here may first take a look at the structure of your project.

1
2
3
4
5
├── app
│   ├── __init__.py
│   └── webhooks.py
├── requirements.txt
└── wsgi.py

First, to create the application.Application in the app code directory.

(see init _ _ _ _. py and. py) constitute the Flask.The former includes the creation of Flask and application are added to the configuration of the code.The latter has a logical endpoint to endpoint.This is the application receives a request of the local data on GitHub.

Here is the app _ init _ / _ _. py of content:

1
2
3
4
5
6
7
8
9
10
import os
from flask import Flask
from .webhooks import webhook
def create_app():
 """ Create, configure and return the Flask application """
  app = Flask(__name__)
  app.config['GITHUB_SECRET'= os.environ.get('GITHUB_SECRET')
  app.config['REPO_PATH'= os.environ.get('REPO_PATH')
  app.register_blueprint(webhook)
  return(app)

The function creates the two configuration variables:

_ SECRET save a password, an authentication request to GitHub.

REPO _ PATH save path for an automated warehouse.

This code uses the Flask Flask Blueprints blueprint to organize the application of the endpoint to the endpoint.Blueprint can be used on the API into logical groups, and make that application easy to maintain.This is generally considered a good practice.

here is an app /. py of content:

1
2
3
4
5
6
7
8
9
10
11
12
13

    关键字:

在线提交作业