Skip to content

Commit d44b140

Browse files
author
Gregory Hill
committed
fix js dynamic proto load and add js integration test
Signed-off-by: Gregory Hill <[email protected]>
1 parent 6a3397a commit d44b140

29 files changed

+349
-2981
lines changed

Diff for: .circleci/Dockerfile

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
FROM circleci/golang:1.11
1+
FROM golang:1.11-alpine
22

3-
RUN curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
4-
RUN unzip protoc-3.3.0-linux-x86_64.zip -d protobuf
5-
RUN sudo cp protobuf/bin/protoc /usr/bin/protoc
3+
ENV PROTO_VERSION 3.3.0
4+
ENV DCOMP_VERSION 1.23.2
5+
6+
RUN apk add --update --no-cache nodejs npm make curl unzip git python bash gcc docker build-base
7+
8+
RUN curl -L "https://github.com/docker/compose/releases/download/${DCOMP_VERSION}/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
9+
RUN curl -OL https://github.com/google/protobuf/releases/download/v${PROTO_VERSION}/protoc-${PROTO_VERSION}-linux-x86_64.zip
10+
RUN unzip protoc-${PROTO_VERSION}-linux-x86_64.zip -d protobuf
11+
RUN cp protobuf/bin/protoc /usr/bin/protoc
612
RUN rm -rf protobuf protoc-*
13+
714
RUN go get -u golang.org/x/tools/cmd/goimports
815
RUN go get -u github.com/golang/protobuf/protoc-gen-go
916
RUN go get -u github.com/golang/dep/cmd/dep
10-
RUN go get -u github.com/goreleaser/goreleaser
1117

1218
# install aws auth binaries
1319
RUN curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
1420
RUN unzip awscli-bundle.zip
15-
RUN sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
21+
RUN ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
1622

1723
# install gcloud auth binaries
1824
RUN curl https://sdk.cloud.google.com | bash
19-
RUN ls /home/circleci/google-cloud-sdk/bin/
20-
ENV PATH /home/circleci/google-cloud-sdk/bin/:$PATH
25+
RUN ls /root/google-cloud-sdk/bin/
26+
ENV PATH /root/google-cloud-sdk/bin/:$PATH

Diff for: .circleci/config.yml

+31-33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ setup_docker: &setup_docker
1212

1313
version: 2
1414
jobs:
15+
ensure_vendor:
16+
<<: *defaults
17+
steps:
18+
- checkout
19+
- run: make ensure_vendor
20+
1521
test:
1622
<<: *defaults
1723
steps:
@@ -20,47 +26,40 @@ jobs:
2026
- run: make test
2127
- run: make build
2228

23-
test_integration:
29+
build_docker:
2430
<<: *defaults
2531
steps:
32+
- checkout
2633
- setup_remote_docker:
2734
<<: *setup_docker
28-
- checkout
29-
- run:
30-
name: Store Service Account
31-
command: echo $GCLOUD_SERVICE_KEY > /tmp/gcloud-service-key.json
32-
- run: gcloud auth activate-service-account --key-file=/tmp/gcloud-service-key.json
33-
- run: make test_integration
35+
- run: make docker_build
3436

35-
ensure_vendor:
37+
test_js:
3638
<<: *defaults
3739
steps:
3840
- checkout
39-
- run: make ensure_vendor
41+
- run: make npm_install
42+
- run: make test_js
4043

41-
build_docker:
42-
<<: *defaults
43-
steps:
44-
- checkout
45-
- setup_remote_docker:
46-
<<: *setup_docker
47-
- run: make docker_build
48-
49-
release_dev:
44+
test_integration:
5045
<<: *defaults
5146
steps:
5247
- setup_remote_docker:
5348
<<: *setup_docker
5449
- checkout
55-
- run: make release_dev
50+
- run:
51+
name: Store Service Account
52+
command: echo $GCLOUD_SERVICE_KEY > /tmp/gcloud-service-key.json
53+
- run: gcloud auth activate-service-account --key-file=/tmp/gcloud-service-key.json
54+
- run: make test_integration
5655

57-
release:
56+
push_latest:
5857
<<: *defaults
5958
steps:
6059
- setup_remote_docker:
6160
<<: *setup_docker
6261
- checkout
63-
- run: make release
62+
- run: make latest
6463

6564
workflows:
6665
version: 2
@@ -76,35 +75,34 @@ workflows:
7675
filters:
7776
<<: *tags_filters
7877

79-
- test_integration:
78+
- build_docker:
8079
requires:
8180
- test
8281
filters:
8382
<<: *tags_filters
84-
branches:
85-
only:
86-
- develop
87-
- master
8883

89-
- build_docker:
84+
- test_js:
9085
requires:
9186
- test
9287
filters:
9388
<<: *tags_filters
9489

95-
- release_dev:
90+
- test_integration:
9691
requires:
97-
- build_docker
98-
- test_integration
92+
- test
9993
filters:
94+
<<: *tags_filters
10095
branches:
101-
only: develop
96+
only:
97+
- develop
98+
- master
10299

103-
- release:
100+
- push_latest:
104101
requires:
105102
- build_docker
106103
- test_integration
107104
filters:
108105
<<: *tags_filters
109106
branches:
110-
ignore: /.*/
107+
only:
108+
- master

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ notes.md
2121

2222
commit_hash.txt
2323
node_modules
24-
hoard-js/node_modules
2524

2625
.vscode/

Diff for: Makefile

+26-10
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ GOFILES_NOVENDOR := $(shell find . -path ./vendor -prune -o -name '*.pb.go' -pru
2424
PACKAGES_NOVENDOR := $(shell go list ./...)
2525

2626
# Protobuf generated go files
27-
PROTO_FILES = $(shell find . -path ./vendor -prune -o -path ./hoard-js/node_modules -prune -o -type f -name '*.proto' -print)
27+
PROTO_FILES = $(shell find . -path ./vendor -prune -o -path ./hoard-js -prune -o -path ./node_modules -prune -o -type f -name '*.proto' -print)
2828
PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES))
2929
PROTO_GO_FILES_REAL = $(shell find . -path ./vendor -prune -o -type f -name '*.pb.go' -print)
3030

3131
OS_ARCHS := "linux/arm linux/386 linux/amd64 darwin/386 darwin/amd64 windows/386 windows/amd64"
3232
DIST := "dist"
3333
GOX_OUTPUT := "$DIST/{{.Dir}}_{{.OS}}_{{.Arch}}"
34-
BUILD_IMAGE := "quay.io/monax/hoard:build"
34+
export DOCKER_HUB := quay.io
35+
export DOCKER_REPO := $(DOCKER_HUB)/monax/hoard
36+
export BUILD_IMAGE := $(DOCKER_REPO):build
3537

3638

3739
# Formatting, linting and vetting
@@ -122,7 +124,7 @@ install:
122124
build: check build_hoard build_hoarctl
123125

124126
.PHONY: docker_build
125-
docker_build: check commit_hash
127+
docker_build: commit_hash
126128
@scripts/build_tool.sh
127129

128130
## build binaries for all architectures
@@ -136,6 +138,12 @@ build_dist:
136138
test: check
137139
@scripts/bin_wrapper.sh go test -v ./... ${GOPACKAGES_NOVENDOR}
138140

141+
.PHONY: test_js
142+
test_js: build install
143+
$(eval HID := $(shell HOARD_JSON_CONFIG=$$(hoard config -j memory) hoard -e &> /dev/null & echo $$!))
144+
npm test
145+
kill ${HID}
146+
139147
## run tests including integration tests
140148
.PHONY: test_integration
141149
test_integration: check
@@ -170,24 +178,32 @@ NOTES.md: project/history.go project/cmd/notes/main.go
170178
docs: CHANGELOG.md NOTES.md
171179

172180
## tag the current HEAD commit with the current release defined in
173-
## ./release/release.go
181+
## ./project/history.go
174182
.PHONY: tag_release
175183
tag_release: test check docs build
176184
@scripts/tag_release.sh
177185

178186
.PHONY: release
179-
release: docs check test docker_build
187+
release: tag_release
180188
@scripts/is_checkout_dirty.sh || (echo "checkout is dirty so not releasing!" && exit 1)
181189
@scripts/release.sh
182190

183-
.PHONY: release_dev
184-
release_dev: test docker_build
185-
@scripts/release_dev.sh
191+
.PHONY: latest
192+
latest:
193+
@scripts/release.sh latest
186194

187195
.PHONY: build_ci_image
188196
build_ci_image:
189-
docker build -t ${CI_IMAGE} -f ./.circleci/Dockerfile .
197+
docker build -t ${BUILD_IMAGE} -f ./.circleci/Dockerfile .
190198

191199
.PHONY: push_ci_image
192200
push_ci_image: build_ci_image
193-
docker push ${CI_IMAGE}
201+
docker push ${BUILD_IMAGE}
202+
203+
.PHONY: npm_install
204+
npm_install:
205+
@cd hoard-js && npm install
206+
207+
.PHONY: npm_publish
208+
npm_publish:
209+
npm publish --access public .

Diff for: README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ The address is then deterministically generated from the encrypted object's (SHA
1717
- [Azure](https://azure.microsoft.com/en-gb/services/storage/)
1818
- [IPFS](https://ipfs.io/)
1919

20-
### Planned
21-
- [BigchainDB](https://www.bigchaindb.com/) (and IPDB)
22-
- [Tendermint](https://tendermint.com/)
23-
2420
## Installing
2521

2622
Hoard should be go-gettable with:
@@ -161,6 +157,33 @@ Hoard uses [GRPC](https://grpc.io/) for its API for which there is a wide range
161157

162158
A Javascript client library can be found here: [hoard-js](https://github.com/monax/hoard/tree/master/hoard-js).
163159

160+
Hoard-js is a fairly lightweight wrapper around the Hoard GRPC API. It mainly serves to abstract over the dynamic
161+
protobuf library and the static protobuf generation.
162+
163+
#### Usage
164+
165+
First we need to have Hoard running. For development purposes this can be accomplished by:
166+
167+
```shell
168+
go get github.com/monax/hoard/cmd/hoard
169+
# Run Hoard with logging
170+
hoard --logging
171+
```
172+
173+
Hoard will run with an in-memory store by default that will be discarded when it is shutdown, but will expose the same
174+
interface as when using remote storage backends.
175+
176+
To interact with Hoard from Node see [example.js](example.js) for a self-contained example of how to use every method
177+
of the API. To run use:
178+
179+
```shell
180+
# Get dependencies
181+
npm install
182+
# Run example
183+
node example.js
184+
```
185+
186+
164187
## Building
165188

166189
To build Hoard you will need to have the following installed:
@@ -176,3 +199,4 @@ make protobuf_deps
176199
# Run checks, tests, and build binaries
177200
make build && make install
178201
```
202+

Diff for: grant/grant.pb.go

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: grant/openpgp.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// OpenPGPGrant encrypts and signs a given reference
19-
func OpenPGPGrant(ref *reference.Ref, public []byte, private *secrets.OpenPGPSecret) ([]byte, error) {
19+
func OpenPGPGrant(ref *reference.Ref, public string, private *secrets.OpenPGPSecret) ([]byte, error) {
2020
if private == nil {
2121
return nil, fmt.Errorf("cannot encrypt because no private key was provided")
2222
}
@@ -28,9 +28,9 @@ func OpenPGPGrant(ref *reference.Ref, public []byte, private *secrets.OpenPGPSec
2828
}
2929

3030
var to openpgp.EntityList
31-
if public != nil {
31+
if public != "" {
3232
// use public keyring
33-
if to, err = openpgp.ReadArmoredKeyRing(bytes.NewBuffer(public)); err != nil {
33+
if to, err = openpgp.ReadArmoredKeyRing(bytes.NewBufferString(public)); err != nil {
3434
return nil, fmt.Errorf("could not read public keyring: %s", err)
3535
}
3636
} else {

0 commit comments

Comments
 (0)