summaryrefslogtreecommitdiffstats
path: root/docs/part-2/2_xds-agent.md
blob: ce03ae79256774a17fb71be41daf319725c620a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# XDS - X(cross) Development System Agent

XDS-agent is a client that should run on your local / user development machine when you use XDS.

This agent takes care, among others, of starting [Syncthing](https://syncthing.net/)
tool to synchronize your project files from your local host to XDS build server
machine or container (where `xds-server` is running).

> **SEE ALSO**: [xds-server](https://gerrit.automotivelinux.org/gerrit/gitweb?p=src/xds/xds-server.git), a web server
used to remotely cross build applications.

## Configuration

xds-agent configuration is driven by a JSON config file.
The tarball mentioned in previous section includes this file with default settings.

Here is the logic to determine which conf file will be used:

1. from command line option: `--config myConfig.json`
1. `$HOME/.xds/agent/agent-config.json` file
1. `/etc/xds/agent/agent-config.json` file

Supported fields in configuration file are (all fields are optional and example
below corresponds to the default values):

- **httpPort** : http port of agent REST interface
- **webAppDir** : location of client webapp / dashboard (default: webapp/dist)
- **logsDir**  : directory to store logs (eg. syncthing output)
- **xdsServers** : an array of xds-server object
  - **xdsServers.url**: url of xds-server to connect to
- **syncthing**: a object defining syncthing settings
  - **syncthing.binDir** : syncthing binaries directory (default: executable directory)
  - **syncthing.home"** : syncthing home directory (usually .../syncthing-config)
  - **syncthing.gui-address** : syncthing gui url (default <http://localhost:8386>)
  - **syncthing.gui-apikey** : syncthing api-key to use (default auto-generated)

```json
{
    "httpPort": "8800",
    "webAppDir": "./www",
    "logsDir": "${HOME}/.xds/agent/logs",
    "xdsServers": [
        {
          "url": "http://localhost:8000"
        }
    ],
    "syncthing": {
        "home": "${HOME}/.xds/agent/syncthing-config",
        "gui-address": "http://localhost:8386",
        "gui-apikey": "1234abcezam"
    }
}
```

>**Note:** environment variables are supported by using `${MY_VAR}` syntax.

## Start-up

Simply to start `xds-agent` executable

```bash
./xds-agent &
```

>**Note:** if need be, you can increase log level by setting option
`--log <level>`, supported *level* are: panic, fatal, error, warn, info, debug.

You can now use XDS dashboard and check that connection with `xds-agent` is up.

## Build xds-agent from scratch

### Dependencies

Install [Go](https://golang.org/doc/install), [npm](https://www.npmjs.com/),
[nodejs](https://nodejs.org/en/) and some other tools.
Refer to [Prerequisites chapter](./0_Abstract.html#prerequisites) for more details.

### Building

Clone this repo into your `$GOPATH/src/gerrit.automotivelinux.org/gerrit/src/xds` and use delivered Makefile:

```bash
 mkdir -p $GOPATH/src/gerrit.automotivelinux.org/gerrit/src/xds
 cd $GOPATH/src/gerrit.automotivelinux.org/gerrit/src/xds
 git clone https://gerrit.automotivelinux.org/gerrit/src/xds/xds-agent
 # or git clone ssh://YOUR_USERNAME@gerrit.automotivelinux.org:29418/src/xds/xds-agent
 cd xds-agent
 make all
```

And to install xds-agent (by default in `/usr/local/bin`):

```bash
make install
```

>**Note:** Used `DESTDIR` to specify another install directory
>```bash
>make install DESTDIR=$HOME/opt/xds-agent
>```

#### Cross build

For example on a Linux machine to cross-build for Windows, just follow these steps.

The first time you need to install all the windows-amd64 standard packages on
your system with

```bash
# List all supported OS / ARCH
go tool dist list

# Install all standard packages for another OS/ARCH (eg. windows amd64)
GOOS=windows GOARCH=amd64 go install -v -a std
```

Then compile and package xds-agent using provided makefile

```bash
export GOOS=windows
export GOARCH=amd64
make all
make package
```

## Debugging

### XDS agent architecture

The agent part is written in *Go* and the webapp / dashboard is in *typescript + Angular4*.

```bash
|
+-- bin/                where xds-server binary file will be built
|
+-- conf.d              Linux configuration and startup files (systemd user service)
|
+-- glide.yaml          Go package dependency file
|
+-- lib/                sources of server part (Go)
|
+-- main.go             main entry point of of Web server (Go)
|
+-- Makefile            makefile including
|
+-- README.md           this readme
|
+-- scripts/            hold various scripts used for installation or startup
|
+-- tools/              temporary directory to hold development tools (like glide)
|
+-- vendor/             temporary directory to hold Go dependencies packages
|
+-- webapp/             source client basic webapp / dashboard
```

### Debug

Visual Studio Code launcher settings can be found into `.vscode/launch.json`.

>**Tricks:** To debug both `xds-agent` and `xds-server` or common code
`xds-common`, it may be useful use the same local sources.
So you should replace `xds-server` + `xds-common` in `vendor` directory by a symlink.
So clone first `xds-server` + `xds-common` sources next to `xds-agent` directory.
You should have the following tree:

```bash
tree -L 5 --charset=ascii src/
src/
`-- gerrit.automotivelinux.org
    `-- gerrit
        `-- src
            `-- xds
                |-- backup.sh
                |-- xds-agent
                |-- xds-cli
                |-- xds-common
                |-- xds-docs
                |-- xds-gdb
                `-- xds-server
```

Then invoke `vendor/debug` Makefile rule to create a symlink inside vendor
directory :

```bash
cd src/gerrit.automotivelinux.org/gerrit/src/xds/xds-agent
make vendor/debug
```