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

Pushing init image for k8s builder to work #61

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/init-image-build-n-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build Init image

on:
push:
branches: [main]

jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- 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 init-image-push
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ OSS_GO_VER ?= 1.17.7
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
OS = $(shell go env GOOS)

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

DOCKER_IMAGE_REPO ?= ghcr.io

BUILD_ARGS=--build-arg ARCH=$(ARCH)
Expand All @@ -47,6 +51,12 @@ image: setup
docker build --rm . -f Dockerfile $(BUILD_ARGS) -t $(IMAGE):$(TAG)-$(ARCH)
docker tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest-$(ARCH)

init-image:
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)
}
6 changes: 3 additions & 3 deletions pkg/offering/base/peer/override/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ var _ = Describe("Base Peer Deployment Overrides", func() {
Expect(init.Command).To(HaveLen(3))
Expect(init.Command[0]).To(Equal("bash"))
Expect(init.Command[1]).To(Equal("-c"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /data/ && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /data/; fi"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /{data/,/opt/hyperledger/k8s_builder} && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /{data/,/opt/hyperledger/k8s_builder}; fi && cp -r /opt/hyperledger/k8s_builder/bin /k8s_builder/"))
})
})
})
Expand Down Expand Up @@ -911,7 +911,7 @@ var _ = Describe("Base Peer Deployment Overrides", func() {
Expect(init.Command).To(HaveLen(3))
Expect(init.Command[0]).To(Equal("bash"))
Expect(init.Command[1]).To(Equal("-c"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /data/ && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /data/; fi"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /{data/,/opt/hyperledger/k8s_builder} && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /{data/,/opt/hyperledger/k8s_builder}; fi && cp -r /opt/hyperledger/k8s_builder/bin /k8s_builder/"))
})
})
})
Expand All @@ -938,7 +938,7 @@ var _ = Describe("Base Peer Deployment Overrides", func() {
Expect(init.Command).To(HaveLen(3))
Expect(init.Command[0]).To(Equal("bash"))
Expect(init.Command[1]).To(Equal("-c"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /{data/,data/peer/ledgersData/stateLeveldb} && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /{data/,data/peer/ledgersData/stateLeveldb}; fi"))
Expect(init.Command[2]).To(Equal("DEFAULT_PERM=775 && DEFAULT_USER=7051 && DEFAULT_GROUP=1000 && PERM=$(stat -c \"%a\" /data/) && USER=$(stat -c \"%u\" /data/) && GROUP=$(stat -c \"%g\" /data/) && if [ ${PERM} != ${DEFAULT_PERM} ] || [ ${USER} != ${DEFAULT_USER} ] || [ ${GROUP} != ${DEFAULT_GROUP} ]; then chmod -R ${DEFAULT_PERM} /{data/,data/peer/ledgersData/stateLeveldb,/opt/hyperledger/k8s_builder} && chown -R -H ${DEFAULT_USER}:${DEFAULT_GROUP} /{data/,data/peer/ledgersData/stateLeveldb,/opt/hyperledger/k8s_builder}; fi && cp -r /opt/hyperledger/k8s_builder/bin /k8s_builder/"))
})
})
})
Expand Down
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
21 changes: 21 additions & 0 deletions sample-network/init/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

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

WORKDIR /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