From 2376c3f9f7aec0a4313247fb93ae8711733e8fca Mon Sep 17 00:00:00 2001 From: "john.h.o.mantaring" Date: Wed, 2 Aug 2023 20:04:41 +0800 Subject: [PATCH] feat(connector-corda): support corda 5 RC via TS/HTTP (no JVM) 1. Update of Corda Cli from 'Corda V5.0.0.0-devpreview-1.0' to 'Corda V5.0.0.0' 2. Update the test samples from 'corda5-solarsystem-contracts-demo' to 'CSDE-cordapp-template-kotlin' Fixes #1480 Co-authored-by: jagpreetsinghsasan jagpreet.singh.sasan@accenture.com Signed-off-by: john.h.o.mantaring --- .../corda-all-in-one/corda-v5/Dockerfile | 117 ++++++++---------- .../corda-all-in-one/corda-v5/README.md | 7 ++ .../corda-all-in-one/corda-v5/healthcheck.sh | 6 +- .../corda-v5/start-services.sh | 21 ++-- ...cts-demo-network.conf => supervisord.conf} | 23 ++-- 5 files changed, 83 insertions(+), 91 deletions(-) create mode 100644 tools/docker/corda-all-in-one/corda-v5/README.md rename tools/docker/corda-all-in-one/corda-v5/{supervisor/corda5-solarsystem-contracts-demo-network.conf => supervisord.conf} (58%) diff --git a/tools/docker/corda-all-in-one/corda-v5/Dockerfile b/tools/docker/corda-all-in-one/corda-v5/Dockerfile index 4316e323d55..f084ce7633e 100644 --- a/tools/docker/corda-all-in-one/corda-v5/Dockerfile +++ b/tools/docker/corda-all-in-one/corda-v5/Dockerfile @@ -1,84 +1,71 @@ -FROM cruizba/ubuntu-dind:20.10.9 +FROM docker:20.10.3-dind -WORKDIR / +RUN apk update +RUN apk add py-pip python3-dev libffi-dev openssl-dev gcc libc-dev make -RUN apt update -RUN apt -y upgrade +# Need curl for healthchecks +RUN apk add --no-cache curl -# # Install git so we can check out the corda5-solarsystem-contracts-demo repo of Corda -RUN apt install -y git +# Need to run shell script run.sh for Corda CLI +RUN apk add --no-cache bash -# Need curl to run healthchecks -RUN apt install -y curl +# The file binary is used to inspect exectubles when debugging container image issues +RUN apk add --no-cache file +RUN apk add --no-cache ca-certificates +RUN apk add --no-cache tzdata +RUN apk add --no-cache gnupg -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends openjdk-11-jdk +#----------------- INSTALLING CORDA CDSE PREREQUISITES -------------------- +#-------------------------------------------------------------------------- -# jq is needed by the /download-frozen-image-v2.sh script to pre-fetch docker images without docker. -RUN apt install -y jq +# Installing Zulu11 JDK +RUN wget -P /etc/apk/keys/ \ +https://cdn.azul.com/public_keys/alpine-signing@azul.com-5d5dc44c.rsa.pub +RUN echo "https://repos.azul.com/zulu/alpine" | tee -a /etc/apk/repositories +RUN apk update +RUN apk add --no-cache zulu11-jdk -# Get the utility script that can pre-fetch the container images without -# a functioning Docker daemon available which we do not have at image build -# time so have to resort to manually get the images instead of just saying -# "docker pull my/cool-image..." etc. -# The reason to jump trough these hoops is to avoid DockerHub rate limiting issues -RUN curl -sSL https://raw.githubusercontent.com/moby/moby/dedf8528a51c6db40686ed6676e9486d1ed5f9c0/contrib/download-frozen-image-v2.sh > /download-frozen-image-v2.sh -RUN chmod +x /download-frozen-image-v2.sh -RUN mkdir -p /etc/corda/corda-dev/ -RUN /download-frozen-image-v2.sh /etc/corda/corda-dev/ corda/corda-dev:5.0.0-devpreview-1.0 +# Installing Corda CLI +RUN mkdir /platform-jars && \ + wget -O /platform-jars/binary.tar.gz \ + https://download.corda.net/c5-release-pack/E0b6f4f8-8907-47ae-b3cd-7f25ff756c2f-5.0.0-GA/platform-jars-5.0.0.tar.gz -RUN curl https://download.corda.net/corda-cli/1.0.0-DevPreview/get-corda-cli.sh > /get-corda-cli.sh -RUN chmod +x /get-corda-cli.sh -RUN /get-corda-cli.sh +RUN cd /platform-jars/ && \ + tar -xvzf binary.tar.gz && \ + cp net/corda/cli/deployment/corda-cli-installer/5.0.0.0/corda-cli-installer-5.0.0.0.zip . && \ + unzip corda-cli-installer-5.0.0.0.zip -d corda-cli-installer && \ + corda-cli-installer/./install.sh +ENV PATH="$PATH:~/.corda/cli" -RUN curl https://download.corda.net/cordapp-builder/5.0.0-DevPreview-1.0/cordapp-builder-installer.jar --output /cordapp-builder-installer.jar -RUN java -jar /cordapp-builder-installer.jar +#-------------------------------------------------------------------------- +#-------------------------------------------------------------------------- -RUN git clone https://github.com/corda/corda5-solarsystem-contracts-demo.git -WORKDIR /corda5-solarsystem-contracts-demo +# Installing CORDA CDSE +RUN apk add --no-cache git +RUN git clone https://github.com/corda/CSDE-cordapp-template-kotlin.git -# Placing the ARG here instead of the top may seem like bad form, but it has -# better build performance this way when we change the ARG's value it will -# not spend 5 to 10 minutes installing the OS level dependencies on the top of -# the image definition file because the cached layers will be the same for those. -ARG SOLARSYSTEM_DEMO_SHA=a3be5ad48d249be7f71c5f15074c874dc0d09b41 -RUN git checkout ${SOLARSYSTEM_DEMO_SHA} +RUN cd CSDE-cordapp-template-kotlin/ && \ + git checkout release/corda-5-0 -RUN /root/bin/corda-cli/bin/corda-cli network config docker-compose solar-system -RUN chmod +x gradlew -RUN ./gradlew build +RUN apk add --no-cache supervisor +## Exposing the required ports 5005, 5432 and 8888 for CSDE +## and 9001 for supervisor. Currently commented because of "--network host" being used to run the container +# EXPOSE 5005 +# EXPOSE 5432 +# EXPOSE 8888 -RUN /root/bin/corda-cli/bin/corda-cli network deploy -n solar-system -f solar-system.yaml > docker-compose.yaml +# EXPOSE 9001 -RUN sed -i 's+corda/corda-dev:latest+corda/corda-dev:5.0.0-devpreview-1.0+g' /corda5-solarsystem-contracts-demo/docker-compose.yaml +COPY supervisord.conf /etc/supervisord.conf -RUN /root/.local/lib/cordapp-builder/bin/cordapp-builder create --cpk contracts/build/libs/corda5-solar-system-contracts-demo-contracts-1.0-SNAPSHOT-cordapp.cpk --cpk workflows/build/libs/corda5-solar-system-contracts-demo-workflows-1.0-SNAPSHOT-cordapp.cpk -o solar-system.cpb +COPY start-services.sh /start-services.sh +RUN chmod +x /start-services.sh -# OpenSSH server -EXPOSE 22 +WORKDIR /CSDE-cordapp-template-java/ -# supervisord web ui/dashboard -EXPOSE 9001 - -# earth-node RPC -EXPOSE 12112 - -# mars-node RPC -EXPOSE 12116 - -# pluto-node RPC -EXPOSE 12119 - -# notary-node RPC -EXPOSE 12122 - -COPY ./start-services.sh /start-services.sh - -COPY ./supervisor/ /etc/supervisor/conf.d/ +# Extend the parent image's entrypoint +# https://superuser.com/questions/1459466/can-i-add-an-additional-docker-entrypoint-script ENTRYPOINT ["/usr/bin/supervisord"] -CMD ["--nodaemon"] +CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"] -# Add our healthcheck script that determines when do we consider the container healthy -COPY healthcheck.sh / -HEALTHCHECK --interval=2s --timeout=5s --start-period=30s --retries=180 CMD /healthcheck.sh -#RUN ~/bin/corda-cli/bin/corda-cli package install -n solar-system solar-system.cpb +HEALTHCHECK --interval=10s --timeout=5s --start-period=100s --retries=1000 CMD [ -f 5vNodeSetupdone.txt ] \ No newline at end of file diff --git a/tools/docker/corda-all-in-one/corda-v5/README.md b/tools/docker/corda-all-in-one/corda-v5/README.md new file mode 100644 index 00000000000..fe53d2d4513 --- /dev/null +++ b/tools/docker/corda-all-in-one/corda-v5/README.md @@ -0,0 +1,7 @@ +# Instructions to compile and run the new Corda v5.0 test network + +To create an image of the dockerfile run: +`DOCKER_BUILDKIT=1 docker build ./tools/docker/corda-all-in-one/corda-v5 -t newcordaimg` + +To run the AIO, execute: +`docker run -it --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock --network host -d newcordaimg` \ No newline at end of file diff --git a/tools/docker/corda-all-in-one/corda-v5/healthcheck.sh b/tools/docker/corda-all-in-one/corda-v5/healthcheck.sh index 469aab00863..601cfe42201 100755 --- a/tools/docker/corda-all-in-one/corda-v5/healthcheck.sh +++ b/tools/docker/corda-all-in-one/corda-v5/healthcheck.sh @@ -2,7 +2,5 @@ set -e #/root/bin/corda-cli/bin/corda-cli network status -n solar-system - -curl -u martian:password --insecure https://localhost:12116/api/v1/nodestatus/getnetworkreadinessstatus -curl -u earthling:password --insecure https://localhost:12112/api/v1/nodestatus/getnetworkreadinessstatus -curl -u plutonian:password --insecure https://localhost:12119/api/v1/nodestatus/getnetworkreadinessstatus +#Need to change since token is needed to check health status +#curl -u admin:admin --insecure https://localhost:8888/api/v1/swagger# diff --git a/tools/docker/corda-all-in-one/corda-v5/start-services.sh b/tools/docker/corda-all-in-one/corda-v5/start-services.sh index 9df798835be..89db3df6648 100755 --- a/tools/docker/corda-all-in-one/corda-v5/start-services.sh +++ b/tools/docker/corda-all-in-one/corda-v5/start-services.sh @@ -1,11 +1,14 @@ #!/bin/bash +set -e -# Load the cached container images into the Docker Daemon before launching -# the Docker Compose network. This is the preferred workaround to synchronizing -# different processes of a supervisord configuration -tar -cC '/etc/corda/corda-dev/' . | docker load - -# Now that the images are cached **and** loaded to the daemon, we can start the -# corda network via the docker-compose file and it will not need to download -# anything from DockerHub (if it does, that's a bug) -supervisorctl start corda5-solarsystem-contracts-demo-network +cd /CSDE-cordapp-template-kotlin/ +while true; do + echo "Waiting for startCorda to execute..." + if ./gradlew listVNodes | grep "X500"; then + echo "Starting v5NodeSetup..."; + ./gradlew 5-vNodeSetup + break; + fi + sleep 5; +done +touch 5vNodeSetupdone.txt diff --git a/tools/docker/corda-all-in-one/corda-v5/supervisor/corda5-solarsystem-contracts-demo-network.conf b/tools/docker/corda-all-in-one/corda-v5/supervisord.conf similarity index 58% rename from tools/docker/corda-all-in-one/corda-v5/supervisor/corda5-solarsystem-contracts-demo-network.conf rename to tools/docker/corda-all-in-one/corda-v5/supervisord.conf index 8d7bbe324b5..a7a8dd04054 100644 --- a/tools/docker/corda-all-in-one/corda-v5/supervisor/corda5-solarsystem-contracts-demo-network.conf +++ b/tools/docker/corda-all-in-one/corda-v5/supervisord.conf @@ -1,30 +1,27 @@ [supervisord] -logfile = /var/log/supervisord.log logfile_maxbytes = 50MB logfile_backups=10 loglevel = info -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl=http://127.0.0.1:9001 - [inet_http_server] port = 0.0.0.0:9001 -[program:start-services] -command=/start-services.sh +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[program:startCorda] +directory=/CSDE-cordapp-template-kotlin +command=/bin/bash -c "./gradlew startCorda" autostart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 -[program:corda5-solarsystem-contracts-demo-network] -command=/usr/local/bin/docker-compose -f /corda5-solarsystem-contracts-demo/docker-compose.yaml up -autostart=false -autorestart=true +[program:5vNodeSetup] +directory=/ +command=/bin/bash -c "./start-services.sh" +autostart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr