Skip to content

Commit

Permalink
Merge pull request #1 from kfsoftware/feature/first-release
Browse files Browse the repository at this point in the history
Feature/first release
  • Loading branch information
dviejokfs authored Jul 15, 2022
2 parents 418c235 + daad665 commit 7c2c7bb
Show file tree
Hide file tree
Showing 53 changed files with 1,796 additions and 9,002 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
with:
go-version: 1.16
-
name: Docker Login
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
24 changes: 2 additions & 22 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ before:

builds:
-
goos:
- linux
goarch:
- amd64
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{.Tag}}
flags:
- -trimpath
-
id: hlf-cc-dev
dir: hlf-cc-dev
binary: hlf-cc-dev
goos:
- linux
- darwin
Expand All @@ -46,12 +32,6 @@ builds:
flags:
- -trimpath

archives:
-
id: hlf-cc-dev
format: zip
allow_different_binary_count: true

dockers:
-
# GOOS of the built binary that should be used.
Expand All @@ -60,8 +40,8 @@ dockers:
goarch: amd64
dockerfile: Dockerfile
image_templates:
- "quay.io/kfsoftware/hlf-cc-dev:{{ .Tag }}"
- "quay.io/kfsoftware/hlf-cc-dev:latest"
- "ghcr.io/kfsoftware/hlf-cc-dev:{{ .Tag }}"
- "ghcr.io/kfsoftware/hlf-cc-dev:latest"
extra_files:
- LICENSE
- README.md
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3


RUN \
microdnf update --nodocs && \
microdnf install curl ca-certificates shadow-utils --nodocs

COPY CREDITS /licenses/CREDITS
COPY LICENSE /licenses/LICENSE
LABEL name="HLF CC Developer" \
vendor="Kung Fu Software <dviejo@kungfusoftware.es>" \
maintainer="Kung Fu Software <dviejo@kungfusoftware.es>" \
version="v1.1.0" \
release="v1.1.0"

COPY hlf-cc-dev /hlf-cc-dev

CMD ["/hlf-cc-dev"]
121 changes: 119 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,120 @@
## Chaincode as a service
## What's `hlf-cc-dev`?

`hlf-cc-dev` is a tool to start developing a new chaincode from your development environment.

### Why does this tool exist?

When developing chaincodes, we need to have an HLF network deployed, usually in our development environment. It is hard for new developers to get started since they need to know how to deploy an HLF network.

This tool aims to ease the onboarding of new developers that are not familiar with the internals of the HLF network but are interested in developing chaincodes.

The only requirement is that the developer has access to a working HLF network. This network can be set up by Administrators that are used to perform these operations, so the developer doesn't need to.

With this tool, instead of installing the chaincode in the peers, approving the chaincode definition, and finally, committing the chaincode, the developer can have the chaincode started in its machine. With one command, it can install, approve and commit the chaincode in one go. SupposeThen, ifhe developer needs to modify the chaincode logic. In that case, all it needs to do is restart the chaincode program running in its machine, just like any other application the developer is used to developing.

### What you'll need

- A TLS/TCP tunnel to your local development environment (ngrok, getout, etc.)
- Hyperledger Fabric peer with external chaincode builder enabled.
- Network config with admin users for all of the organizations peers you will use.

## General diagram

The following diagram explains the architecture of the final solution

![Diagram](./static/img/diagram.png)

## Steps to get started

To start the server, you need the network config with the admin users for each organization.

```bash
hlf-cc-dev serve --address ":8080" --metrics-address ":8081" --config "<PATH_TO_NETWORK_CONFIG>"
```

## Start development in your local environment

You need to have a chaincode that's able to be deployed as an external service; you can take a look at the following templates:

- For Go (https://github.com/kfsoftware/hlf-cc-go-template)
- For Node.JS (https://github.com/kfsoftware/hlf-cc-node-template)
- **pending** For Java (https://github.com/kfsoftware/hlf-cc-java-template)

We recommend using the Go template since it's the easiest one to get started with.

Once you have the chaincode project set up on your local machine, you need to expose your server to the public; the easiest way to do this is to use a TLS/TCP tunnel, for example, [ngrok](https://ngrok.com/download).

```bash
ngrok tcp 9999 --region=eu # region can be us, eu, au, ap, sa, jp, in
```
The previous command will have this output:

![ngrok](./static/img/ngrok-tunnel.png)

Copy the Forwarding URL, but remove the `tcp://` part; for example, if you got `tcp://6.tcp.eu.ngrok.io:19922`, then you want to use `6.tcp.eu.ngrok.io:19922` for the following command(hlf-cc-dev).

After having exposed your chaincode server to the public, you can run the following command to trigger:

- Installation of the chaincode on the peers.
- Approval of the chaincode definition.
- Committing the chaincode definition.

```bash
CHAINCODE_NAME=template_go
API_URL="http://localhost:8080/graphql"
SIGNATURE_POLICY="OR('Org1MSP.member', 'Org2MSP.member')"
CHAINCODE_ADDRESS_TUNNEL="4.tcp.eu.ngrok.io:13438" # the forwarding URL you get from opening an ngrok tunnel
hlf-cc-dev start --localChaincode="localhost:9999" \
--chaincodeAddress="${CHAINCODE_ADDRESS_TUNNEL}" \
--chaincode="${CHAINCODE_NAME}" \
--signaturePolicy="${SIGNATURE_POLICY}" \
--env-file="${PWD}/.env" \
--apiUrl="${API_URL}"
```

After the successful execution of the previous command, you can follow the instructions on the README.md for each template.

For example, for Go, you would run the following command:

```bash
source .env && go run ./main.go
```

Then you can go to http://localhost:8080/graphql and test the chaincode by running the following mutation:

```graphql
mutation invoke {
invokeChaincode(input:{
chaincodeName:"template_go"
function: "InitLedger"
args: []
transientMap: []
}){
response
transactionID
chaincodeStatus
}
}

mutation query {
queryChaincode(input:{
chaincodeName:"template_go"
function: "GetAllAssets"
args: []
transientMap: []
}){
response
chaincodeStatus
}
}

```

If there are any issues you run into with the previous mutations, this can be because:
- The network config used to start the server is not correct.
- The users set up in the network config are not admins.
- The chaincode name is not valid.
- The chaincode function is not valid.

If after checking the previous things you still get an error, please, [you can open an issue](https://github.com/kfsoftware/hlf-cc-dev/issues/new)

Documentation: TODO
Loading

0 comments on commit 7c2c7bb

Please sign in to comment.