Skip to content

Commit

Permalink
Merge pull request #11 from insidieux/consul-catalog-registry
Browse files Browse the repository at this point in the history
Add consul variations: consul agent and consul catalog
  • Loading branch information
insidieux authored Feb 2, 2021
2 parents e6f28d3 + ae919bc commit 903564c
Show file tree
Hide file tree
Showing 32 changed files with 980 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: test/coverage.out
file: coverage.out

binary:
name: Build binary
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea
/vendor

/coverage.out
mock_*_test.go
wire_gen.go
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all: cleanup vendor wire lint test build
.PHONY: cleanup
cleanup:
@rm ${PWD}/bin/${APP_NAME}* || true
@rm ${PWD}/tests/coverage.out || true
@rm ${PWD}/coverage.out || true
@find ${PWD} -type f -name "wire_gen.go" -delete
@find ${PWD} -type f -name "mock_*_test.go" -delete
@rm -r ${PWD}/vendor || true
Expand Down Expand Up @@ -80,7 +80,7 @@ lint:

.PHONY: test
test:
@rm -r ${PWD}/test/coverage.out || true
@rm -r ${PWD}/coverage.out || true
@docker run --rm \
-v ${PWD}:/project \
-w /project \
Expand All @@ -89,7 +89,7 @@ test:
-race \
-mod vendor \
-covermode=atomic \
-coverprofile=/project/test/coverage.out \
-coverprofile=/project/coverage.out \
/project/...

.PHONY: build
Expand Down Expand Up @@ -143,7 +143,6 @@ endif
@docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD} ${DOCKER_REGISTRY}
@docker push ${DOCKER_IMAGE}:${DOCKER_TAG}


.PHONY: mockery
mockery:
ifndef MOCKERY_SOURCE_DIR
Expand Down
6 changes: 6 additions & 0 deletions cmd/pinchy/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ func NewCommand(version string) *cobra.Command {
Use: sourceProvider.Name(),
Short: fmt.Sprintf(`Fetch data from source "%s"`, sourceProvider.Name()),
}
if sourceProvider.Deprecated() {
sourceCmd.Deprecated = fmt.Sprintf(`source "%s" is deprecated`, sourceProvider.Name())
}
for _, registryProvider := range registry.GetProviderList() {
registryCmd := &cobra.Command{
Use: registryProvider.Name(),
Short: fmt.Sprintf(`Save data in registry "%s"`, registryProvider.Name()),
}
if registryProvider.Deprecated() {
registryCmd.Deprecated = fmt.Sprintf(`registry "%s" is deprecated`, registryProvider.Name())
}
onceCommand := &cobra.Command{
Use: `once`,
Short: `Run main process only once: sync and return result`,
Expand Down
19 changes: 19 additions & 0 deletions configs/source/file/consul-agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: service-name
address: 127.0.0.1
id: service-id-1
port: 80
tags:
- tag-1
- tag-2
meta:
key: value

- name: service-name
address: 127.0.0.2
id: service-id-2
port: 80
tags:
- tag-1
- tag-2
meta:
key: value
25 changes: 25 additions & 0 deletions configs/source/file/consul-catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- name: service-name
address: 127.0.0.1
id: service-id
port: 80
tags:
- tag-1
- tag-2
meta:
key: value
node:
node: node-1
address: 127.0.0.100

- name: service-name
address: 127.0.0.2
id: service-id-2
port: 80
tags:
- tag-1
- tag-2
meta:
key: value
node:
node: node-1
address: 127.0.0.100
9 changes: 0 additions & 9 deletions configs/source/file/example.yml

This file was deleted.

21 changes: 17 additions & 4 deletions deployments/docker-compose/pinchy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
version: '3'

services:
pinchy:
image: insidieux/pinchy:v1.0.0
pinchy-1:
image: insidieux/pinchy:v1.1.0
volumes:
- ./configs/source/file:/etc/pinchy
command:
- 'file'
- 'consul'
- 'consul-agent'
- '--source.path'
- '/etc/pinchy/example.yml'
- '/etc/pinchy/consul-agent.yml'
- '--registry.address'
- 'http://consul:8500'
- 'once'
pinchy-2:
image: insidieux/pinchy:v1.1.0
volumes:
- ./configs/source/file:/etc/pinchy
command:
- 'file'
- 'consul-catalog'
- '--source.path'
- '/etc/pinchy/consul-catalog.yml'
- '--registry.address'
- 'http://consul:8500'
- 'once'

2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- [Contributing guide][]

[User guide]: ./user-guide.md
[Contributing guide]: ./contributing-guide.md
[Contributing guide]: ./contributing.md
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
- Add new sub directory to `/internal/extension/{source,registry}`
- Put wiring code for dynamic load implementations:
- Register implementation of `ProviderInterface` at `init` function
- Add anonymous import to `/cmd/pinchy/modules.go`
- Add anonymous import to `/cmd/pinchy/internal/modules.go`
16 changes: 16 additions & 0 deletions docs/registry/consul.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Pinchy registry "Consul"

## Available variations

### consul-agent [**Deprecated!**]

Registry work with Consul agent HTTP API

### consul-agent

Registry work with Consul agent HTTP API

### consul-catalog

Registry work with Consul catalog HTTP API


## Available flags

```
--registry.address string Consul http api address (default "127.0.0.1:8500")
--registry.tag string Common service tag added for all registered service (default "pinchy")
```
4 changes: 3 additions & 1 deletion docs/source/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

## services.yml example

Example services.yml file be found in [configs](./../../configs/source/file/example.yml) file.
Example services.yml file be found in configs directory:
* [Consul agent registry](../../configs/source/file/consul-agent.yml) file.
* [Consul catalog registry](../../configs/source/file/consul-catalog.yml) file.
19 changes: 7 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ go 1.15

require (
github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b
github.com/google/wire v0.4.0
github.com/hashicorp/consul/api v1.7.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/google/wire v0.5.0
github.com/hashicorp/consul/api v1.8.1
github.com/pkg/errors v0.9.1
github.com/sethvargo/go-signalcontext v0.1.0
github.com/sirupsen/logrus v1.2.0
github.com/spf13/afero v1.2.2
github.com/spf13/cast v1.3.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/afero v1.5.1
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/thoas/go-funk v0.7.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
Loading

0 comments on commit 903564c

Please sign in to comment.