Skip to content

Commit

Permalink
Tag the plugin image to avoid unnecessary building docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
eiichiro-oiwa committed Apr 8, 2022
1 parent 60cb6e5 commit 548126c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion chaincode/runtimeImg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN mkdir -p /chaincode/output
COPY ./chaincode /chaincode/output/chaincode

RUN ln -s /bin/true /usr/bin/go

RUN ln -s /chaincode/output/chaincode /usr/local/bin/chaincode
5 changes: 3 additions & 2 deletions server/immpluginsrv/immplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (

type server struct{
org string
podName string
}

type InstanceValue struct {
Expand Down Expand Up @@ -170,9 +171,10 @@ func (s *server) validateUser(cert *x509.Certificate, funcName string) error {
func main() {
immpluginsrv := &server{
org: os.Getenv("IMMS_ORG"),
podName: os.Getenv("IMMS_POD_NAME"),
}

err := initPodInPod(immpluginsrv.org)
err := initPodInPod(immpluginsrv.podName)
if err != nil {
log.Fatalf("%s\n", err)
}
Expand All @@ -181,7 +183,6 @@ func main() {
if err != nil {
log.Fatalf("failed to listen: %s\n", err)
}


s := grpc.NewServer()
immplugin.RegisterImmPluginServer(s, immpluginsrv)
Expand Down
14 changes: 13 additions & 1 deletion server/immpluginsrv/podinpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package main

import (
"crypto/sha256"
"encoding/hex"
"context"
"time"
"fmt"
Expand All @@ -29,7 +31,7 @@ import (
"immutil"
)

func initPodInPod(org string) (retErr error) {
func initPodInPod(podName string) (retErr error) {
dockerClient, err := dclient.NewClientWithOpts(dclient.WithHost("http://localhost:2376"))
if err != nil {
retErr = fmt.Errorf("failed to create podman client: %s\n", err)
Expand Down Expand Up @@ -97,6 +99,16 @@ func initPodInPod(org string) (retErr error) {
retErr = fmt.Errorf("failed to load images: %s", err)
return
}

buildImgTag := "dev-" /*networkID*/ + podName + "-hlRsyslog-5.0" /*Chaincode Name*/
digest := sha256.Sum256([]byte(buildImgTag))
digestStr := hex.EncodeToString(digest[:])
buildImgTag = "dev-" + podName + "-hlrsyslog-5.0-" + digestStr
err = dockerClient.ImageTag(context.Background(), immutil.ContRuntimeImg, buildImgTag)
if err != nil {
retErr = fmt.Errorf("failed to tag %s: %s\n", immutil.ContRuntimeImg, err)
return
}

return // success
}
1 change: 1 addition & 0 deletions server/immsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ func startPeer(podName string) (state, resourceVersion string, retErr error) {
Image: pullRegAddr + immutil.ImmPluginSrvImg,
Env: []corev1.EnvVar{
{ Name: "IMMS_ORG", Value: org, },
{ Name: "IMMS_POD_NAME", Value: podName, },
},
Command: []string{"/var/lib/immpluginsrv"},
StartupProbe: &corev1.Probe{
Expand Down

0 comments on commit 548126c

Please sign in to comment.