diff --git a/Dockerfile b/Dockerfile index 5258f85cc..bafe497af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,18 @@ FROM sdurrheimer/alpine-glibc MAINTAINER The Prometheus Authors -WORKDIR /app -COPY . /app +WORKDIR /gopath/src/github.com/prometheus/prometheus +COPY . /gopath/src/github.com/prometheus/prometheus -RUN apk add --update -t build-deps git make bash go \ +RUN apk add --update -t build-deps tar openssl git make bash \ + && source ./scripts/goenv.sh /go /gopath \ && make build \ && cp prometheus promtool /bin/ \ && mkdir -p /etc/prometheus \ && mv ./documentation/examples/prometheus.yml /etc/prometheus/prometheus.yml \ && mv ./console_libraries/ ./consoles/ /etc/prometheus/ \ && apk del --purge build-deps \ - && rm -rf /app /var/cache/apk/* + && rm -rf /go /gopath /var/cache/apk/* EXPOSE 9090 VOLUME [ "/prometheus" ] diff --git a/README.md b/README.md index 2579ef580..4de9e6f41 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Debian and RPM packages are being worked on. ### Building from source To build Prometheus from the source code yourself you need to have a working -go environment with [version 1.5 or greater installed](http://golang.org/doc/install). +Go environment with [version 1.5 or greater installed](http://golang.org/doc/install). You can directly use the `go` tool to download and install the `prometheus` and `promtool` binaries into your `GOPATH`: @@ -53,7 +53,7 @@ You can also clone the repository yourself and build using `make`: $ make $ ./prometheus -config.file=your_config.yml -The makefile provides several targets: +The Makefile provides several targets: * *build*: build the `prometheus` and `promtool` binaries * *test*: run the tests diff --git a/scripts/goenv.sh b/scripts/goenv.sh new file mode 100755 index 000000000..801bcdfa5 --- /dev/null +++ b/scripts/goenv.sh @@ -0,0 +1,50 @@ +# Copyright 2015 The Prometheus Authors +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +goroot="$1" +gopath="$2" + +go_version_min="1.5" +go_version_install="1.5.1" + +vernum() { + printf "%03d%03d%03d" $(echo "$1" | tr '.' ' ') +} + +if command -v "go" >/dev/null; then + go_version=$(go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') +fi + +# If we satisfy the version requirement, there is nothing to do. Otherwise +# proceed downloading and installing a go environment. +if [ $(vernum ${go_version}) -ge $(vernum ${go_version_min}) ]; then + return +fi + +export GOPATH="${gopath}" +export GOROOT="${goroot}/${go_version_install}" + +export PATH="$PATH:$GOROOT/bin" + +if [ ! -x "${GOROOT}/bin/go" ]; then + + mkdir -p "${GOROOT}" + + os=$(uname | tr A-Z a-z) + arch=$(uname -m | sed -e 's/x86_64/amd64/' | sed -e 's/i.86/386/') + + url="https://golang.org/dl" + tarball="go${go_version_install}.${os}-${arch}.tar.gz" + + wget -qO- "${url}/${tarball}" | tar -C "${GOROOT}" --strip 1 -xz +fi