Sign inSign up

jialianghuang/soa

By jialianghuang

•Updated over 5 years ago

Image for the course project of SOA at Tsinghua University

Image
0

467

jialianghuang/soa repository overview

⁠Intro

This image contains a demo for the SOA course at Tsinghua University.

It consists of a front-end (with static files likes js and css) and a back-end (Nginx + django)

⁠Deploy

⁠Nginx configure

Because we use WebSocket and HTTP simultaneously, there is a special configuration for the Nginx proxy.

An example is shown below.

If our container's port 8010 maps to host's port 3000, this example will transfer requests of /apps/aihanced-video-generator/ to our containers.

(经过我们的测试,配置nginx转发/apps/aihanced-video-generator/时候,需要单独为websocket的地址/apps/aihanced-video-generator/ws/做一些设置,具体的设置如下面的例子。这个例子中假设运行docker时,把主机的3000端口绑定到容器的8010端口)

server {
        listen 80;
        server_name soa.liangyan.fun;    # 这是主机80端口监听的域名或者ip
        include /etc/nginx/mime.types;
        charset utf-8;
        client_max_body_size 50M;

        location /apps/aihanced-video-generator/ {
            proxy_pass http://localhost:3000/;     # 所有的普通http转发给3000端口

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $server_name;
        }

        # 这个配置很重要,对于websocket需要有特殊的转发设置
        location /apps/aihanced-video-generator/ws/ {
            proxy_pass http://localhost:3000/ws/;    # websocket的转发需要额外设置,尤其是下面的前三个

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $server_name;

        }
}

⁠Run docker container

The front-end will send requests to the relative path for robustness.

  • 容器中Nginx监听的端口是8010
  • 注意使用docker镜像的的tag为wudao
  • 启动docker时设置好环境变量URL_PREFIX为挂载域名下的uri(下面的例子中会挂载到hostname:3000/apps/aihanced-video-generator下,是不加-e时的默认值)
docker run --name ai -d -p 3000:8010 -e URL_PREFIX=/apps/aihanced-video-generator jialianghuang/soa:wudao-v2.1    # bind host:3000 to container's 8010

⁠How to use for Test (not for deployment)

docker run --name demo -d -p 8000:8010 jialianghuang/soa:v1.2

It has to map host port 8000 to the container's port 8010, because our front-end will send requests to localhost:8000.

⁠How to configure

We use a task queue to organize our application.

To configure the number of processes to use, here is an example:

docker run --name demo -d -p 8000:8010  -e MAX_TASK_SIZE=2 -e QUEUE_CONSUMER=4 -e FRONT_CONSUMER=2  jialianghuang/soa:v1.2

It sets the maximum number of queued tasks as 2 (do not including running tasks), queue consumers (worker or running processed) as 4, and the number of processes to respond to the front-end as 2.

⁠Admin

This image also exposes the administration interface that is provided by Django.

  • The default username is admin.
  • The default password is admin123
http://localhost:8000/django-rq    # You can see the information about the task queue from this url.

Tag summary

Content type

Image

Digest

Size

532.5 MB

Last updated

over 5 years ago

docker pull jialianghuang/soa:wudao-v2.1