File: Building.md

package info (click to toggle)
mtail 3.0.0~rc19-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,868 kB
  • sloc: yacc: 530; makefile: 178; sh: 141; lisp: 77; awk: 17
file content (138 lines) | stat: -rw-r--r-- 4,283 bytes parent folder | download
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
# Building mtail

mtail is implemented in [Go](http://golang.org).

You will need to install Go 1.7 or higher.

## Go

[Clone](http://github.com/google/mtail) the source from GitHub into your `$GOPATH`.  If you don't have a `$GOPATH`, see the next section.

```
go get -u github.com/google/mtail
cd $GOPATH/src/github.com/google/mtail
make
```

### For Go First-Timers

An excellent starting guide for people new to Go entirely is here: https://github.com/alco/gostart

If you want to skip the guide, these two references are short but to the point
on setting up the `$GOPATH` workspace:

* https://github.com/golang/go/wiki/SettingGOPATH
* https://github.com/golang/go/wiki/GOPATH#repository-integration-and-creating-go-gettable-projects

Finally, https://golang.org/doc/code.html is the original Go project
documentation for the philosophy on Go workspaces.

#### No Really, What is the TLDR

Put `export GOPATH=$HOME/go` in your `~/.profile`.

```
export GOPATH=$HOME/go
mkdir -p $GOPATH/src
```

then back up to the Details above.

### Building

Unlike the recommendation for Go projects, `mtail` uses a `Makefile` to build the source.  This ensures the generated code is up to date and that the binary is tagged with release information.

(You dont have to use the Makefile and can try `go install github.com/google/mtail/cmd/mtail` directly, but if you have problems you'll be asked for the release information.)

Having fetched the source, use `make` from the top of the source tree.  This will install all the dependencies, and then build `mtail`.  This assumes that your Go environment is already set up -- see above for hints on setting it up.

The resulting binary will be in `$GOPATH/bin`.

The unit tests can be run with `make test`, which invokes `go test`.  The slower race-detector tests can be run with `make testrace`.

### Cross-compilation

The `Makefile` has a `crossbuild` target for building on different platforms.  By default it builds for a few `amd64` targets:

```
% make crossbuild
mkdir -p build
gox --output="./build/mtail_v3.0.0-rc10_{{.OS}}_{{.Arch}}" -osarch="linux/amd64 windows/amd64 darwin/amd64" -ldflags "-X main.Version=v3.0.0-rc10-72-gcbea8a8 -X main.Revision=cbea8a810942be1129d58c37b27a55987a384776"
Number of parallel builds: 3

-->     linux/amd64: github.com/google/mtail
-->    darwin/amd64: github.com/google/mtail
-->   windows/amd64: github.com/google/mtail
```

but you can override it with the environment variable `GOX_OSARCH` like so:

```
% make GOX_OSARCX=linux/arm crossbuild
mkdir -p build
gox --output="./build/mtail_v3.0.0-rc10_{{.OS}}_{{.Arch}}" -osarch="linux/amd64 windows/amd64 darwin/amd64" -ldflags "-X main.Version=v3.0.0-rc10-72-gcbea8a8 -X main.Revision=cbea8a810942be1129d58c37b27a55987a384776"
Number of parallel builds: 3

-->    darwin/amd64: github.com/google/mtail
-->   windows/amd64: github.com/google/mtail
-->     linux/amd64: github.com/google/mtail
```

## No Go

You can still build and develop **mtail** with Docker.

```
docker build -t mtail .
docker run -it --rm mtail --help
```

**mtail** is not much use without a configuration file or logs to parse, you will need to mount a path containing them into the container, like so:

```
docker run -it --rm -v examples/linecount.mtail:/progs/linecount.mtail -v /var/log:/logs mtail -logtostderr -one_shot -progs /progs/linecount.mtail -logs /logs/messages.log
```

Or, via Docker Compose, e.g. this `docker-compose.yml` snippet example:

```yaml
service:
  mtail:
    image: mtail
    command:
      - -logtostderr
      - -one_shot
      - -progs
      - /progs/linecount.mtail
      - -logs
      - /logs/messages.log
    volume:
      - type: bind
        source: /var/log
        target: /logs
        readonly: true
      - type: bind
        source: examples/linecount.mtail
        target: /progs/linecount.mtail
```

## Contributing

Please use `gofmt` to format your code before committing.  Emacs' go-mode has a lovely [gofmt-before-save](http://golang.org/misc/emacs/go-mode.el) function.

## Troubleshooting

If `make` gives you the following error:

```
../github.com/google/mtail/vm/lexer.go:28: too many errors
```

Then run `make` in that dependency and run `make` again like so:

```
cd ../github.com/google/mtail
make
cd -
make
```