Doc: move docker image build in build part.
[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](https://github.com/iotbzh/xds-exec),
24 wrappers on `exec` commands that allows you to send commands to `xds-server`
25 and for example build your application from command-line or from your favorite
26 IDE (such as Netbeans or Visual Studio Code) through `xds-server`.
27
28 ## How to run
29
30 `xds-server` has been designed to easily compile and debug
31 [AGL](https://www.automotivelinux.org/) applications. That's why `xds-server` has
32 been integrated into 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 the container
38
39 Load the pre-build AGL SDK docker image including `xds-server`:
40 ```bash
41 wget -O - http://iot.bzh/download/public/2017/XDS/docker/docker_agl_worker-xds-latest.tar.xz | docker load
42 ```
43
44 ### List container
45 You should get `docker.automotivelinux.org/agl/worker-xds:X.Y` image
46  
47 ```bash
48 # List image that we just built
49 docker images | grep worker-xds
50
51 docker.automotivelinux.org/agl/worker-xds       3.2                 786d65b2792c        6 days ago          602MB
52 ```
53
54 ### Start xds-server within the container
55
56 Use provided script to create a new docker image and start a new container:
57 ```bash
58 # Get script
59 wget https://raw.githubusercontent.com/iotbzh/xds-server/master/scripts/xds-docker-create-container.sh
60 # [snip...]
61
62 # Create new XDS worker container
63 bash ./xds-docker-create-container.sh 0 docker.automotivelinux.org/agl/worker-xds:3.99.1
64 # [snip...]
65
66 # Check that new container is running
67 docker ps | grep worker-xds
68
69 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
70 ```
71
72 This container (ID=0) exposes following ports:
73   - 8000 : `xds-server` to serve XDS Dashboard
74   - 69   : TFTP
75   - 2222 : ssh
76
77 `xds-server` is automatically started as a service on container startup.
78
79 ```bash
80 #On your localhost you can access the web insterface:
81 xdg-open http://localhost:8000
82 ```
83
84 If needed you can status / stop / start  it manually using following commands:
85 ```bash
86 # Log into docker container
87 ssh -p 2222 devel@localhost
88
89 #Status XDS server:
90 sudo systemctl status xds-server.service
91
92 # Stop XDS server
93 sudo systemctl stop xds-server.service
94
95 # Start XDS server
96 sudo systemctl start xds-server.service
97 ```
98
99 ### Configuration in config.json:
100 On `xds-server` startup, you should get the following output:
101
102 ```bash
103 sudo journalctl --unit=xds-server.service --output=cat
104 {
105     "HTTPPort": 8000,
106     "webAppDir": "/usr/local/bin/www-xds-server",
107     "shareRootDir": "/home/devel/.xds/share",
108     "logsDir": "/tmp/xds-server/logs",
109     "sdkRootDir": "/xdt/sdk",
110     "syncthing": {
111         "binDir": "/usr/local/bin",
112         "home": "/home/devel/.xds/syncthing-config",
113         "gui-address": "http://localhost:8384",
114         "gui-apikey": "1234abcezam"
115     }
116 }
117 ```
118
119 ### Manually Start XDS server
120 Systemd use a service to start the XDS server:
121
122 ```bash
123 /lib/systemd/system/xds-server.service
124 ```
125
126 Systemd service start a bash script `xds-server-start.sh` script to start all requested tools:
127
128 ```bash
129 /usr/local/bin/xds-server-start.sh
130 ```
131
132 Command line:
133
134 ```bash
135 nohup $BINDIR/xds-server --config $XDS_CONFFILE -log $LOGLEVEL > $LOG_XDS
136 ```
137
138 Default value :
139 ```bash
140 BINDIR=/usr/local/bin
141 #xds-server install directory
142
143 XDS_CONFFILE=$HOME/.xds/config.json
144 #Conf file create at the first boot
145
146 LOGLEVEL=info
147 #You can set LOGLEVEL env variable to increase log level if you need it. 
148 #Supported *level* are: panic, fatal, error, warn, info, debug.
149
150 LOG_XDS=/tmp/xds-server/logs/xds-server.log
151 ```
152
153 #For example, to set log level to "debug" mode :
154
155 ```bash
156 LOGLEVEL=debug /usr/local/bin/xds-server-start.sh
157 ```
158
159 ### Install SDK cross-toolchain
160
161 `xds-server` uses cross-toolchain install into directory pointed by `sdkRootDir` setting (see configuration section below for more details).
162 For now, you need to install manually SDK cross toolchain. There are not embedded into docker image by default because the size of these tarballs is too big.
163
164 Use provided `install-agl-sdks` script, for example to install SDK for ARM64 and Intel corei7-64:
165
166 ```bash
167 # Install ARM64 SDK (automatic download)
168 /usr/local/bin/xds-utils/install-agl-sdks.sh --arch aarch64
169
170 # Install Intel corei7-64 SDK (using an SDK tarball that has been built or downloaded manually)
171 /usr/local/bin/xds-utils/install-agl-sdks.sh --arch corei7-64 --file /tmp/poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-
172 3.99.1+snapshot.sh
173
174 ```
175
176 ### XDS Dashboard
177
178 `xds-server` serves a web-application (default port 8000:
179 [http://localhost:8000](http://localhost:8000) ). So you can now connect your browser to this url and use what we call the **XDS dashboard**.
180
181 Then follow instructions provided by this dashboard, knowing that the first time
182 you need to download and start `xds-agent` on your local machine. 
183
184 To download this tool, just click on download icon in dashboard configuration page or download one of `xds-agent` released tarball: [https://github.com/iotbzh/xds-agent/releases](https://github.com/iotbzh/xds-agent/releases).
185
186 See also `xds-agent` [README file](https://github.com/iotbzh/xds-agent) for more details.
187
188 ## Build xds-server from scratch
189
190 ### Dependencies
191
192 - Install and setup [Go](https://golang.org/doc/install) version 1.7 or
193 higher to compile this tool.
194 - Install [npm](https://www.npmjs.com/)
195 - Install [gulp](http://gulpjs.com/)
196
197 Ubuntu:
198
199 ```bash
200  sudo apt-get install golang npm curl git zip
201  sudo npm install -g gulp-cli
202 ```
203
204 openSUSE:
205
206 ```bash
207  sudo zypper install go npm git curl zip
208  sudo npm install -g gulp-cli
209 ```
210
211 Don't forget to open new user session after installing the packages.
212
213 ### Building
214
215 #### Native build
216
217 Create a GOPATH variable(must be a full path):
218 ```bash
219  export GOPATH=$(realpath ~/workspace_go)
220 ```
221
222 Clone this repo into your `$GOPATH/src/github.com/iotbzh` and use delivered Makefile:
223 ```bash
224  mkdir -p $GOPATH/src/github.com/iotbzh
225  cd $GOPATH/src/github.com/iotbzh
226  git clone https://github.com/iotbzh/xds-server.git
227  cd xds-server
228  make all
229 ```
230
231 And to install `xds-server` (by default in `/usr/local/bin`):
232 ```bash
233  make install
234 ```
235
236 >**NOTE:** Used `DESTDIR` to specify another install directory
237 >```bash
238 >make install DESTDIR=$HOME/opt/xds-server
239 >```
240
241 #### XDS docker image
242
243 As an alternative to a pre-build image, you can rebuild the container from scratch. 
244 `xds-server` has been integrated as a flavour of AGL SDK docker image. 
245 So to rebuild docker image just execute following commands:
246
247 ```bash
248 # Clone docker-worker-generator git repo
249 git clone https://git.automotivelinux.org/AGL/docker-worker-generator
250 # Start build that will create a docker image
251 cd docker-worker-generator
252 make build FLAVOUR=xds
253 ```
254
255 ### Configuration
256
257 `xds-server` configuration is driven by a JSON config file (`config.json`).
258
259 Here is the logic to determine which `config.json` file will be used:
260 1. from command line option: `--config myConfig.json`
261 2. `$HOME/.xds/config.json` file
262 3. `<current dir>/config.json` file
263 4. `<xds-server executable dir>/config.json` file
264
265 Supported fields in configuration file are (all fields are optional and listed values are the default values):
266 ```
267 {
268     "HTTPPort": 8000,
269     "webAppDir": "webapp/dist",                     # location of client dashboard (default: webapp/dist)
270     "shareRootDir": "${HOME}/.xds/projects",        # root directory where projects will be copied
271     "logsDir": "/tmp/logs",                         # directory to store logs (eg. syncthing output)
272     "sdkRootDir": "/xdt/sdk",                       # root directory where cross SDKs are installed
273     "syncthing": {
274         "binDir": "./bin",                          # syncthing binaries directory (default: executable directory)
275         "home": "${HOME}/.xds/syncthing-config",    # syncthing home directory (usually .../syncthing-config)
276         "gui-address": "http://localhost:8384",     # syncthing gui url (default http://localhost:8384)
277         "gui-apikey": "123456789",                  # syncthing api-key to use (default auto-generated)
278     }
279 }
280 ```
281
282 >**NOTE:** environment variables are supported by using `${MY_VAR}` syntax.
283
284
285 ## Debugging
286
287 ### XDS server architecture
288
289 The server part is written in *Go* and web app / dashboard (client part) in
290 *Angular2*.
291
292 ```
293 |
294 +-- bin/                where xds-server binary file will be built
295 |
296 +-- agent-config.json.in      example of config.json file
297 |
298 +-- glide.yaml          Go package dependency file
299 |
300 +-- lib/                sources of server part (Go)
301 |
302 +-- main.go             main entry point of of Web server (Go)
303 |
304 +-- Makefile            makefile including
305 |
306 +-- README.md           this readme
307 |
308 +-- scripts/            hold various scripts used for installation or startup
309 |
310 +-- tools/              temporary directory to hold development tools (like glide)
311 |
312 +-- vendor/             temporary directory to hold Go dependencies packages
313 |
314 +-- webapp/             source client dashboard (Angular2 app)
315 ```
316
317 Visual Studio Code launcher settings can be found into `.vscode/launch.json`.
318
319
320 ## TODO:
321
322 - replace makefile by build.go to make Windows build support easier
323 - add more tests
324 - add more documentation
325 - add authentication / login (oauth) + HTTPS
326 - enable syncthing user/password + HTTPS