Skip to content

Commit

Permalink
[WIP] Add minikube to devcontainer
Browse files Browse the repository at this point in the history
Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed Apr 26, 2024
1 parent 60f50b5 commit 5086fec
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
18 changes: 17 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,34 @@
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers-contrib/features/mkdocs:2": {
"plugins": "mkdocs-material mike"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"version": "latest",
"helm": "latest",
"minikube": "latest"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/postCreateCommand.sh"
"postCreateCommand": ".devcontainer/postCreateCommand.sh",

// Use 'postStartCommand' to run commands after the container is created like starting minikube.
"postStartCommand": "nohup bash -c 'minikube start &' > minikube.log 2>&1",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"

"remoteEnv": {
"KUBECONFIG_PATH": "${localWorkspaceFolder}/.fabric/kubeconfig"
}
}
21 changes: 14 additions & 7 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
#
set -eu

export GOOS=$(go env GOOS)
export GOARCH=$(go env GOARCH)
mkdir -p "${HOME}"/.local/bin

export GOENV_OS=$(go env GOOS)
export GOENV_ARCH=$(go env GOARCH)
export UNAME_KERNAL=$(uname -s)

#
# Install k9s
#
curl -sSL https://github.com/derailed/k9s/releases/download/v0.32.4/k9s_${UNAME_KERNAL}_${GOENV_ARCH}.tar.gz | tar -zxf - -C "${HOME}/.local/bin/" k9s && chmod +x "${HOME}/.local/bin/k9s"

#
# Install yq
#
mkdir -p "${HOME}"/.local/bin
curl -sSLo "${HOME}"/.local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_${GOOS}_${GOARCH} && chmod +x "${HOME}"/.local/bin/yq
curl -sSLo "${HOME}/.local/bin/yq" https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_${GOENV_OS}_${GOENV_ARCH} && chmod +x "${HOME}/.local/bin/yq"

#
# Install fabric binaries and the nano test network
Expand All @@ -32,9 +39,9 @@ cd ..
# Add k8s builder config to fabric core.yaml
#
# To install the k8s builder use the following command:
# GOBIN="${PWD}"/.fabric/builders/k8s_builder go install ./cmd/...
# GOBIN="${PWD}"/.fabric/builders/k8s_builder/bin go install ./cmd/...
#
export FABRIC_K8S_BUILDER_PATH="${PWD}"/.fabric/builders/k8s_builder
mkdir -p "${FABRIC_K8S_BUILDER_PATH}"
export FABRIC_K8S_BUILDER_PATH="${PWD}/.fabric/builders/k8s_builder"
mkdir -p "${FABRIC_K8S_BUILDER_PATH}/bin"

yq -i '.chaincode.externalBuilders += { "name": "k8s_builder", "path": "${FABRIC_K8S_BUILDER_PATH}" | envsubst(ne), "propagateEnvironment": [ "CORE_PEER_ID", "KUBECONFIG_PATH" ] }' .fabric/config/core.yaml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
.idea/

.fabric

*.log
63 changes: 63 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,69 @@ We use [pull requests](http://help.github.com/pull-requests/) to deliver changes

Please to try to be consistent with the rest of the code and conform to linting rules where they are provided.

## Development environment

```
GOBIN="${PWD}"/.fabric/builders/k8s_builder/bin go install ./cmd/...
```

```
kubectl config view --minify --flatten --raw --context=minikube > "${PWD}/.fabric/kubeconfig"
```

Start the fans!

```
./network start
```


```shell
curl -fsSL \
https://github.com/hyperledger-labs/fabric-builder-k8s/releases/download/v0.7.2/go-contract-v0.7.2.tgz \
-o go-contract-v0.7.2.tgz
```

Set up the environment for running peer commands and check everything is working.

```
. ./peer1admin.sh
peer channel list
```

Deploy the chaincode package as usual, starting by installing the k8s chaincode package.

```shell
peer lifecycle chaincode install go-contract-v0.7.2.tgz
```

Export a `PACKAGE_ID` environment variable for use in the following commands.

```shell
export PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid go-contract-v0.7.2.tgz) && echo $PACKAGE_ID
```

Note: the `PACKAGE_ID` must match the chaincode code package identifier shown by the `peer lifecycle chaincode install` command.

Approve the chaincode.

```shell
peer lifecycle chaincode approveformyorg -o 127.0.0.1:6050 --channelID mychannel --name sample-contract --version 1 --package-id $PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
```

Commit the chaincode.

```shell
peer lifecycle chaincode commit -o 127.0.0.1:6050 --channelID mychannel --name sample-contract --version 1 --sequence 1 --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
```

Query the chaincode metadata!

```shell
peer chaincode query -C mychannel -n sample-contract -c '{"Args":["org.hyperledger.fabric:GetMetadata"]}'
```


## Code of Conduct Guidelines <a name="conduct"></a>

See our [Code of Conduct Guidelines](./CODE_OF_CONDUCT.md).
Expand Down

0 comments on commit 5086fec

Please sign in to comment.