Skip to content

Commit 00c4e70

Browse files
committed
shared volume to copy k8s builder binraies from init to peer container
Signed-off-by: asararatnakar <[email protected]>
1 parent a8d9f52 commit 00c4e70

File tree

7 files changed

+67
-26
lines changed

7 files changed

+67
-26
lines changed

.github/workflows/init-image-build-n-push.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212

13-
- name: Build and Push Init Image
13+
- name: Build and Push Init Image if doesn't exists
1414
run: |
1515
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
16-
make init-image
16+
make init-image init-image-push

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
#
1818

1919
IMAGE ?= ghcr.io/hyperledger-labs/fabric-operator
20-
INIT_IMAGE ?= ghcr.io/hyperledger-labs/init
2120
TAG ?= $(shell git rev-parse --short HEAD)
2221
ARCH ?= $(shell go env GOARCH)
2322
OSS_GO_VER ?= 1.17.7
2423
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
2524
OS = $(shell go env GOOS)
26-
K8S_TAG = v0.6.0
25+
26+
INIT_IMAGE ?= ghcr.io/hyperledger-labs/init
27+
K8S_BUILDER_TAG = v0.7.2
28+
INIT_TAG ?= 1.0.0
2729

2830
DOCKER_IMAGE_REPO ?= ghcr.io
2931

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

5254
init-image:
53-
docker build --rm . -f sample-network/init/Dockerfile --build-arg K8S_TAG=$(K8S_TAG) -t $(INIT_IMAGE):latest-$(ARCH)
54-
docker push $(INIT_IMAGE):latest-$(ARCH)
55+
INIT_IMAGE=$(INIT_IMAGE) INIT_TAG=$(INIT_TAG) ARCH=$(ARCH) K8S_BUILDER_TAG=$(K8S_BUILDER_TAG) scripts/init-build-push.sh "build"
56+
57+
init-image-push:
58+
INIT_IMAGE=$(INIT_IMAGE) INIT_TAG=$(INIT_TAG) ARCH=$(ARCH) scripts/init-build-push.sh scripts/init-build-push.sh "push"
5559

5660
govendor:
5761
@go mod vendor

pkg/offering/base/peer/override/deployment.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ func (o *Override) V2Deployment(instance *current.IBPPeer, deployment *dep.Deplo
414414
}
415415
if instance.UsingCCLauncherImage() {
416416
dirs = append(dirs, "cclauncher/")
417+
} else if isV24Peer(instance) {
418+
dirs = append(dirs, "/opt/hyperledger/k8s_builder")
419+
cmdFormat += ` && cp -r /opt/hyperledger/k8s_builder/bin /k8s_builder/`
417420
}
418421

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

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

459468
// Append a k/v JSON substitution map to the peer env.
@@ -635,8 +644,7 @@ func (o *Override) UpdateDeployment(instance *current.IBPPeer, k8sDep *appsv1.De
635644
if err != nil {
636645
return errors.Wrapf(err, "failed to update V2 fabric deployment for instance '%s'", instance.GetName())
637646
}
638-
peerVersion := version.String(instance.Spec.FabricVersion)
639-
if peerVersion.EqualWithoutTag(version.V2_4_1) || peerVersion.GreaterThan(version.V2_4_1) {
647+
if isV24Peer(instance) {
640648
err := o.V24DeploymentUpdate(instance, deployment)
641649
if err != nil {
642650
return errors.Wrapf(err, "failed to update V24 fabric deployment for instance '%s'", instance.GetName())
@@ -970,3 +978,8 @@ func hsmDaemonSettings(instance *current.IBPPeer, hsmConfig *config.HSMConfig, p
970978
deployment.AppendPVCVolumeIfMissing(pvcVolumeName, instance.PVCName())
971979
}
972980
}
981+
982+
func isV24Peer(instance *current.IBPPeer) bool {
983+
peerVersion := version.String(instance.Spec.FabricVersion)
984+
return peerVersion.EqualWithoutTag(version.V2_4_1) || peerVersion.GreaterThan(version.V2_4_1)
985+
}

sample-network/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,6 @@ The operator can also be configured for use with [fabric-builder-k8s](https://gi
132132
providing smooth and immediate _Chaincode Right Now!_ deployments. With the `k8s` builder, the peer node will directly
133133
manage the lifecycle of the chaincode pods.
134134

135-
Reconstruct the network with the "k8s-fabric-peer" image:
136-
```shell
137-
network down
138-
139-
export TEST_NETWORK_PEER_IMAGE=ghcr.io/hyperledgendary/k8s-fabric-peer
140-
export TEST_NETWORK_PEER_IMAGE_LABEL=v0.6.0
141-
142-
network up
143-
network channel create
144-
```
145-
146135
Download a "k8s" chaincode package:
147136
```shell
148137
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

sample-network/init/Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
ARG K8S_TAG
2-
FROM ghcr.io/hyperledgendary/k8s-fabric-peer:${K8S_TAG} as builder
31

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

4+
ARG K8S_BUILDER_TAG
5+
66
RUN microdnf update \
77
&& microdnf install -y \
88
shadow-utils \
99
iputils \
1010
tar \
11+
wget \
1112
&& groupadd -g 7051 ibp-user \
1213
&& useradd -u 7051 -g ibp-user -s /bin/bash ibp-user \
1314
&& microdnf remove shadow-utils \
14-
&& microdnf clean all \
15-
&& mkdir -p /opt/hyperledger/k8s_builder/bin;
15+
&& microdnf clean all
16+
17+
WORKDIR /opt/hyperledger/k8s_builder/bin
1618

17-
COPY --from=builder /opt/hyperledger/k8s_builder/bin/ /opt/hyperledger/k8s_builder/bin/
19+
RUN wget https://github.com/hyperledger-labs/fabric-builder-k8s/releases/download/${K8S_BUILDER_TAG}/fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz \
20+
&& tar -xzf fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz \
21+
&& rm -rf fabric-builder-k8s-${K8S_BUILDER_TAG}-Linux-X64.tgz

sample-network/network

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ context TOOLS_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-tools
7979
context TOOLS_IMAGE_LABEL ${FABRIC_VERSION}
8080
context OPERATOR_IMAGE ghcr.io/hyperledger-labs/fabric-operator
8181
context OPERATOR_IMAGE_LABEL latest-amd64
82-
context INIT_IMAGE registry.access.redhat.com/ubi8/ubi-minimal
83-
context INIT_IMAGE_LABEL latest
82+
context INIT_IMAGE ghcr.io/hyperledger-labs/init
83+
context INIT_IMAGE_LABEL 1.0.0-amd64
8484
context GRPCWEB_IMAGE ghcr.io/hyperledger-labs/grpc-web
8585
context GRPCWEB_IMAGE_LABEL latest
8686
context COUCHDB_IMAGE couchdb

scripts/init-build-push.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright contributors to the Hyperledger Fabric Operator project
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
#
8+
# Licensed under the Apache License, Version 2.0 {the "License"};
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
docker manifest inspect ${INIT_IMAGE}:${INIT_TAG}-${ARCH} >> /dev/null
22+
23+
if [[ $? -ne 0 ]]; then
24+
if [[ $1 = "build" ]]; then
25+
docker build --rm . -f sample-network/init/Dockerfile --build-arg K8S_BUILDER_TAG=${K8S_BUILDER_TAG} -t ${INIT_IMAGE}:${INIT_TAG}-${ARCH}
26+
docker tag ${INIT_IMAGE}:${INIT_TAG}-${ARCH} ${INIT_IMAGE}:latest-${ARCH}
27+
elif [[ $1 = "push" ]]; then
28+
docker push ${INIT_IMAGE}:latest-${ARCH}
29+
docker push ${INIT_IMAGE}:${INIT_TAG}-${ARCH}
30+
fi
31+
fi

0 commit comments

Comments
 (0)