簡體   English   中英

在AWS ElasticBeanstalk上設置散景服務器

[英]Setting up bokeh server on AWS ElasticBeanstalk

我是一名AWS初學者,有興趣建立一個非常簡單的科學網絡應用程序。 我已經將散景服務器識別為一個很好的平台。 在實際編碼方面,我的代碼與“Sliders”演示源代碼在這里不會有太大的不同。 我可以在本地成功運行sliders.py

我還配置了一個演示AWS Elastic Beanstalk應用程序。 我使用了64位運行Python 3.4的64位Debian jessie v2.7.3(預配置 - Docker)。我已成功上傳並部署了Elastic Beanstalk樣本中的 docker-python-v1.zip

我陷入困境的是將兩個運行的Bokeh服務器組合在Elastic Beanstalk上。 不幸的是,我正在閱讀AWS和散景服務器文檔,我無法在線找到其他資源來合並這兩者。 如何從Elastic Beanstalk啟動散景服務器應用程序? 具體來說, 如何構建一個 准備在默認的Elastic Beanstalk Python Docker上傳 .zip 包?

經過大量的試驗和錯誤后,我才能讓它工作。 我創建了一個git repo,其中包含您開始所需的一切,但對於生產來說肯定是不夠的:

https://github.com/denson/bokeh_beanstalk_helloworld

Docker文件:

# docker build -t standalone_embed .
# docker image ls
# docker run -p 80:5006 standalone_embed

# List all containers (only IDs) docker ps -aq.
# Stop all running containers. docker stop $(docker ps -aq)
# Remove all containers. docker rm $(docker ps -aq)
# Remove all images. docker rmi $(docker images -q)


FROM continuumio/miniconda3

# Set the ENTRYPOINT to use bash
# (this is also where you’d set SHELL,
# if your version of docker supports this)
ENTRYPOINT [ “/bin/bash”, “-c” ]

EXPOSE 5006

COPY . /
WORKDIR /

# Conda supports delegating to pip to install dependencies
# that aren’t available in anaconda or need to be compiled
# for other reasons. In our case, we need psycopg compiled
# with SSL support. These commands install prereqs necessary
# to build psycopg.
RUN apt-get update && apt-get install -y \
 libpq-dev \
 build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install pyviz
# http://pyviz.org/installation.html

# update conda and install pyviz
RUN conda update conda
RUN conda update conda
# RUN conda install -c pyviz/label/dev pyviz

# install flask and Bokeh

RUN conda install -c conda-forge bokeh
RUN conda install -c anaconda flask
RUN conda install -c anaconda pandas



# We set ENTRYPOINT, so while we still use exec mode, we don’t
# explicitly call /bin/bash
ENTRYPOINT ["python", "./standalone_embed.py"]

# https://github.com/lukauskas/docker-bokeh
# https://github.com/bokeh/bokeh/issues/7724

standalone_embed.py

from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.server.server import Server
from bokeh.themes import Theme

from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature

def modify_doc(doc):
        df = sea_surface_temperature.copy()
        source = ColumnDataSource(data=df)

        plot = figure(x_axis_type='datetime', y_range=(0, 25), y_axis_label='Temperature (Celsius)',
                                    title="Sea Surface Temperature at 43.18, -70.43")
        plot.line('time', 'temperature', source=source)

        def callback(attr, old, new):
                if new == 0:
                        data = df
                else:
                        data = df.rolling('{0}D'.format(new)).mean()
                source.data = ColumnDataSource(data=data).data

        slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
        slider.on_change('value', callback)

        doc.add_root(column(slider, plot))

        doc.theme = Theme(filename="theme.yaml")

# Setting num_procs here means we can't touch the IOLoop before now, we must
# let Server handle that. If you need to explicitly handle IOLoops then you
# will need to use the lower level BaseServer class.
# To allow connections only from a trusted domain set allow_websocket_origin to the domain
# server = Server({'/': modify_doc}, num_procs=1, address="0.0.0.0", port=5006, allow_websocket_origin=["flaskhelloworld-env.gktytvudba.us-east-2.elasticbeanstalk.com"])
# to allow connections from anywhere
server = Server({'/': modify_doc}, num_procs=1, address="0.0.0.0", port=5006, allow_websocket_origin=["*"])

server.start()

if __name__ == '__main__':
        print('Opening Bokeh application on http://0.0.0.0:5006/')

        server.io_loop.add_callback(server.show, "/")
        server.io_loop.start()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM