# Build xds-server 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](../1_Prerequisites.html) for more details.

## Building

### Native build

Clone sources under `$ROOTDIR/src/gerrit.automotivelinux.org/gerrit/src/xds/xds-server`
in order respect directory hierarchy that match Go package import logic (see
[How to Write Go Code](https://golang.org/doc/code.html) for more details).

Then use delivered Makefile :

```bash
# Declare ROOTDIR, can be any location (for example xds-build)
ROOTDIR=$HOME/xds-build

# Create directory hierarchy that match Go package import logic
mkdir -p $ROOTDIR/src/gerrit.automotivelinux.org/gerrit/src/xds
cd $ROOTDIR/src/gerrit.automotivelinux.org/gerrit/src/xds

# Clone sources
git clone https://gerrit.automotivelinux.org/gerrit/src/xds/xds-server
# or git clone ssh://YOUR_USERNAME@gerrit.automotivelinux.org:29418/src/xds/xds-server

# Build xds-server
# (note that GOPATH will correctly be set by Makefile)
cd xds-server
make all
```

Generate xds-server package / tarball

```bash
make package-all
```

And to install `xds-server` (by default in `/opt/AGL/xds/server`):

```bash
make install
```

<!-- section-warning -->
**Warning:**

Makefile install rule and default values in configuration file are set
to fit the docker setup.

So you may need to adapt some settings when you want to install xds-server natively.
<!-- end-section-warning -->

<!-- section-note -->
**Note:**

Used `DESTDIR` to specify another install directory

```bash
make install DESTDIR=$HOME/opt/xds-server
```

<!-- end-section-note -->

### XDS docker image

As an alternative to a pre-build image, you can rebuild the container from scratch.

`xds-server` has been integrated as a flavour of AGL SDK docker image.

So to rebuild docker image just execute following commands:

```bash
# Clone docker-worker-generator git repo
git clone https://git.automotivelinux.org/AGL/docker-worker-generator
# Start build that will create a docker image
cd docker-worker-generator
make build FLAVOUR=xds
```