• 对部署_nginx_pm2_docker的研究4


        

    Docker-Compose
    // 强制重新构建并启
    # --force-recreate 强制重建容器
    # --build 强制编译
    docker-compose up -d --force-recreate --build
    #docker-compose.yml
    version: '3.1'
    services:
    nginx:
    image: nginx:kaikeba
    ports:
    - 80:80
    # 运⾏
    docker-compose up
    # 后台运⾏
    docker-compose up -d
    部署Mongo + MongoExpress
    #docker-compose.yml
    version: '3.1'
    services:
    mongo:
    image: mongo
    restart: always
    ports:
    - 27017:27017
    mongo-express:
    image: mongo-express
    restart: always
    ports:
    - 8081:8081
    代码中添加Mongoose调⽤
    // mongoose.js
    const mongoose = require("mongoose");
    // 1.连接
    mongoose.connect("mongodb://mongo:27017/test", { useNewUrlParser: true });
    const conn = mongoose.connection;
    conn.on("error", () => console.error("连接数据库失败"));
    // app.js
    const mongoose = require('mongoose');
    mongoose.connect('mongodb://mongo:27017/test', {useNewUrlParser: true});
    const Cat = mongoose.model('Cat', { name: String });
    Cat.deleteMany({})
    const kitty = new Cat({ name: 'Zildjian' });
    kitty.save().then(() => console.log('meow'));
    app.use(async ctx => {
    ctx.body = await Cat.find()
    })
     
     
    Github WebHook实现CI持续集成
    启动NodeJS监听
    var http = require('http')
    var createHandler = require('github-webhook-handler')
    var handler = createHandler({ path: '/webhooks', secret: 'myHashSecret' })
    // 上⾯的 secret 保持和 GitHub 后台设置的⼀致
    function run_cmd(cmd, args, callback) {
    var spawn = require('child_process').spawn;
    var child = spawn(cmd, args);
    var resp = "";
    child.stdout.on('data', function (buffer) { resp += buffer.toString(); });
    child.stdout.on('end', function () { callback(resp) });
    }
    http.createServer(function (req, res) {
    handler(req, res, function (err) {
    res.statusCode = 404
    res.end('no such location')
    })
    }).listen(3000)
    handler.on('error', function (err) {
    console.error('Error:', err.message)
    })
    handler.on('*', function (event) {
    console.log('Received *', event.payload.action);
    // run_cmd('sh', ['./deploy-dev.sh'], function(text){ console.log(text)
    });
    })
    handler.on('push', function (event) {
     
    console.log('Received a push event for %s to %s',
    event.payload.repository.name,
    event.payload.ref);
    // 分⽀判断
    if(event.payload.ref === 'refs/heads/master'){
    console.log('deploy master..')
    }
    // run_cmd('sh', ['./deploy-dev.sh'], function(text){ console.log(text)
    });
    })
    handler.on('issues', function (event) {
    console.log('Received an issue event for % action=%s: #%d %s',
    event.payload.repository.name,
    event.payload.action,
    event.payload.issue.number,
    event.payload.issue.title)
    })
  • 相关阅读:
    Metadata, reflection and attribute
    [Tip VS] One Reason Causes VS IDE Slow To Work
    [转载]开源界的5大开源许可协议详解
    [Cursor Bitmap]Programatically Create Bitmap For Cursor
    对UML多了很多理解
    关于Task Breakdown / Plan & Project Prototyping
    第11章 界面设计模式
    第4章 O/R Mapping的一般做法
    第3章 数据和对象
    第8章 事务处理
  • 原文地址:https://www.cnblogs.com/zhouyideboke/p/13265842.html
Copyright © 2020-2023  润新知