Skip to content

Commit

Permalink
Merge pull request #361 from hyperledger-labs/kubernetes
Browse files Browse the repository at this point in the history
Experimental Kubernetes support
  • Loading branch information
dzikowski authored Jul 14, 2023
2 parents 1d763eb + a8ece15 commit f0b6d09
Show file tree
Hide file tree
Showing 74 changed files with 9,349 additions and 4,599 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea
e2e
e2e-network
fablo-target
node_modules
Jenkinsfile
Expand Down
99 changes: 66 additions & 33 deletions .github/workflows/test-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
./fablo-build.sh
- name: Test simple network
run: e2e-network/test-01-simple.sh
run: e2e-network/docker/test-01-simple.sh

- uses: actions/upload-artifact@v2
if: always()
with:
name: test-main
path: |
e2e-network/test-01-simple.sh.logs/*
e2e-network/test-01-simple.sh.tmpdir/fablo-target/**/*
e2e-network/docker/test-01-simple.sh.logs/*
e2e-network/docker/test-01-simple.sh.tmpdir/fablo-target/**/*
- name: Test generators
run: |
Expand All @@ -39,6 +39,60 @@ jobs:
- name: Lint
run: npm run lint && ./lint.sh
test-k8:
needs: test-main
runs-on: ubuntu-latest
timeout-minutes: 30
steps:

- name: Check out repository code
uses: actions/checkout@v2

- name: install k8, hlf plugin and helm
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.14.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind create cluster --wait 5m
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
kubectl krew install hlf
if [ -f "~/.bashrc" ]; then
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
fi
if [ -f "~/.zshrc" ]; then
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
fi
helm repo add kfs "https://kfsoftware.github.io/hlf-helm-charts" --force-update
helm install hlf-operator --version=1.8.0 kfs/hlf-operator
- name: Build Fablo
run: |
shellcheck --version && \
yamllint -v && \
npm install && \
npm run build && \
./fablo-build.sh
- name: fablo k8 tests
run: |
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
e2e-network/k8s/test-01-simple-k8s.sh
test-02-raft:
needs: test-main
Expand All @@ -55,15 +109,15 @@ jobs:
./fablo-build.sh
- name: Test RAFT network
run: e2e-network/test-02-raft-2orgs.sh
run: e2e-network/docker/test-02-raft-2orgs.sh

- uses: actions/upload-artifact@v2
if: always()
with:
name: test-02-raft
path: |
e2e-network/test-02-raft.sh.logs/*
e2e-network/test-02-raft.sh.tmpdir/fablo-target/**/*
e2e-network/docker/test-02-raft.sh.logs/*
e2e-network/docker/test-02-raft.sh.tmpdir/fablo-target/**/*
test-03-private-data:
needs: test-main
Expand All @@ -80,15 +134,15 @@ jobs:
./fablo-build.sh
- name: Test private data
run: e2e-network/test-03-private-data.sh
run: e2e-network/docker/test-03-private-data.sh

- uses: actions/upload-artifact@v2
if: always()
with:
name: test-03-private-data
path: |
e2e-network/test-03-private-data.sh.logs/*
e2e-network/test-03-private-data.sh.tmpdir/fablo-target/**/*
e2e-network/docker/test-03-private-data.sh.logs/*
e2e-network/docker/test-03-private-data.sh.tmpdir/fablo-target/**/*
test-04-snapshot:
needs: test-main
Expand All @@ -105,33 +159,12 @@ jobs:
./fablo-build.sh
- name: Test snapshots
run: e2e-network/test-04-snapshot.sh
run: e2e-network/docker/test-04-snapshot.sh

- uses: actions/upload-artifact@v2
if: always()
with:
name: test-04-snapshot
path: |
e2e-network/test-04-snapshot.sh.logs/*
e2e-network/test-04-snapshot.sh.tmpdir/fablo-target/**/*
node-chaincodes-unit-tests:
needs: test-main
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Test chaincode for Fabric 1.4.x
run: |
cd samples/chaincodes/chaincode-kv-node-1.4 && \
npm install && \
npm run build && \
npm run test
- name: Test chaincode for Fabric 2.x
run: |
cd samples/chaincodes/chaincode-kv-node && \
npm install && \
npm run build && \
npm run test
e2e-network/docker/test-04-snapshot.sh.logs/*
e2e-network/docker/test-04-snapshot.sh.tmpdir/fablo-target/**/*
6 changes: 6 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# SC1090: Can't follow non-constant source. Use a directive to specify location.
disable=SC1090

# SC1091: Not following
disable=SC1091

# SC2034: Unused
disable=SC2034

# SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
disable=SC2164

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.2.0-unstable

### Features
* Initial support for Kubernetes

## 1.1.0

### Features
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ chaincodes:
- Org1
```
## Kubernetes support
TODO
## Other features
### Connection profiles
Expand Down
17 changes: 14 additions & 3 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ formatGeneratedFiles() {
shfmt -i=2 -l -w "$yeoman_target_dir" >/dev/null

for yaml in "$yeoman_target_dir"/**/*.yaml; do

# the expansion failed, no yaml files found
if [ "$yaml" = "$yeoman_target_dir/**/*.yaml" ]; then
break
fi

# remove trailing spaces
sed --in-place 's/[ \t]*$//' "$yaml"

Expand All @@ -43,10 +49,15 @@ formatGeneratedFiles() {
}

yeoman_target_dir="/network/workspace"
yeoman_command=${1:-Fablo:setup-docker}
yeoman_command=${1:-Fablo:setup-network}

# This part of output will be replaces with empty line. It breaks parsing of yeoman generator output.
# See also: https://github.com/yeoman/generator/issues/1294
annoying_yeoman_info="No change to package.json was detected. No package manager install will be executed."

executeYeomanCommand "$yeoman_command"
# Execute the command
executeYeomanCommand "$yeoman_command" 2>&1 | sed "s/$annoying_yeoman_info//g"

if echo "$yeoman_command" | grep "setup-docker"; then
if echo "$yeoman_command" | grep "setup-network"; then
formatGeneratedFiles
fi
2 changes: 1 addition & 1 deletion docs/sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/hyperledger-labs/fablo/releases/download/1.1.0/schema.json",
"$schema": "https://github.com/hyperledger-labs/fablo/releases/download/1.2.0-unstable/schema.json",
"global": {
"fabricVersion": "2.3.2",
"tls": false,
Expand Down
12 changes: 11 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"properties": {
"$schema": {
"const": "https://github.com/hyperledger-labs/fablo/releases/download/1.1.0/schema.json"
"const": "https://github.com/hyperledger-labs/fablo/releases/download/1.2.0-unstable/schema.json"
},
"global": {
"$id": "#/properties/global",
Expand Down Expand Up @@ -83,6 +83,16 @@
"type": "boolean",
"default": false
},
"engine": {
"$id": "#/properties/global/properties/engine",
"title": "Engine on which the network will be deployed",
"type": "string",
"enum": [
"docker",
"kubernetes"
],
"default": "docker"
},
"monitoring": {
"$id": "#/properties/monitoring",
"title": "Monitoring settings",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))"
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
FABLO_HOME="$TEST_TMP/../.."
FABLO_HOME="$TEST_TMP/../../.."

networkUp() {
"$FABLO_HOME/fablo-build.sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))"
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
FABLO_HOME="$TEST_TMP/../.."
FABLO_HOME="$TEST_TMP/../../.."

CONFIG="$FABLO_HOME/samples/fablo-config-hlf2-2orgs-2chaincodes-raft.yaml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))"
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
FABLO_HOME="$TEST_TMP/../.."
FABLO_HOME="$TEST_TMP/../../.."

FABLO_CONFIG="$FABLO_HOME/samples/fablo-config-hlf1.4-2orgs-2chaincodes-private-data.yaml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))"
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
FABLO_HOME="$TEST_TMP/../.."
FABLO_HOME="$TEST_TMP/../../.."

CONFIG="$FABLO_HOME/samples/fablo-config-hlf2-1org-1chaincode-raft-explorer.json"

Expand Down Expand Up @@ -105,10 +105,11 @@ expectInvokeRest "$fablo_rest_org1 $user_token" "my-channel1" "chaincode1" \
hook_command="perl -i -pe 's/FABRIC_VERSION=2\.3\.3/FABRIC_VERSION=2\.4\.2/g' ./fablo-target/fabric-docker/.env"

# prune the network and restore from snapshot
(cd "$TEST_TMP" &&
"$FABLO_HOME/fablo.sh" prune &&
"$FABLO_HOME/fablo.sh" restore "$snapshot_name" "$hook_command" &&
"$FABLO_HOME/fablo.sh" start
(
cd "$TEST_TMP" &&
"$FABLO_HOME/fablo.sh" prune &&
"$FABLO_HOME/fablo.sh" restore "$snapshot_name" "$hook_command" &&
"$FABLO_HOME/fablo.sh" start
)
waitForChaincode "cli.org1.example.com" "peer0.org1.example.com:7041" "my-channel1" "chaincode1" "0.0.1"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions e2e-network/k8s/expect-invoke-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -e

user="$1"
peer="$2"
channel="$3"
chaincode="$4"
fcn="$5"
key="$6"
value="$7"
expected="$8"
config="$(find . -type f -iname 'org1.yaml')"




if [ -z "$expected" ]; then
echo "Usage: ./expect-invoke.sh [user] [peer] [chaincdoe] [channel] [fcn] [arg1] [arg2] [expected_substring]"
exit 1
fi

label="Invoke $channel/$peer"
echo ""
echo "➜ testing: $label"

response="$(
kubectl hlf chaincode invoke \
--config "$config" \
--user "$user" \
--peer "$peer" \
--chaincode "$chaincode" \
--channel "$channel" \
--fcn "$fcn" \
-a "$key" \
${value:+ -a "$value"} \
# shellcheck disable=SC2188
2>&1
)"

echo "$response"

if echo "$response" | grep -F "$expected"; then
echo "✅ ok (cli): $label"
else
echo "❌ failed (cli): $label | expected: $expected"
exit 1
fi
Loading

0 comments on commit f0b6d09

Please sign in to comment.