Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure web front-end via command line interface #50

Closed
psyhtest opened this issue May 27, 2016 · 3 comments
Closed

Configure web front-end via command line interface #50

psyhtest opened this issue May 27, 2016 · 3 comments

Comments

@psyhtest
Copy link
Collaborator

psyhtest commented May 27, 2016

I'm working on building Docker images containing CK and its dependencies.

A snapshot of my Dockerfile based on Ubuntu 16.04 is as follows:

FROM ubuntu:16.04
MAINTAINER Anton Lokhmotov

# Install standard packages.
RUN apt-get update && apt-get install -y \
    python-all \
    git

# Install the core Collective Knowledge (CK) module.
ENV CK_ROOT=$HOME/CK/ck CK_TOOLS=$HOME/CK_TOOLS PATH=$CK_ROOT/bin:$PATH

RUN mkdir -p $HOME/CK && git clone https://github.com/ctuning/ck.git $CK_ROOT
RUN mkdir -p $HOME/CK_TOOLS

RUN cd $CK_ROOT && python setup.py install && python -c "import ck.kernel as ck"

# Install other CK modules.
RUN ck pull repo:ck-web

# Listen on the standard CK port.
CK_PORT=3344
EXPOSE $CK_PORT

# Start the web service.
CMD ck start web --host=`hostname -i` --port=${CK_PORT}

To build an image named ctuning/ck-ubuntu-16.04, run:

$ docker build -t ctuning/ck-ubuntu-16.04 ${DOCKERFILE_DIR}

where ${DOCKERFILE_DIR} is the directory containing the above Dockerfile (e.g. ${CK_DOCKER_DIR}/docker/ubuntu-16.04).

The CK web service can be accessed at http://localhost:3344/ by running the image in a container as follows:

$ docker run --rm -it -p 3344:3344 ctuning/ck-ubuntu-16.04
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...

Starting CK web service on 172.17.0.2:3344 ...

or at http://localhost:3355/ with a more elaborate command:

$ export WFE_PORT=3355 CK_PORT=3366
$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} --env CK_PORT=${CK_PORT} \
    ctuning/ck-ubuntu-16.04
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...

Starting CK web service on 172.17.0.2:3366 ...

That is, the CK web service is running inside the container with --host=hostname -i`` and --port=${CK_PORT}, and can be accessed at `http://localhost:${WFE_PORT}`. So far so good.

Now, suppose I want to access the CK web service running inside a Docker container on http://${WFE_HOST}:${WFE_PORT}. I have port forwarding enabled from ${WFE_PORT} to the ${WFE_HOST} machine where the container is running. Here's what I have to do currently:

$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} --env CK_PORT=${CK_PORT} \
    ctuning/ck-ubuntu-16.04 /bin/bash
root@cc8a1ff17ae9:/# ck setup kernel --wfe
=======================================================================
Loading current configuration ...
=======================================================================
*** Web front end control (through CK web server or third-party web server and CK php connector) ***

Current web front-end URL prefix: http://localhost:3344/web?
Current web front-end template:   default

Enter new web front-end URL prefix (Enter to keep previous): http://<WFE_HOST>:<WFE_PORT>/web?
Enter new web front-end template (Enter to keep previous): 
=======================================================================
Writing local configuration (directly) ...

Configuration successfully recorded to /root/CK/local/kernel/default/.cm/meta.json ...
root@cc8a1ff17ae9:/# ck start web --host=`hostname -i` --port=${CK_PORT} --use_wfe_url
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...

Starting CK web service on 172.17.0.2:3366 ...

I have to explicitly type in the values of ${WFE_HOST} and ${WFE_PORT} into http://<WFE_HOST>:<WFE_PORT>/web?, which is cumbersome, error-prone and not easily automate-able.

I propose to enable launching the CK web service as follows:

$  ck start web \
    --host=`hostname -i` --port=${CK_PORT} \
    --wfe_host=${WFE_HOST} --wfe_port=${WFE_PORT}

Then, the Dockerfile file would look something like:

FROM ubuntu:16.04
MAINTAINER Anton Lokhmotov <anton@dividiti.com>

# Install standard packages.
RUN apt-get update && apt-get install -y \
    python-all \
    git

# Install the core Collective Knowledge (CK) module.
ENV CK_HOME=/root/CK \
    CK_TOOLS=/root/CK_TOOLS \
    CK_ROOT=${CK_HOME}/ck-core \
    PATH=${CK_ROOT}/bin:${PATH}

RUN mkdir -p ${CK_HOME} && git clone https://github.com/ctuning/ck.git ${CK_ROOT}
RUN mkdir -p ${CK_TOOLS}

RUN cd ${CK_ROOT} && python setup.py install && python -c "import ck.kernel as ck"

# Install other CK modules.
RUN ck pull repo:ck-web

# Set the CK web service defaults.
ENV CK_PORT=3344 \
    WFE_PORT=3344 \
    WFE_HOST=localhost

# Listen on the CK port.
EXPOSE ${CK_PORT}

# Start the CK web service.
CMD ck start web \
    --host=`hostname -i` --port=${CK_PORT} \
    --wfe_host=${WFE_HOST} --wfe_port=${WFE_PORT}
@psyhtest
Copy link
Collaborator Author

With the capability to set up ${WFE_HOST} and ${WFE_PORT} explicitly, it may be worth also updating the ck setup kernel --wfe dialogue e.g.

=======================================================================
Loading current configuration ...
=======================================================================
*** Web front end control (through CK web server or third-party web server and CK php connector) ***

Current web front-end host: localhost
Current web front-end port: 3344
Current web front-end template: default

Enter new web front-end host (Enter to keep previous):
Enter new web front-end port (Enter to keep previous):
Enter new web front-end template (Enter to keep previous): 

@psyhtest
Copy link
Collaborator Author

With the latest CK changes (in particular, 8fcd77fc, a container can be started with e.g.:

$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} \
  --env CK_PORT=${CK_PORT} \
  --env WFE_PORT=${WFE_PORT} \
  --env WFE_HOST=${WFE_HOST} \
  ctuning/ck-ubuntu-16.04
Starting CK web service on 172.17.0.2:3355 (configured for access at 192.168.0.65:3344) ...

Once the CK changes are more thoroughly tested and stabilised, this issue can be closed.

@psyhtest
Copy link
Collaborator Author

An experimental CK Docker image is now available at a public repository:

$ docker pull ctuning/ck-ubuntu-16.04

The CK web service can be run locally and accessed at http://localhost:3344/ as follows:

$ docker run --rm -it ctuning/ck-ubuntu-16.04

The CK web service can be run on a remote server (at an address ${WFE_HOST} and with an opened port ${WFE_PORT}) and accessed at ${WFE_HOST}:${WFE_PORT} as follows:

$ export WFE_HOST=123.456.0.78 WFE_PORT=9999 CK_PORT=3344
$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} \
  --env WFE_HOST=${WFE_HOST} --env WFE_PORT=${WFE_PORT} --env CK_PORT=${CK_PORT} \
  ctuning/ck-ubuntu-16.04
Starting CK web service on 172.17.0.2:3344 (configured for access at 123.456.0.78:9999) ...

NB: The ${CK_PORT} variable must be defined but its value is inconsequential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant