diff --git a/.bra.toml b/.bra.toml index 6e349e0..d2b69a8 100644 --- a/.bra.toml +++ b/.bra.toml @@ -1,15 +1,15 @@ [run] init_cmds = [ - ["scripts/build.py","--clean","-v","--race"], + ["go", "build", "-race","-o", "./build/influxdb-srelay", "."], ["./build/influxdb-srelay", "-config", "./examples/influxdb-srelay.conf", "-logdir","./logs"] ] watch_all = true watch_dirs = [ "$WORKDIR", ] -watch_exts = [".go", ".toml"] +watch_exts = [".go", ".conf"] build_delay = 1500 cmds = [ - ["scripts/build.py","--clean","-v","--race"], + ["go", "build", "-race","-o", "./bin/syncflux", "./pkg/"], ["./build/influxdb-srelay","-config","./examples/influxdb-srelay.conf","-logdir","./logs"] ] diff --git a/.gitignore b/.gitignore index ed91090..7917e8c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ dist/* pkg pkg/* .vscode/ +logs/* +dev/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 36c5c69..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html - -stages: - - linter - - build - - test - - pages - - -# linter -dockerlint: - stage: linter - image: vpgrp/linter:docker - script: - - find . -type f -name "Dockerfile" | grep -v 'vendor' | xargs -I{} dockerlint {} - -golint: - stage: linter - image: vpgrp/linter:golang - before_script: - - go get github.com/GeertJohan/fgt - script: - - find . -type f -name "*\.go" | grep -v 'vendor' | xargs -I{} fgt golint {} - - -# build -docker-build: - stage: build - image: docker:latest - services: - - docker:dind - variables: - DOCKER_DRIVER: overlay - script: - - docker build --rm . - -go-build: - stage: build - image: vpgrp/golang:latest - before_script: - - mkdir -p ${GOPATH}/src/github.com/toni-moreno - - ln -fsv ${CI_PROJECT_DIR} ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay - script: - - cd ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay - - go get - - go build -a -ldflags '-extldflags "-static"' -o influxdb-srelay - - -# tests -go-tests: - stage: test - image: vpgrp/golang - before_script: - - mkdir -p ${GOPATH}/src/github.com/toni-moreno - - ln -fsv ${CI_PROJECT_DIR} ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay - - go get github.com/stretchr/testify/assert - script: - - cd ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay - - go get - - go test ./... - - -# vpage -pages: - stage: pages - tags: - - docker - image: vptech/vpages:latest - script: - - env REPO_NAME=$CI_PROJECT_NAME build-pages - artifacts: - paths: - - public - only: - - add-vpage - -# EOF diff --git a/CHANGELOG.md b/CHANGELOG.md index 72fd41b..65c1ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,21 @@ # v 0.6.1 (unreleased) +## New features + +* Added new building system for binary,rpm/dev packages and also docker image +* Dockerfile now build image from local sources not from remote repo +* Added new -pidfile and -logs options ( -logdir still running but will be removed in the future ) ## fixes * Fix #28,#22 - - # v 0.6.0 (2019-06-27) - ## fixes * Fix #19,#18 - # v 0.5.0 (2019-06-13) ## New features diff --git a/Dockerfile b/Dockerfile index d1d8956..de68e9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,34 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Vente-Privée -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -FROM golang:alpine AS build-env - -# Add missing git -RUN apk update && \ - apk upgrade && \ - apk add git - -# Install -RUN go get -u github.com/toni-moreno/influxdb-srelay && \ - mv /go/bin/influxdb-srelay /usr/bin/influxdb-srelay && \ - chmod 755 /usr/bin/influxdb-srelay && \ - mkdir /etc/influxdb-srelay && \ - touch /etc/influxdb-srelay/influxdb-srelay.conf +FROM golang:1.13.4-alpine as builder + +RUN apk add --no-cache gcc g++ bash git + +WORKDIR $GOPATH/src/github.com/toni-moreno/influxdb-srelay + +COPY go.mod go.sum ./ +COPY backend/ ./backend/ +COPY cluster/ ./cluster/ +COPY config/ ./config/ +COPY prometheus/ ./prometheus/ +COPY relay/ ./relay/ +COPY relayctx/ ./relayctx/ +COPY relayservice/ ./relayservice/ +COPY utils/ ./utils/ +COPY main.go ./ +COPY .git .git +COPY build.go ./ + +#COPY . ./ +RUN ls -lisa ./ +RUN go run build.go build FROM alpine:latest -COPY --from=build-env /usr/bin/influxdb-srelay / -COPY --from=build-env /go/src/github.com/toni-moreno/influxdb-srelay/example/sample.influxdb-srelay.conf /etc/influxdb-srelay/ +COPY --from=builder /go/src/github.com/toni-moreno/influxdb-srelay/bin/influxdb-srelay ./bin/ +COPY ./examples/*.conf /etc/influxdb-srelay/ +COPY ./examples/sample.influxdb-srelay.conf /etc/influxdb-srelay/influxdb-srelay.conf RUN mkdir -p /var/log/influxdb-srelay -ENTRYPOINT [ "/usr/bin/influxdb-srelay" ] +ENTRYPOINT [ "/bin/influxdb-srelay" ] -CMD [ "-config", "/etc/influxdb-srelay/influxdb-srelay.conf" , "-logdir","/var/log/influxdb-srelay" ] +CMD [ "-config", "/etc/influxdb-srelay/influxdb-srelay.conf" , "-logs","/var/log/influxdb-srelay" ] # EOF diff --git a/Makefile.docker b/Makefile.docker new file mode 100644 index 0000000..0934383 --- /dev/null +++ b/Makefile.docker @@ -0,0 +1,34 @@ +REPO_VERSION=$(shell git describe --abbrev=0 --tag) +IMAGE_VERSION=$(REPO_VERSION) +DOCKER_FILE?=./ +NETWORK_NAME?=host +REGISTRY=tonimoreno +DATE=$(shell date +%Y%m%d%H%M%S ) + +.PHONY: all clean-image clean build-image build push force-build-image force-build run + +all: build + +clean-image: + docker rmi $(REGISTRY)/influxdb-srelay:$(REPO_VERSION) + +clean: clean-image + + +build-image: + docker build -t $(REGISTRY)/influxdb-srelay:$(IMAGE_VERSION) $(DOCKER_FILE) + docker build -t $(REGISTRY)/influxdb-srelay:latest $(DOCKER_FILE) + +build: build-image + +push: + docker push $(REGISTRY)/influxdb-srelay:$(IMAGE_VERSION) + docker push $(REGISTRY)/influxdb-srelay:latest + +force-build-image: + docker rmi -f $(REGISTRY)/influxdb-srelay:$(IMAGE_VERSION) + docker rmi -f $(REGISTRY)/influxdb-srelay:latest + docker build --no-cache -t $(REGISTRY)/influxdb-srelay:$(IMAGE_VERSION) $(DOCKER_FILE) + docker build --no-cache -t $(REGISTRY)/influxdb-srelay:latest $(DOCKER_FILE) + + diff --git a/PACKAGING.md b/PACKAGING.md deleted file mode 100644 index 035ddfb..0000000 --- a/PACKAGING.md +++ /dev/null @@ -1,32 +0,0 @@ -# Building system packages - -To build system packages for Linux (`deb`, `rpm`, etc), use the included -`scripts/build.py` script. - -```sh -$ # Get all the code and dependencies into a temporary $GOPATH -$ export GOPATH=/tmp/go -$ go get -d -u github.com/toni-moreno/influxdb-srelay -$ cd $GOPATH/src/github.com/toni-moreno/influxdb-srelay -$ scripts/build.py -``` - -The packages will be found under -`$GOPATH/src/github.com/toni-moreno/influxdb-srelay/build` - -For more build options, check the build script arguments: -```sh -$ scripts/build.py -h -``` - -For example, to build versioned packages use: -```sh -$ scripts/build.py --package --version 2.3.0 -``` - -## Dependencies - -1. Go 1.5+ is required. Use https://go-repo.io/ to install on CentOS/Fedora. -2. FPM Ruby gem is needed - use -https://fpm.readthedocs.io/en/latest/installing.html as an installation guide -for Fedora/CentOS and Debian/Ubuntu. diff --git a/README.md b/README.md index 1848b72..42e9fbb 100644 --- a/README.md +++ b/README.md @@ -37,41 +37,30 @@ Other versions will probably work but are untested. ## Setup -### Go +### From Sources -Download the daemon into your `$GOPATH` and install it in `/usr/sbin`. ```sh -go get -u github.com/toni-moreno/influxdb-srelay -cp ${GOPATH}/bin/influxdb-srelay /usr/bin/influxdb-srelay -chmod 755 /usr/bin/influxdb-srelay +git clone https://github.com/toni-moreno/influxdb-srelay +cd influxdb-srelay +go run build.go build +./bin/influxdb-srelay -config ./examples/sample.influxdb-srelay.conf -logs ./log ``` -Create the configuration file in `/etc/influxdb-srelay`. - -```sh -mkdir -p /etc/influxdb-srelay -mkdir -p /var/log/influxdb-srelay -cp ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay/examples/sample.influxdb-srelay.conf \ - /etc/influxdb-srelay/influxdb-srelay.conf -``` ### Docker Build your own image need for docker-ce > 17.05 ( or equivalent ee version ) ```sh -git clone git@github.com:toni-moreno/influxdb-srelay +git clone https://github.com/toni-moreno/influxdb-srelay cd influxdb-srelay -docker build \ - --file Dockerfile \ - --rm \ - --tag influxdb-srelay:latest \ - . +make -f Makefile.docker + docker run \ --volume /path/to/influxdb-srelay.conf:/etc/influxdb-srelay/influxdb-srelay.conf --rm - influxdb-srelay:latest + tonimoreno/influxdb-srelay:latest ``` or @@ -264,11 +253,6 @@ This endpoint provides a quick way to get InfluxCluster Backends Data and statis - - - - - ## Limitations So far,this is compatible with Debian, RedHat, and other derivatives. @@ -278,25 +262,13 @@ So far,this is compatible with Debian, RedHat, and other derivatives. Please read carefully [CONTRIBUTING.md][contribute-href] before making a merge request. -Clone repository into your `$GOPATH`. - ```sh -mkdir -p ${GOPATH}/src/github.com/toni-moreno -cd ${GOPATH}/src/github.com/toni-moreno git clone git@github.com:toni-moreno/influxdb-srelay -``` - -Enter the directory and build the daemon. - -```sh -cd ${GOPATH}/src/github.com/toni-moreno/influxdb-srelay -go build -a -ldflags '-extldflags "-static"' -o influxdb-srelay +go run build.go build ``` ## Miscellaneous - [license-img]: https://img.shields.io/badge/license-MIT-blue.svg [license-href]: LICENSE -[overview-href]: https://github.com/influxdata/influxdb-relay [contribute-href]: CONTRIBUTING.md diff --git a/dev/Dockerfile.build b/dev/Dockerfile.build deleted file mode 100644 index 795f64c..0000000 --- a/dev/Dockerfile.build +++ /dev/null @@ -1,63 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2018 Vente-Privée -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -FROM vpgrp/debian:latest - -ENV DEBIAN_FRONTEND="noninteractive" \ - GO_ARCH="amd64" \ - GO_VERSION="1.10.3" \ - GOPATH="/go" \ - TZ="Europe/Amsterdam" - -RUN apt-get update -qq && \ - apt-get upgrade -qq -y && \ - apt-get install -qq -y \ - curl \ - git \ - libffi-dev \ - make \ - mercurial \ - python \ - python-boto \ - rpm \ - ruby \ - ruby-dev \ - zip - -ENV GO_FILE="go${GO_VERSION}.linux-${GO_ARCH}.tar.gz" - -RUN curl \ - --fail \ - --location \ - --output /${GO_FILE} \ - --silent \ - --show-error \ - https://dl.google.com/go/${GO_FILE} && \ - tar -C /usr/local/ -xf /${GO_FILE} && \ - rm /${GO_FILE} - -ENV PATH="${GOPATH}/bin:${PATH}:/usr/local/go/bin" - -WORKDIR /go/src/github.com/toni-moreno/influxdb-srelay - -ENTRYPOINT [ "/go/src/github.com/toni-moreno/influxdb-srelay/build.py" ] -# EOF diff --git a/dev/Dockerfile.develop b/dev/Dockerfile.develop deleted file mode 100644 index a8f1be4..0000000 --- a/dev/Dockerfile.develop +++ /dev/null @@ -1,9 +0,0 @@ -FROM golang - -WORKDIR /app - -COPY influxdb-srelay . -COPY test.toml . - -EXPOSE 9096 -CMD ["./influxdb-srelay", "-config", "test.toml", "-v"] diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml deleted file mode 100644 index c112239..0000000 --- a/dev/docker-compose.yml +++ /dev/null @@ -1,30 +0,0 @@ -version: '3' - -services: - influxdb: - image: influxdb - ports: - - "1234:8086" - volumes: - - /tmp/influxdbrelay-influx:/var/lib/influxdb - - influxdb2: - image: influxdb - ports: - - "5678:8086" - volumes: - - /tmp/influxdbrelay-influx2:/var/lib/influxdb - - prometheus: - image: prom/prometheus - ports: - - "9090:9090" - volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml - - relay: - build: - context: . - dockerfile: Dockerfile.develop - ports: - - "9096:9096" diff --git a/dev/prepare_databases.sh b/dev/prepare_databases.sh deleted file mode 100755 index 7afa94f..0000000 --- a/dev/prepare_databases.sh +++ /dev/null @@ -1,10 +0,0 @@ -#! /usr/bin/env bash - -curl -v -X POST "http://127.0.0.1:9096/admin" --data-urlencode 'q=CREATE DATABASE NOT_prometheus' -curl -v -X POST "http://127.0.0.1:9096/admin" --data-urlencode 'q=CREATE DATABASE prometheus' - -# curl -X POST "http://127.0.0.1:8086/query" --data-urlencode 'db=prometheus' --data-urlencode 'q=SHOW SERIES' -# curl -X POST "http://127.0.0.1:8086/query" --data-urlencode 'db=NOT_prometheus' --data-urlencode 'q=SHOW SERIES' - -# curl -X POST "http://127.0.0.1:9096/write?db=NOT_prometheus" --data-binary -# 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000' diff --git a/dev/prometheus.yml b/dev/prometheus.yml deleted file mode 100644 index 0ec724c..0000000 --- a/dev/prometheus.yml +++ /dev/null @@ -1,10 +0,0 @@ -remote_write: - - url: "http://relay:9096/api/v1/prom/write?db=prometheus" - -scrape_configs: - - job_name: 'AUTOPARSE' - scrape_interval: 10s - static_configs: - - targets: ['localhost:9090'] - labels: - group: 'production' diff --git a/dev/test.toml b/dev/test.toml deleted file mode 100644 index e73a728..0000000 --- a/dev/test.toml +++ /dev/null @@ -1,36 +0,0 @@ -[[http]] -name = "test-config" -bind-addr = "0.0.0.0:9096" -health-timeout-ms = 10000 -rate-limit = 5 -burst-limit = 10 - -[[http.output]] -name="influxdb01" -location="http://influxdb:8086/" -endpoints = {write="/write", ping="/ping", query="/query"} - -[[http.output]] -name="influxdb02" -location="http://influxdb2:8086/" -endpoints = {write="/write", ping="/ping", query="/query"} -buffer-size-mb=100 -max-batch-kb=1000 -max-delay-interval="5s" - -[[http.output]] -name="influxdb03" -location="http://influxdb:8086/" -endpoints = {write="/write", ping="/ping", query="/query"} -buffer-size-mb=100 -max-batch-kb=1000 -max-delay-interval="5s" - -[[filter]] -tag-expression = "^.{0,5}$" -measurement-expression = "^.{3,12}$" -outputs = [ "influxdb01", "influxdb03" ] - -[[filter]] -tag-expression = "^.{5,12}$" -outputs = [ "influxdb02" ] diff --git a/dev/v1.toml b/dev/v1.toml deleted file mode 100644 index 42730d5..0000000 --- a/dev/v1.toml +++ /dev/null @@ -1,16 +0,0 @@ -[[http]] -name = "test-config" -bind-addr = "0.0.0.0:9096" - -[[http.output]] -name="influxdb01" -location="http://influxdb:8086/prom/write" -type="prometheus" - -[[http.output]] -name="influxdb02" -location="http://influxdb:8086/prom/write" -type="prometheus" -buffer-size-mb=100 -max-batch-kb=1000 -max-delay-interval="5s" \ No newline at end of file diff --git a/dev/v2.toml b/dev/v2.toml deleted file mode 100644 index 62cf1f1..0000000 --- a/dev/v2.toml +++ /dev/null @@ -1,16 +0,0 @@ -[[http]] -name = "test-config" -bind-addr = "0.0.0.0:9096" - -[[http.output]] -name="influxdb01" -location="http://influxdb:8086/" -endpoints = {write="/write", write_prom="/api/v1/prom/write", ping="/ping", query="/query"} - -[[http.output]] -name="influxdb02" -location="http://influxdb:8086/" -endpoints = {write="/write", write_prom="/api/v1/prom/write", ping="/ping", query="/query"} -buffer-size-mb=100 -max-batch-kb=1000 -max-delay-interval="5s" \ No newline at end of file