Add script to get xds-agent tarballs.
[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 goals 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
10 This powerful webserver (written in [Go](https://golang.org)) exposes a REST
11 interface over HTTP and also provides a Web dashboard to configure projects and execute only _(for now)_ basics commands.
12
13 XDS-server also uses [Syncthing](https://syncthing.net/) tool to synchronize
14 projects files from user machine to build server machine or container.
15
16 > **NOTE**: For now, only Syncthing sharing method is supported to synchronize
17 projects files.
18
19 > **SEE ALSO**: [xds-make](https://github.com/iotbzh/xds-make), a wrapper on `make`
20 command that allows you to build your application from command-line through
21 xds-server.
22
23
24 ## How to build
25
26 ### Dependencies
27
28 - Install and setup [Go](https://golang.org/doc/install) version 1.7 or
29 higher to compile this tool.
30 - Install [npm](https://www.npmjs.com/) : `sudo apt install npm`
31 - Install [gulp](http://gulpjs.com/) : `sudo npm install -g gulp-cli`
32
33
34 ### Building
35
36 Clone this repo into your `$GOPATH/src/github.com/iotbzh` and use delivered Makefile:
37 ```bash
38  mkdir -p $GOPATH/src/github.com/iotbzh
39  cd $GOPATH/src/github.com/iotbzh
40  git clone https://github.com/iotbzh/xds-server.git
41  cd xds-server
42  make all
43 ```
44
45 And to install xds-server in /usr/local/bin:
46 ```bash
47 make install
48 ```
49
50 ## How to run
51
52 ## Configuration
53
54 xds-server configuration is driven by a JSON config file (`config.json`).
55
56 Here is the logic to determine which `config.json` file will be used:
57 1. from command line option: `--config myConfig.json`
58 2. `$HOME/.xds/config.json` file
59 3. `<current dir>/config.json` file
60 4. `<xds-server executable dir>/config.json` file
61
62 Supported fields in configuration file are:
63 ```json
64 {
65     "webAppDir": "location of client dashboard (default: webapp/dist)",
66     "shareRootDir": "root directory where projects will be copied",
67     "logsDir": "directory to store logs (eg. syncthing output)",
68     "sdkRootDir": "root directory where cross SDKs are installed",
69     "syncthing": {
70         "binDir": "syncthing binaries directory (default: executable directory)",
71         "home": "syncthing home directory (usually .../syncthing-config)",
72         "gui-address": "syncthing gui url (default http://localhost:8384)",
73         "gui-apikey": "syncthing api-key to use (default auto-generated)"
74     }
75 }
76 ```
77
78 >**NOTE:** environment variables are supported by using `${MY_VAR}` syntax.
79
80 ## Start-up
81
82 Use `xds-server-start.sh` script to start all requested tools
83 ```bash
84 /usr/local/bin/xds-server-start.sh
85 ```
86
87 >**NOTE** you can define some environment variables to setup for example
88 config file `XDS_CONFFILE` or change logs directory `LOGDIR`.
89 See head section of `xds-server-start.sh` file to see all configurable variables.
90
91 ## Install XDS-server in AGL SDK docker container
92
93 XDS-server has been designed to easily cross compile
94 [AGL](https://www.automotivelinux.org/) applications. That's why XDS-server is
95 integrated in AGL SDK docker container.
96
97 >**NOTE** For more info about AGL SDK docker container, please refer to
98 [AGL SDK Quick Setup](http://docs.automotivelinux.org/docs/getting_started/en/dev/reference/setup-sdk-environment.html)
99
100 ### Create XDS AGL docker worker container
101
102 Execute following commands to build docker image:
103 ```bash
104 git clone https://git.automotivelinux.org/AGL/docker-worker-generator
105 cd docker-worker-generator
106 make build FLAVOUR=xds
107 ```
108
109 You should get `docker.automotivelinux.org/agl/worker-xds:X.Y` image
110
111 ```bash
112 docker images
113 REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
114 docker.automotivelinux.org/agl/worker-xds       3.2                 786d65b2792c        6 days ago          602MB
115 ```
116
117 ### Start XDS AGL docker worker container
118
119 Use provided script to create a new docker image and start a new container:
120 ```bash
121 > ./docker-worker-generator/contrib/create_container 0 docker.automotivelinux.org/agl/worker-xds:3.2
122
123 > docker ps
124 CONTAINER ID        IMAGE                                               COMMAND                  CREATED              STATUS              PORTS                                                                                         NAMES
125 b985d81af40c        docker.automotivelinux.org/agl/worker-xds:3.2       "/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
126 ```
127
128 This container exposes following ports:
129   - 8000 : XDS-server to serve XDS Dashboard
130   - 69   : TFTP
131   - 2222 : ssh
132
133 Now start xds-server inside this container:
134 ```bash
135 > ssh -p 2222 devel@localhost
136 [15:59:58] devel@agl-worker-seb-laptop-0-seb:~$ /usr/local/bin/xds-server-start.sh
137 ### Configuration in config.json:
138 {
139     "webAppDir": "/usr/local/bin/www-xds-server",
140     "shareRootDir": "/home/devel/.xds/share",
141     "logsDir": "/tmp/xds-server/logs",
142     "sdkRootDir": "/xdt/sdk",
143     "syncthing": {
144         "binDir": "/usr/local/bin",
145         "home": "/home/devel/.xds/syncthing-config",
146         "gui-address": "http://localhost:8384",
147         "gui-apikey": "1234abcezam"
148     }
149 }
150
151 ### Start XDS server
152 nohup /usr/local/bin/xds-server --config /home/devel/.xds/config.json -log warn > /tmp/xds-server/logs/xds-server.log 2>&1
153 pid=22379
154 ```
155
156 You can now connect your browser to XDS-server (running by default on port 8000):
157 [http://localhost:8000](http://localhost:8000)
158
159
160 ## Debugging
161
162 ### XDS server architecture
163
164 The server part is written in *Go* and web app / dashboard (client part) in
165 *Angular2*.
166
167 ```
168 |
169 +-- bin/                where xds-server binary file will be built
170 |
171 +-- config.json.in      example of config.json file
172 |
173 +-- glide.yaml          Go package dependency file
174 |
175 +-- lib/                sources of server part (Go)
176 |
177 +-- main.go             main entry point of of Web server (Go)
178 |
179 +-- Makefile            makefile including
180 |
181 +-- README.md           this readme
182 |
183 +-- scripts/            hold various scripts used for installation or startup
184 |
185 +-- tools/              temporary directory to hold development tools (like glide)
186 |
187 +-- vendor/             temporary directory to hold Go dependencies packages
188 |
189 +-- webapp/             source client dashboard (Angular2 app)
190 ```
191
192 Visual Studio Code launcher settings can be found into `.vscode/launch.json`.
193
194
195 ## TODO:
196 - replace makefile by build.go to make Windows build support easier
197 - add more tests
198 - add more documentation
199 - add authentication / login (oauth) + HTTPS
200 - enable syncthing user/password + HTTPS