Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade yq from v3.x to v4.x #721

Merged
merged 9 commits into from
Oct 24, 2023
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Make sure that you have the following required dependencies installed:
* yq v3.x (newer versions, v4.x and higher, are currently *not* supported!)
You can install `yq` v3 via `go get`.
```bash
GO111MODULE=on go get github.com/mikefarah/yq/v3
GO111MODULE=on go get github.com/mikefarah/yq/v4
```

* Protocol Buffers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ if [[ ! -f "$GATEWAY_CONFIG" ]]; then
exit 1
fi

MSP_ID=$(yq r $GATEWAY_CONFIG organizations.${ORG^}.mspid)
PEER_ID=$(yq r $GATEWAY_CONFIG organizations.${ORG^}.peers[0])
ADDR=$(yq r $GATEWAY_CONFIG peers.\"${PEER_ID}\".url | sed 's/grpcs:\/\///')
MSP_ID=$(yq e ".organizations.${ORG^}.mspid" $GATEWAY_CONFIG)
PEER_ID=$(yq e ".organizations.${ORG^}.peers[0]" $GATEWAY_CONFIG)
ADDR=$(yq e ".peers.\"${PEER_ID}\".url" $GATEWAY_CONFIG | sed 's/grpcs:\/\///')
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved

echo "export CONF_PATH=$FPC_PATH/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto" > ${ORG}.env
echo "export GATEWAY_CONFIG=\$CONF_PATH/peerOrganizations/${ORG,,}.example.com/connections.yaml" >> ${ORG}.env
Expand Down
6 changes: 3 additions & 3 deletions samples/deployment/test-network/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fi
echo "Adding FPC external builder to core.yaml"
# Create a backup copy of `core.yaml` first and always work from there.
backup ${CORE_PATH}
yq m -i -a=append ${CORE_PATH} core_ext.yaml
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' ${CORE_PATH} core_ext.yaml -i
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved


###############################################
Expand Down Expand Up @@ -80,8 +80,8 @@ sed -i "s+\.\./+${FABRIC_SAMPLES_HOST}/test-network/+g" "${DOCKER_COMPOSE_CA}"
echo "${DOCKER_COMPOSE_TEST_NET}"
peers=("peer0.org1.example.com" "peer0.org2.example.com")
for p in "${peers[@]}"; do
yq w -i ${DOCKER_COMPOSE_TEST_NET} "services.\"$p\".volumes[+]" "${FPC_PATH_HOST}:/opt/gopath/src/github.com/hyperledger/fabric-private-chaincode"
yq w -i ${DOCKER_COMPOSE_TEST_NET} "services.\"$p\".volumes[+]" "${FABRIC_SAMPLES_HOST}/config/core.yaml:/etc/hyperledger/fabric/core.yaml"
yq eval ".services.\"$p\".volumes += [\"${FPC_PATH_HOST}:/opt/gopath/src/github.com/hyperledger/fabric-private-chaincode\"]" ${DOCKER_COMPOSE_TEST_NET} -i
yq eval ".services.\"$p\".volumes += [\"${FABRIC_SAMPLES_HOST}/config/core.yaml:/etc/hyperledger/fabric/core.yaml\"]" ${DOCKER_COMPOSE_TEST_NET} -i
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved
done

###############################################
Expand Down
21 changes: 11 additions & 10 deletions samples/deployment/test-network/update-connection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ for org in "${orgs[@]}"; do
KEYS=("${ORG_PATH}/users/${user}@${org}.example.com/msp/keystore"/*)

# add cryptopath and admin cert / key
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.cryptoPath ${ORG_PATH}/msp
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.users.${user}.cert.path "${CERTS[0]}"
yq w -i ${CONNECTIONS_PATH} organizations.${org^}.users.${user}.key.path "${KEYS[0]}"
yq eval ".organizations.${org^}.cryptoPath = \"${ORG_PATH}/msp\"" ${CONNECTIONS_PATH} -i
yq eval ".organizations.${org^}.users.${user}.cert.path = \"${CERTS[0]}\"" ${CONNECTIONS_PATH} -i
yq eval ".organizations.${org^}.users.${user}.key.path = \"${KEYS[0]}\"" ${CONNECTIONS_PATH} -i
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved

# add channels and entity matcher
yq m -i ${CONNECTIONS_PATH} - <<EOF
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' ${CONNECTIONS_PATH} -i <<EOF
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved

channels:
_default:
peers:
Expand All @@ -75,19 +76,19 @@ entityMatchers:
EOF

# fetch all peers from connections
yq r --printMode pv "${CONNECTIONS_PATH}" peers >> "${tmp_dir}/peers-${org}.yaml"
yq e ".peers" "${CONNECTIONS_PATH}" >> "${tmp_dir}/peers-${org}.yaml"
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved
done

# consolidate all collected peers in a single peers.yaml
yq m "${tmp_dir}"/peers-*.yaml >> "${tmp_dir}/peers.yaml"
yq v "${tmp_dir}/peers.yaml"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "${tmp_dir}"/peers-*.yaml >> "${tmp_dir}/peers.yaml"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml" -i
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved

# merge peers.yaml into all connection files
for org in "${orgs[@]}"; do
ORG_PATH="${FPC_PATH}/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/${org}.example.com"
CONNECTIONS_PATH="${ORG_PATH}/connection-${org}.yaml"
yq m -i "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml"
yq v "${CONNECTIONS_PATH}"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "${tmp_dir}"/peers-*.yaml >> "${tmp_dir}/peers.yaml"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml" -i
mbrandenburger marked this conversation as resolved.
Show resolved Hide resolved
done

echo "Updated!"
echo "Updated!"
2 changes: 1 addition & 1 deletion utils/docker/base-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ RUN go install golang.org/x/tools/cmd/goimports@latest \
&& go install github.com/maxbrunsfeld/counterfeiter/v6@latest \
&& go install honnef.co/go/tools/cmd/[email protected] \
&& go install github.com/client9/misspell/cmd/misspell@latest \
&& go install github.com/mikefarah/yq/v3@latest
&& go install github.com/mikefarah/yq/v4@latest

# Install SGX SSL
ENV SGX_SSL /opt/intel/sgxssl
Expand Down
2 changes: 1 addition & 1 deletion utils/docker/dev_peer_cc-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ RUN apt-get install -y -q \
${APT_ADD_PKGS}

RUN GO111MODULE=on \
go get github.com/mikefarah/yq/v3
go get github.com/mikefarah/yq/v4

WORKDIR ${FPC_PATH}