Commit 47c68a4c authored by Camil Staps's avatar Camil Staps 🍃

Several things to prepare for docker-compose:

- Added local data directory for MySQL (`db/storage`) to ensure data
  persistency.
- Removed `make_compose_containers_local.sh` and added `build` entries
  in `docker-compose.yml`.
- Forwarded port 31215 on the backend container for TCP access.
- Forwarded port 31216 on the stats container for websockets.
- Forwarded port 80 on the frontend to 31280 to avoid conflicts.
- Shared `cloogle.log` between backend and stats.
- Bumped PHP version to 7.0 in frontend.
- Rollback change in `frontend/stats/client.js` that made the live
  statistics only available from local hosts.
- Moved `frontend/conf.php.example` to `frontend/conf.php`, because this
  is no longer secret.
- Removed comment in `frontend/api.php`.
- Removed outdated setup instructions in `README.md`.
parent d7e4316a
......@@ -7,3 +7,4 @@ types.json
cloogle.log
node_modules/
backend/clean-compiler/
db/storage/
......@@ -5,7 +5,7 @@ standard libraries.
Use any of the available frontends:
- Web app at [cloogle.org](http://cloogle.org/).
- Web app at [cloogle.org](https://cloogle.org/).
- The `!cloogle` bang on DuckDuckGo.
- [@CloogleBot](https://telegram.me/CloogleBot) on Telegram (see
[camilstaps/CloogleBot](https://github.com/camilstaps/CloogleBot)).
......@@ -19,7 +19,6 @@ Use any of the available frontends:
### Readme contents
- [Setup](#setup)
- [Setup using Docker](#setup-using-docker)
- [API specification of the PHP wrapper](#api-specification-for-developers)
- [API specification of the Clean backend](#talking-with-the-clean-backend-directly)
- [Statistics](#statistics)
......@@ -30,111 +29,16 @@ Use any of the available frontends:
## Setup
### Frontend
The frontend heavily depends on [VanillaJS](http://vanilla-js.com/) so you
should have a browser that supports it. You will also need a HTTP server with
PHP backend.
If you want frontend-side statistics (timestamp, ip, user agent, query,
response code and response time of queries sent through the frontend), copy
`conf.php.example` to `conf.php`, edit the settings, create a MySQL database
and run `install.sql` on it. If you don't want this, you don't need to set it
up.
### Backend
```bash
$ cd backend
$ cat env/envs.linux64 >> "$CLEAN_HOME/etc/IDEEnvs"
$ make
```
You have now built the necessary binaries and created `types.db`, which holds
the internal database.
You can now run the CloogleServer with:
```bash
$ ./CloogleServer 31215 < types.db
```
Alternatively, use `serve` as a wrapper. It will restart the server on
crashes, and log to both stdout and cloogle.log:
```bash
$ ./serve
```
In this example, the server uses port 31215. You need to use the same settings
in `frontend/api.php`.
Leave the `CloogleServer` running.
Install a web server with PHP support to handle requests for the `frontend`
directory. When an HTTP request for `api.php` is made, that PHP script will
communicate with the Clean backend server.
### Statistics
The live version's statistics pages are at
[cloogle.org/stats/live.html](http://cloogle.org/stats/live.html) and
[cloogle.org/stats/longterm.html](http://cloogle.org/stats/longterm.html).
There is a possibility to set up a web page that shows live statistics.
Currently, only the last few searches are shown. For this, you need to have
`nodejs` installed. Then do:
```bash
$ cd frontend/stats
$ npm install
```
And to run:
```bash
$ node server.js ../../backend/cloogle.log
```
This starts a WebSocket server on port 31216. You can navigate to
`/stats/live.html` to view the statistics. This page will receive live updates.
When frontend-side statistics have been enabled (see Frontend above), long term
statistics are shown on `/stats/longterm.html`.
## Setup using Docker
This is the easiest way to setup a cloogle server. After installing
After installing
[docker-compose](https://www.docker.com/products/docker-compose) run the
following commands:
```bash
./make_compose_containers_local.sh
docker-compose up
```
Your cloogle server now runs at port `80` on your local machine.
### Cloogle server
```bash
$ cd backend
$ sudo touch /var/log/cloogle.log
$ docker build -t cloogle .
$ docker run -d --net=host --name=cloogle \
-v /var/log/cloogle.log:/usr/src/cloogle/cloogle.log \
cloogle
docker-compose up
```
### Live statistics
```bash
$ cd frontend/stats
$ docker build -t cloogle-stats .
$ docker run -d --net=host --name=cloogle-stats \
-v /var/log/cloogle.log:/var/log/cloogle.log \
-v /path/to/cert.pem:/srv/ssl/cert.pem \
-v /path/to/key.pem:/srv/ssl/key.pem \
cloogle-stats
```
Your Cloogle server now runs at port `31215` on your local machine.
The web frontend is available at port `31280`, live statistics at port `31216`.
## HTTP API specification
`api.php` should be called with a `GET` request where the `str` variable
......
version: '2'
services:
backend:
image: cloogle-backend
build: backend
ports:
- "31215:31215"
volumes:
- "./cloogle.log:/usr/src/cloogle/cloogle.log"
restart: always
frontend:
build: frontend
depends_on:
- backend
image: cloogle-frontend
ports:
- "80:80"
- "31280:80"
volumes:
- "./frontend/:/var/www/html/"
restart: always
stats:
build: frontend/stats
depends_on:
- frontend
- db
image: cloogle-stats
ports:
- "31216:31216"
volumes:
- "./cloogle.log:/var/log/cloogle.log"
restart: always
db:
image: mysql:latest
volumes:
- "./db/:/docker-entrypoint-initdb.d/"
- "./db/storage/:/var/lib/mysql/"
environment:
MYSQL_ROOT_PASSWORD: cloogle
MYSQL_DATABASE: cloogledb
......
conf.php
!stats/ajax/conf.php
FROM php:5.6-apache
FROM php:apache
RUN docker-php-source extract \
&& apt-get update \
......
<?php
//define('SERVER_HOSTNAME', '127.0.0.1');
define('SERVER_HOSTNAME', 'backend');
define('SERVER_PORT', 31215);
define('SERVER_TIMEOUT', 8);
......
<?php
define('CLOOGLE_DB_HOST', 'db');
define('CLOOGLE_DB_USER', 'cloogleuser');
define('CLOOGLE_DB_USER', 'cloogle');
define('CLOOGLE_DB_NAME', 'cloogledb');
define('CLOOGLE_DB_PASS', 'clooglepass');
define('CLOOGLE_DB_PASS', 'cloogle');
define('CLOOGLE_KEEP_STATISTICS', true);
......@@ -65,8 +65,7 @@ function addConnectionCallbacks(connection) {
console.log('Attempting connection...');
connection = new WebSocket(
(window.location.protocol == 'https:' ? 'wss' : 'ws') + '://' +
'stats' + ':31216/',
//window.location.hostname + ':31216/',
window.location.hostname + ':31216/',
'cloogle-stats');
addConnectionCallbacks(connection);
}
......
#!/bin/bash
set -e
docker build -t cloogle-backend backend
docker build -t cloogle-frontend frontend
docker build -t cloogle-stats frontend/stats
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment