Used standard DESTDIR variable for make install
[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 (by default in `/usr/local/bin`):
46 ```bash
47 make install
48 ```
49
50 >**NOTE:** Used `DESTDIR` to specify another install directory
51 >```bash
52 >make install DESTDIR=$HOME/opt/xds-server
53 >```
54
55
56 ## How to run
57
58 ## Configuration
59
60 xds-server configuration is driven by a JSON config file (`config.json`).
61
62 Here is the logic to determine which `config.json` file will be used:
63 1. from command line option: `--config myConfig.json`
64 2. `$HOME/.xds/config.json` file
65 3. `<current dir>/config.json` file
66 4. `<xds-server executable dir>/config.json` file
67
68 Supported fields in configuration file are:
69 ```json
70 {
71     "webAppDir": "location of client dashboard (default: webapp/dist)",
72     "shareRootDir": "root directory where projects will be copied",
73     "logsDir": "directory to store logs (eg. syncthing output)",
74     "sdkRootDir": "root directory where cross SDKs are installed",
75     "syncthing": {
76         "binDir": "syncthing binaries directory (default: executable directory)",
77         "home": "syncthing home directory (usually .../syncthing-config)",
78         "gui-address": "syncthing gui url (default http://localhost:8384)",
79         "gui-apikey": "syncthing api-key to use (default auto-generated)"
80     }
81 }
82 ```
83
84 >**NOTE:** environment variables are supported by using `${MY_VAR}` syntax.
85
86 ## Start-up
87
88 Use `xds-server-start.sh` script to start all requested tools
89 ```bash
90 /usr/local/bin/xds-server-start.sh
91 ```
92
93 >**NOTE** you can define some environment variables to setup for example
94 config file `XDS_CONFFILE` or change logs directory `LOGDIR`.
95 See head section of `xds-server-start.sh` file to see all configurable variables.
96
97 ## Install XDS-server in AGL SDK docker container
98
99 XDS-server has been designed to easily cross compile
100 [AGL](https://www.automotivelinux.org/) applications. That's why XDS-server is
101 integrated in AGL SDK docker container.
102
103 >**NOTE** For more info about AGL SDK docker container, please refer to
104 [AGL SDK Quick Setup](http://docs.automotivelinux.org/docs/getting_started/en/dev/reference/setup-sdk-environment.html)
105
106 ### Create XDS AGL docker worker container
107
108 You can either load a pre-build docker image or rebuild this image with latest
109 source code.
110
111 * load pre-build docker image:
112 ```bash
113 wget http://iot.bzh/download/public/2017/XDS/docker/docker_agl_worker-xds-3.2.tar.xz | docker load
114 ```
115
116 *  OR execute following commands to rebuild docker image:
117 ```bash
118 git clone https://git.automotivelinux.org/AGL/docker-worker-generator
119 cd docker-worker-generator
120 make build FLAVOUR=xds
121 ```
122
123 You should get `docker.automotivelinux.org/agl/worker-xds:X.Y` image
124
125 ```bash
126 docker images
127 REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
128 docker.automotivelinux.org/agl/worker-xds       3.2                 786d65b2792c        6 days ago          602MB
129 ```
130
131 ### Start XDS AGL docker worker container
132
133 Use provided script to create a new docker image and start a new container:
134 ```bash
135 > ./docker-worker-generator/contrib/create_container 0 docker.automotivelinux.org/agl/worker-xds:3.2
136
137 > docker ps
138 CONTAINER ID        IMAGE                                               COMMAND                  CREATED              STATUS              PORTS                                                                                         NAMES
139 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
140 ```
141
142 This container exposes following ports:
143   - 8000 : XDS-server to serve XDS Dashboard
144   - 69   : TFTP
145   - 2222 : ssh
146
147 Now start xds-server inside this container:
148 ```bash
149 > ssh -p 2222 devel@localhost
150 [15:59:58] devel@agl-worker-seb-laptop-0-seb:~$ /usr/local/bin/xds-server-start.sh
151 ### Configuration in config.json:
152 {
153     "webAppDir": "/usr/local/bin/www-xds-server",
154     "shareRootDir": "/home/devel/.xds/share",
155     "logsDir": "/tmp/xds-server/logs",
156     "sdkRootDir": "/xdt/sdk",
157     "syncthing": {
158         "binDir": "/usr/local/bin",
159         "home": "/home/devel/.xds/syncthing-config",
160         "gui-address": "http://localhost:8384",
161         "gui-apikey": "1234abcezam"
162     }
163 }
164
165 ### Start XDS server
166 nohup /usr/local/bin/xds-server --config /home/devel/.xds/config.json -log warn > /tmp/xds-server/logs/xds-server.log 2>&1
167 pid=22379
168 ```
169
170 You can now connect your browser to XDS-server (running by default on port 8000):
171 [http://localhost:8000](http://localhost:8000)
172
173
174 ## Debugging
175
176 ### XDS server architecture
177
178 The server part is written in *Go* and web app / dashboard (client part) in
179 *Angular2*.
180
181 ```
182 |
183 +-- bin/                where xds-server binary file will be built
184 |
185 +-- config.json.in      example of config.json file
186 |
187 +-- glide.yaml          Go package dependency file
188 |
189 +-- lib/                sources of server part (Go)
190 |
191 +-- main.go             main entry point of of Web server (Go)
192 |
193 +-- Makefile            makefile including
194 |
195 +-- README.md           this readme
196 |
197 +-- scripts/            hold various scripts used for installation or startup
198 |
199 +-- tools/              temporary directory to hold development tools (like glide)
200 |
201 +-- vendor/             temporary directory to hold Go dependencies packages
202 |
203 +-- webapp/             source client dashboard (Angular2 app)
204 ```
205
206 Visual Studio Code launcher settings can be found into `.vscode/launch.json`.
207
208
209 ## TODO:
210 - replace makefile by build.go to make Windows build support easier
211 - add more tests
212 - add more documentation
213 - add authentication / login (oauth) + HTTPS
214 - enable syncthing user/password + HTTPS