Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit 5b67922

Browse files
authored
Merge pull request #16 from inloco/feature/elastic-auth
Feature/elastic auth
2 parents d584e94 + 8a9af0e commit 5b67922

File tree

8 files changed

+144
-79
lines changed

8 files changed

+144
-79
lines changed

.circleci/config.yml

Lines changed: 120 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
version: 2
1+
version: 2.1
2+
defaults: &defaults
3+
environment:
4+
DOCKER_REPO: inlocomedia/kafka-elasticsearch-injector-go
25
jobs:
3-
build:
4-
environment:
5-
- PACKAGE_PATH: "github.com/inloco/kafka-elasticsearch-injector"
6+
test:
7+
<<: *defaults
68
docker:
79
- image: circleci/golang:1.12
8-
environment:
9-
DOCKER_REPO: inlocomedia/kafka-elasticsearch-injector-go
1010
- image: confluentinc/cp-zookeeper:3.1.1
1111
environment:
1212
- ZOOKEEPER_CLIENT_PORT=2181
@@ -27,9 +27,6 @@ jobs:
2727
transport.host: 127.0.0.1
2828
steps:
2929
- checkout
30-
- run:
31-
name: Generate helper files
32-
command: echo $(git rev-parse --short HEAD) > HEAD
3330
- setup_remote_docker:
3431
reusable: true
3532
- run:
@@ -47,34 +44,125 @@ jobs:
4744
until nc -z localhost 9200 || ((count ++ >= 10)); \
4845
do echo "Retrying: Verify if Elasticsearch is ready"; sleep 5; done
4946
- run:
50-
name: "Run project tests (excluding vendor)"
51-
command: go test $(go list ./... | grep -v /vendor/)
47+
name: "Run tests"
48+
command: make test
49+
- save_cache:
50+
key: go-mod-v4-{{ checksum "go.sum" }}
51+
paths:
52+
- "/go/pkg/mod"
53+
build-image:
54+
<<: *defaults
55+
docker:
56+
- image: circleci/golang:1.12
57+
steps:
58+
- checkout
59+
- setup_remote_docker:
60+
reusable: true
61+
docker_layer_caching: true
62+
- run:
63+
name: Make `golang get` play nice with bitbucket and github repositories
64+
command: |
65+
git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"
66+
git config --global url."git@github.com:".insteadOf "https://github.com/"
67+
cat ~/.gitconfig
68+
ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
69+
ssh-keyscan github.com >> ~/.ssh/known_hosts
70+
- restore_cache:
71+
keys:
72+
- go-mod-v4-{{ checksum "go.sum" }}
5273
- run:
53-
name: Build injector
54-
command: GOOS=linux GOARCH=386 go build -a --ldflags="-s" -o bin/injector cmd/injector.go
74+
name: Compile binary
75+
command: make compile-binary
5576
- run:
56-
name: Build injector docker image
77+
name: Build docker images
5778
command: |
5879
docker build --rm=false -t "${DOCKER_REPO}:ci" -f cmd/Dockerfile .
59-
- save_cache:
60-
key: go-mod-v4-{{ checksum "go.sum" }}
80+
- run:
81+
name: Save docker images and version description files
82+
command: |
83+
mkdir -p /tmp/workspace
84+
docker save -o /tmp/workspace/image.tar $DOCKER_REPO:ci
85+
(git describe --abbrev=0 2>/dev/null | sed 's/[^0-9\\.]*//g' || echo -n "0.0.0") > /tmp/workspace/TAG
86+
(git rev-parse --short HEAD) > /tmp/workspace/HEAD
87+
- persist_to_workspace:
88+
root: /tmp/workspace
6189
paths:
62-
- "/go/pkg/mod"
63-
- deploy:
64-
name: Push to Docker Hub
90+
- image.tar
91+
- TAG
92+
- HEAD
93+
94+
deploy-image:
95+
<<: *defaults
96+
docker:
97+
- image: circleci/python:3.7
98+
steps:
99+
- setup_remote_docker:
100+
reusable: true
101+
- attach_workspace:
102+
at: /tmp/workspace
103+
- run:
104+
name: Restore docker images from build
105+
command: |
106+
docker load -i /tmp/workspace/image.tar
107+
- run:
108+
name: "docker login"
109+
command: docker login --username $DOCKER_USER --password $DOCKER_PASSWORD
110+
- run:
111+
name: Push images
65112
command: |
66-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
67-
docker tag "${DOCKER_REPO}:ci" "${DOCKER_REPO}:$(cat VERSION)"
68-
docker push "${DOCKER_REPO}:$(cat VERSION)"
69-
docker tag "${DOCKER_REPO}:ci" "${DOCKER_REPO}:master"
70-
docker push "${DOCKER_REPO}:master"
71-
elif [[ $(echo "${CIRCLE_BRANCH}"| grep -c -e "hotfix\/.*") -gt 0 ]]; then
72-
docker tag "${DOCKER_REPO}:ci" "${DOCKER_REPO}:$(cat VERSION)-pre"
73-
docker push "${DOCKER_REPO}:$(cat VERSION)-pre"
74-
elif [[ $(echo "${CIRCLE_BRANCH}"| grep -c -e "release\/.*") -gt 0 ]]; then
75-
docker tag "${DOCKER_REPO}:ci" "${DOCKER_REPO}:$(cat VERSION)-pre"
76-
docker push "${DOCKER_REPO}:$(cat VERSION)-pre"
113+
export TAG=$(cat /tmp/workspace/TAG)
114+
export HEAD=$(cat /tmp/workspace/HEAD)
115+
export VERSION=$(echo -n "$TAG-$HEAD")
116+
117+
if [ -z $CIRCLE_TAG ]; then
118+
docker tag $DOCKER_REPO:ci $DOCKER_REPO:$VERSION
119+
docker push $DOCKER_REPO:$VERSION
120+
echo "Pushed $DOCKER_REPO:$VERSION"
77121
else
78-
docker tag "${DOCKER_REPO}:ci" "${DOCKER_REPO}:$(cat VERSION)-$(cat HEAD)"
79-
docker push "${DOCKER_REPO}:$(cat VERSION)-$(cat HEAD)"
122+
docker tag $DOCKER_REPO:ci $DOCKER_REPO:$TAG
123+
docker push $DOCKER_REPO:$TAG
124+
echo "Pushed $DOCKER_REPO:$TAG"
80125
fi
126+
workflows:
127+
version: 2.1
128+
test-and-deploy-image-for-commit:
129+
jobs:
130+
- test:
131+
filters:
132+
branches:
133+
ignore: /master/
134+
- build-image:
135+
filters:
136+
branches:
137+
ignore: /master/
138+
- deploy-image:
139+
context: media
140+
requires:
141+
- build-image
142+
filters:
143+
branches:
144+
ignore: /master/
145+
test-and-deploy-image-for-tag:
146+
jobs:
147+
- test:
148+
filters:
149+
tags:
150+
only: /.+/
151+
branches:
152+
ignore: /.*/
153+
- build-image:
154+
filters:
155+
tags:
156+
only: /.+/
157+
branches:
158+
ignore: /.*/
159+
- deploy-image:
160+
context: media
161+
requires:
162+
- test
163+
- build-image
164+
filters:
165+
tags:
166+
only: /.+/
167+
branches:
168+
ignore: /.*/

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
go/deps:
2-
dep ensure -v
3-
41
test:
52
go test $$(go list ./... | grep -v /vendor/)
63

7-
docker/build:
4+
compile-binary:
85
GOOS=linux GOARCH=386 go build -o bin/injector cmd/injector.go
6+
7+
docker/build: compile-binary
98
GOOS=linux GOARCH=386 go build -o bin/producer util/producer/producer.go
109
docker build --rm=false -t "inlocomedia/kafka-elasticsearch-injector:local" -f cmd/Dockerfile .
1110
docker build --rm=false -t "inlocomedia/kafka-elasticsearch-injector:producer-local" -f util/producer/Dockerfile .

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ To create new injectors for your topics, you should create a new kubernetes depl
2121
- `PROBES_PORT` Kubernetes probes port. Set to any available port. **REQUIRED**
2222
- `K8S_LIVENESS_ROUTE` Kubernetes route for liveness check. **REQUIRED**
2323
- `K8S_READINESS_ROUTE`Kubernetes route for readiness check. **REQUIRED**
24+
- `ELASTICSEARCH_USER` Elasticsearch user. **OPTIONAL**
25+
- `ELASTICSEARCH_PASSWORD` Elasticsearch password. **OPTIONAL**
2426
- `KAFKA_CONSUMER_CONCURRENCY` Number of parallel goroutines working as a consumer. Default value is 1 **OPTIONAL**
2527
- `KAFKA_CONSUMER_BATCH_SIZE` Number of records to accumulate before sending them to elasticsearch(for each goroutine). Default value is 100 **OPTIONAL**
2628
- `ES_INDEX_COLUMN` Record field to append to index name. Ex: to create one ES index per campaign, use "campaign_id" here **OPTIONAL**

VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ require (
99
github.com/datamountaineer/schema-registry v0.0.0-20170721142813-6240b64c5baa
1010
github.com/go-kit/kit v0.8.0
1111
github.com/inloco/goavro v0.0.0-20180215164239-eba86de05ad3
12+
github.com/kr/pretty v0.1.0 // indirect
1213
github.com/olivere/elastic/v7 v7.0.1
1314
github.com/onsi/ginkgo v1.8.0 // indirect
1415
github.com/onsi/gomega v1.5.0 // indirect
15-
github.com/pierrec/xxHash v0.1.1 // indirect
1616
github.com/pkg/errors v0.8.1
1717
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
1818
github.com/stretchr/testify v1.2.2

0 commit comments

Comments
 (0)