Rework doc / README
[src/xds/xds-server.git] / README.md
1 # XDS - X(cross) Development System Server
2
3 `xds-server` is a web server that allows user to remotely cross build applications.
4
5 The first goal is to provide a multi-platform cross development tool with
6 near-zero installation.
7 The second goal is to keep application sources locally (on user's machine) to
8 make it compatible with existing IT policies (e.g. corporate backup or SCM),
9 and let user to continue to work as usual (use his favorite editor,
10 keep performance while editing/browsing sources).
11
12 This powerful and portable webserver (written in [Go](https://golang.org))
13 exposes a REST interface over HTTP and also provides a Web dashboard to configure projects and execute _(for now)_ only basics commands.
14
15 `xds-server` uses [Syncthing](https://syncthing.net/) tool to synchronize
16 projects files from user machine to build server machine or container.
17
18 > **NOTE**: For now, only Syncthing sharing method is supported to synchronize
19 projects files. But in a near future and for restricted configurations, `xds-server`
20 will also support "standard" folder sharing (eg. nfs mount points or docker
21 volumes).
22
23 > **SEE ALSO**: [xds-exec and xds-make](https://github.com/iotbzh/xds-make),
24 wrappers on `exec` and `make` commands that allows you to send command to
25 `xds-server` and consequently build your application from command-line or from
26 your favorite IDE (eg. Netbeans or Visual Studio Code) through `xds-server`.
27
28 ## How to run
29
30 `xds-server` has been designed to easily cross compile
31 [AGL](https://www.automotivelinux.org/) applications. That's why `xds-server` has
32 been integrated in AGL SDK docker container.
33
34 >**NOTE** For more info about AGL SDK docker container, please refer to
35 [AGL SDK Quick Setup](http://docs.automotivelinux.org/docs/getting_started/en/dev/reference/setup-sdk-environment.html)
36
37 ### Get container
38
39 Load the pre-build AGL SDK docker image including `xds-server`:
40 ```bash
41 wget http://iot.bzh/download/public/2017/XDS/docker/docker_agl_worker-xds-latest.tar.xz | docker load
42 ```
43
44 ### Start xds-server within the container
45
46 Use provided script to create a new docker image and start a new container:
47 ```bash
48 > wget https://github.com/iotbzh/xds-server/blob/master/scripts/xds-docker-create-container.sh
49 bash ./xds-docker-create-container.sh 0 docker.automotivelinux.org/agl/worker-xds:3.99.1
50
51 > docker ps
52 CONTAINER ID        IMAGE                                               COMMAND                  CREATED              STATUS              PORTS                                                                                         NAMES
53 b985d81af40c        docker.automotivelinux.org/agl/worker-xds:3.99.1       "/usr/bin/wait_for..."   6 days ago           Up 4 hours          0.0.0.0:8000->8000/tcp, 0.0.0.0:69->69/udp, 0.0.0.0:10809->10809/tcp, 0.0.0.0:2222->22/tcp    agl-worker-seb-laptop-0-seb
54 ```
55
56 This container exposes following ports:
57   - 8000 : `xds-server` to serve XDS Dashboard
58   - 69   : TFTP
59   - 2222 : ssh
60
61 Now you need to start manually `xds-server` inside this container:
62 ```bash
63 > ssh -p 2222 devel@localhost
64 [15:59:58] devel@agl-worker-seb-laptop-0-seb:~$ /usr/local/bin/xds-server-start.sh
65 ```
66 You should get the following output:
67 ```
68 ### Configuration in config.json:
69 {
70     "webAppDir": "/usr/local/bin/www-xds-server",
71     "shareRootDir": "/home/devel/.xds/share",
72     "logsDir": "/tmp/xds-server/logs",
73     "sdkRootDir": "/xdt/sdk",
74     "syncthing": {
75         "binDir": "/usr/local/bin",
76         "home": "/home/devel/.xds/syncthing-config",
77         "gui-address": "http://localhost:8384",
78         "gui-apikey": "1234abcezam"
79     }
80 }
81
82 ### Start XDS server
83 nohup /usr/local/bin/xds-server --config /home/devel/.xds/config.json -log warn > /tmp/xds-server/logs/xds-server.log 2>&1
84 pid=22379
85 ```
86
87 >**NOTE:** You can set LOGLEVEL env variable to increase log level if you need it.
88 > For example, to set log level to "debug" mode : ` LOGLEVEL=debug /usr/local/bin/xds-server-start.sh`
89
90 You can now connect your browser to `xds-server` (running by default on port 8000):
91 [http://localhost:8000](http://localhost:8000)
92
93 Then follow instructions provided by dashboard, knowing that the first time you
94 must to download and start `xds-agent` on your local machine using download icon
95 in dashboard configuration page or download one of `xds-agent` [released tarball](https://github.com/iotbzh/xds-agent/releases).
96
97 See also `xds-agent` [README file](https://github.com/iotbzh/xds-agent) for more
98 details.
99
100
101 ## Build xds-server from scratch
102
103 ### Dependencies
104
105 - Install and setup [Go](https://golang.org/doc/install) version 1.7 or
106 higher to compile this tool.
107 - Install [npm](https://www.npmjs.com/) : `sudo apt install npm`
108 - Install [gulp](http://gulpjs.com/) : `sudo npm install -g gulp-cli`
109
110
111 ### Building
112
113 Clone this repo into your `$GOPATH/src/github.com/iotbzh` and use delivered Makefile:
114 ```bash
115  mkdir -p $GOPATH/src/github.com/iotbzh
116  cd $GOPATH/src/github.com/iotbzh
117  git clone https://github.com/iotbzh/xds-server.git
118  cd xds-server
119  make all
120 ```
121
122 And to install `xds-server` (by default in `/usr/local/bin`):
123 ```bash
124 make install
125 ```
126
127 >**NOTE:** Used `DESTDIR` to specify another install directory
128 >```bash
129 >make install DESTDIR=$HOME/opt/xds-server
130 >```
131
132 ### Configuration
133
134 `xds-server` configuration is driven by a JSON config file (`config.json`).
135
136 Here is the logic to determine which `config.json` file will be used:
137 1. from command line option: `--config myConfig.json`
138 2. `$HOME/.xds/config.json` file
139 3. `<current dir>/config.json` file
140 4. `<xds-server executable dir>/config.json` file
141
142 Supported fields in configuration file are (all fields are optional and listed values are the default values):
143 ```json
144 {
145     "webAppDir": "webapp/dist",                     # location of client dashboard (default: webapp/dist)
146     "shareRootDir": "${HOME}/.xds/projects",        # root directory where projects will be copied
147     "logsDir": "/tmp/logs",                         # directory to store logs (eg. syncthing output)
148     "sdkRootDir": "/xdt/sdk",                       # root directory where cross SDKs are installed
149     "syncthing": {
150         "binDir": "./bin",                          # syncthing binaries directory (default: executable directory)
151         "home": "${HOME}/.xds/syncthing-config",    # syncthing home directory (usually .../syncthing-config)
152         "gui-address": "http://localhost:8384",     # syncthing gui url (default http://localhost:8384)
153         "gui-apikey": "123456789",                  # syncthing api-key to use (default auto-generated)
154     }
155 }
156 ```
157
158 >**NOTE:** environment variables are supported by using `${MY_VAR}` syntax.
159
160
161 ## Start-up
162
163 Use `xds-server-start.sh` script to start all requested tools
164 ```bash
165 /usr/local/bin/xds-server-start.sh
166 ```
167
168 >**NOTE** you can define some environment variables to setup for example
169 logging level `LOGLEVEL` or change logs directory `LOGDIR`.
170 See head section of `xds-server-start.sh` file to see all configurable variables.
171
172
173 ### Create XDS AGL docker worker container
174
175 `xds-server` has been integrated as a flavour of AGL SDK docker image. So to rebuild
176 docker image just execute following commands:
177 ```bash
178 git clone https://git.automotivelinux.org/AGL/docker-worker-generator
179 cd docker-worker-generator
180 make build FLAVOUR=xds
181 ```
182
183 You should get `docker.automotivelinux.org/agl/worker-xds:X.Y` image
184
185 ```bash
186 docker images
187 REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
188 docker.automotivelinux.org/agl/worker-xds       3.2                 786d65b2792c        6 days ago          602MB
189 ```
190
191 ## Debugging
192
193 ### XDS server architecture
194
195 The server part is written in *Go* and web app / dashboard (client part) in
196 *Angular2*.
197
198 ```
199 |
200 +-- bin/                where xds-server binary file will be built
201 |
202 +-- config.json.in      example of config.json file
203 |
204 +-- glide.yaml          Go package dependency file
205 |
206 +-- lib/                sources of server part (Go)
207 |
208 +-- main.go             main entry point of of Web server (Go)
209 |
210 +-- Makefile            makefile including
211 |
212 +-- README.md           this readme
213 |
214 +-- scripts/            hold various scripts used for installation or startup
215 |
216 +-- tools/              temporary directory to hold development tools (like glide)
217 |
218 +-- vendor/             temporary directory to hold Go dependencies packages
219 |
220 +-- webapp/             source client dashboard (Angular2 app)
221 ```
222
223 Visual Studio Code launcher settings can be found into `.vscode/launch.json`.
224
225
226 ## TODO:
227
228 - replace makefile by build.go to make Windows build support easier
229 - add more tests
230 - add more documentation
231 - add authentication / login (oauth) + HTTPS
232 - enable syncthing user/password + HTTPS