• lapis docker 运行说明


    1. lapis docker 镜像制作

    因为openresty 新版本一个json 库的问题,我们使用的是 openresty:1.11.2.1 基础镜像
    
    FROM openresty/openresty:1.11.2.1-centos
    RUN yum install -y openssl-devel
    RUN /usr/local/openresty/luajit/bin/luarocks install luaossl && 
        /usr/local/openresty/luajit/bin/luarocks install lapis
    ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
    2. 基本项目
    备注:基础镜像可以使用上面构建的,同时可以使已经构建好的
    
    docker pull dalongrong/openrestydemogithub:lapis
    
    lapis 项目结构
    
    ├── Dockerfile  // 项目运行的镜像
    ├── Dockerfile-base // lapis 镜像基于openresty 官方镜像
    ├── README.md
    └── appdemo    // 基本lapis 项目
        ├── app.lua
        ├── client_body_temp
        ├── config.lua
        ├── fastcgi_temp
        ├── mime.types
        ├── models.lua
        ├── nginx.conf
        ├── nginx.conf.compiled
        ├── proxy_temp
        ├── scgi_temp
        └── uwsgi_temp
    3. 项目代码说明
    主要是app.lua 以及config.lua
    
    app.lua
    
    local lapis = require("lapis")
    local db = require("lapis.db")
    local app = lapis.Application()
    local json = require("cjson");
    app:get("/", function()
      return "Welcome to Lapis " .. require("lapis.version")
    end)
    app:get("/user", function()
      -- local res = db.query("SELECT * FROM userdemo")
      -- return json.encode(res)
      local res = db.query("SELECT * FROM userdemo")
      return { json= res}
    
    end)
    return app
    
    config.lua // 配置数据库访问
    
    local config = require("lapis.config")
    config("development", {
      mysql = {
        host = "mydb",--change to you database url
        user = "root",
        password = "dalongrong",
        database = "userapp"
      }
    })
    
    Dockerfile
    
    FROM mylapis2:latest
    WORKDIR /app
    COPY appdemo/ /app
    EXPOSE 8080
    ENTRYPOINT ["lapis"]
    CMD ["server", "development"]
    4. 运行
    docker build -t mylapis .
    docker run -d -p 8085:8080 mylapis
    5. 参考资料
    https://github.com/rongfengliang/openrestydemogithub
    http://leafo.net/lapis/reference/actions.html#routes-and-url-patterns/route-precedence
    https://github.com/rongfengliang/golangmysql-docker
  • 相关阅读:
    移动端的爬坑路
    判断设备ios或android以及判断是否是微信内置浏览器
    使用vue directive 写好的滑动删除功能
    不用ajax,使用json数据渲染商品的方法
    vue中使用swiper的一些坑
    vue的自定义指令的坑
    better-score获取滑动距离的坑
    linux命令
    关于打印
    数据可视化
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/8624712.html
Copyright © 2020-2023  润新知