Skip to content

Commit

Permalink
shared volume to copy k8s builder binraies from init to peer container
Browse files Browse the repository at this point in the history
Signed-off-by: asararatnakar <[email protected]>
  • Loading branch information
asararatnakar committed Oct 10, 2022
1 parent a8d9f52 commit 00c4e70
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/init-image-build-n-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Build and Push Init Image
- name: Build and Push Init Image if doesn't exists
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
make init-image
make init-image init-image-push
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
#

IMAGE ?= ghcr.io/hyperledger-labs/fabric-operator
INIT_IMAGE ?= ghcr.io/hyperledger-labs/init
TAG ?= $(shell git rev-parse --short HEAD)
ARCH ?= $(shell go env GOARCH)
OSS_GO_VER ?= 1.17.7
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
OS = $(shell go env GOOS)
K8S_TAG = v0.6.0

INIT_IMAGE ?= ghcr.io/hyperledger-labs/init
K8S_BUILDER_TAG = v0.7.2
INIT_TAG ?= 1.0.0

DOCKER_IMAGE_REPO ?= ghcr.io

Expand All @@ -50,8 +52,10 @@ image: setup
docker tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest-$(ARCH)

init-image:
docker build --rm . -f sample-network/init/Dockerfile --build-arg K8S_TAG=$(K8S_TAG) -t $(INIT_IMAGE):latest-$(ARCH)
docker push $(INIT_IMAGE):latest-$(ARCH)
INIT_IMAGE=$(INIT_IMAGE) INIT_TAG=$(INIT_TAG) ARCH=$(ARCH) K8S_BUILDER_TAG=$(K8S_BUILDER_TAG) scripts/init-build-push.sh "build"

init-image-push:
INIT_IMAGE=$(INIT_IMAGE) INIT_TAG=$(INIT_TAG) ARCH=$(ARCH) scripts/init-build-push.sh scripts/init-build-push.sh "push"

govendor:
@go mod vendor
Expand Down
17 changes: 15 additions & 2 deletions pkg/offering/base/peer/override/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ func (o *Override) V2Deployment(instance *current.IBPPeer, deployment *dep.Deplo
}
if instance.UsingCCLauncherImage() {
dirs = append(dirs, "cclauncher/")
} else if isV24Peer(instance) {
dirs = append(dirs, "/opt/hyperledger/k8s_builder")
cmdFormat += ` && cp -r /opt/hyperledger/k8s_builder/bin /k8s_builder/`
}

var directories string
Expand Down Expand Up @@ -454,6 +457,12 @@ func (o *Override) V2Deployment(instance *current.IBPPeer, deployment *dep.Deplo
peerContainer.DeleteEnv("CORE_VM_DOCKER_ATTACHSTDOUT")

deployment.AppendEmptyDirVolumeIfMissing(fmt.Sprintf("%s-cclauncher", instance.Name), corev1.StorageMediumMemory)
} else if isV24Peer(instance) {
// This is the case where it is a 2.4.x peer and using K8S Builder as external builder
volumeMountName := fmt.Sprintf("%s-k8sbuilder", instance.GetName())
initContainer.AppendVolumeMountIfMissing(volumeMountName, "/k8s_builder")
peerContainer.AppendVolumeMountIfMissing(volumeMountName, "/opt/hyperledger/k8s_builder")
deployment.AppendEmptyDirVolumeIfMissing(fmt.Sprintf("%s-k8sbuilder", instance.Name), corev1.StorageMediumMemory)
}

// Append a k/v JSON substitution map to the peer env.
Expand Down Expand Up @@ -635,8 +644,7 @@ func (o *Override) UpdateDeployment(instance *current.IBPPeer, k8sDep *appsv1.De
if err != nil {
return errors.Wrapf(err, "failed to update V2 fabric deployment for instance '%s'", instance.GetName())
}
peerVersion := version.String(instance.Spec.FabricVersion)
if peerVersion.EqualWithoutTag(version.V2_4_1) || peerVersion.GreaterThan(version.V2_4_1) {
if isV24Peer(instance) {
err := o.V24DeploymentUpdate(instance, deployment)
if err != nil {
return errors.Wrapf(err, "failed to update V24 fabric deployment for instance '%s'", instance.GetName())
Expand Down Expand Up @@ -970,3 +978,8 @@ func hsmDaemonSettings(instance *current.IBPPeer, hsmConfig *config.HSMConfig, p
deployment.AppendPVCVolumeIfMissing(pvcVolumeName, instance.PVCName())
}
}

func isV24Peer(instance *current.IBPPeer) bool {
peerVersion := version.String(instance.Spec.FabricVersion)
return peerVersion.EqualWithoutTag(version.V2_4_1) || peerVersion.GreaterThan(version.V2_4_1)
}
11 changes: 0 additions & 11 deletions sample-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,6 @@ The operator can also be configured for use with [fabric-builder-k8s](https://gi
providing smooth and immediate _Chaincode Right Now!_ deployments. With the `k8s` builder, the peer node will directly
manage the lifecycle of the chaincode pods.

Reconstruct the network with the "k8s-fabric-peer" image:
```shell
network down

export TEST_NETWORK_PEER_IMAGE=ghcr.io/hyperledgendary/k8s-fabric-peer
export TEST_NETWORK_PEER_IMAGE_LABEL=v0.6.0

network up
network channel create
```

Download a "k8s" chaincode package:
```shell
curl -fsSL https://github.com/hyperledgendary/conga-nft-contract/releases/download/v0.1.1/conga-nft-contract-v0.1.1.tgz -o conga-nft-contract-v0.1.1.tgz
Expand Down
14 changes: 9 additions & 5 deletions sample-network/init/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
ARG K8S_TAG
FROM ghcr.io/hyperledgendary/k8s-fabric-peer:${K8S_TAG} as builder

FROM registry.access.redhat.com/ubi8/ubi-minimal

ARG K8S_BUILDER_TAG

RUN microdnf update \
&& microdnf install -y \
shadow-utils \
iputils \
tar \
wget \
&& groupadd -g 7051 ibp-user \
&& useradd -u 7051 -g ibp-user -s /bin/bash ibp-user \
&& microdnf remove shadow-utils \
&& microdnf clean all \
&& mkdir -p /opt/hyperledger/k8s_builder/bin;
&& microdnf clean all

WORKDIR /opt/hyperledger/k8s_builder/bin

COPY --from=builder /opt/hyperledger/k8s_builder/bin/ /opt/hyperledger/k8s_builder/bin/
RUN wget https://github.com/hyperledger-labs/fabric-builder-k8s/releases/download/${K8S_BUILDER_TAG}/fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz \
&& tar -xzf fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz \
&& rm -rf fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz
4 changes: 2 additions & 2 deletions sample-network/network
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ context TOOLS_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-tools
context TOOLS_IMAGE_LABEL ${FABRIC_VERSION}
context OPERATOR_IMAGE ghcr.io/hyperledger-labs/fabric-operator
context OPERATOR_IMAGE_LABEL latest-amd64
context INIT_IMAGE registry.access.redhat.com/ubi8/ubi-minimal
context INIT_IMAGE_LABEL latest
context INIT_IMAGE ghcr.io/hyperledger-labs/init
context INIT_IMAGE_LABEL 1.0.0-amd64
context GRPCWEB_IMAGE ghcr.io/hyperledger-labs/grpc-web
context GRPCWEB_IMAGE_LABEL latest
context COUCHDB_IMAGE couchdb
Expand Down
31 changes: 31 additions & 0 deletions scripts/init-build-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 {the "License"};
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

docker manifest inspect ${INIT_IMAGE}:${INIT_TAG}-${ARCH} >> /dev/null

if [[ $? -ne 0 ]]; then
if [[ $1 = "build" ]]; then
docker build --rm . -f sample-network/init/Dockerfile --build-arg K8S_BUILDER_TAG=${K8S_BUILDER_TAG} -t ${INIT_IMAGE}:${INIT_TAG}-${ARCH}
docker tag ${INIT_IMAGE}:${INIT_TAG}-${ARCH} ${INIT_IMAGE}:latest-${ARCH}
elif [[ $1 = "push" ]]; then
docker push ${INIT_IMAGE}:latest-${ARCH}
docker push ${INIT_IMAGE}:${INIT_TAG}-${ARCH}
fi
fi

0 comments on commit 00c4e70

Please sign in to comment.