Skip to content

Commit fd00a2d

Browse files
authored
Merge pull request #45 from corda/docker-sample
2 parents 9bc9adc + df4b240 commit fd00a2d

File tree

22 files changed

+1038
-0
lines changed

22 files changed

+1038
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016, R3 Limited.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# dockerform-yocordapp
2+
3+
This time we've taken the original yo cordapp and modified it to demonstrate an example of how you can use dockerForm to bootstrap a corda network on a single machine.
4+
5+
For the purposes of this example, we'll use the yo cordapp as a base to create a clear example for how to use the dockerForm gradle build task in a normal cordapp setup.
6+
7+
> Note this is generally intended to be used on localhost.
8+
9+
10+
## Concepts
11+
12+
In the original yo application, the app sent what is essentially a nudge from one endpoint and another.
13+
14+
In corda, we can use abstractions to accomplish the same thing.
15+
16+
17+
We define a state (the yo to be shared), define a contract (the way to make sure the yo is legit), and define the flow (the control flow of our cordapp).
18+
19+
20+
## Usage
21+
22+
### Quick Start with Docker
23+
24+
If you have docker installed you can use our gradle tasks to generate a valid docker compose file for your node configuration.
25+
26+
```bash
27+
# generate the docker-compose file
28+
./gradlew prepareDockerNodes
29+
30+
# run our corda network
31+
docker-compose -f ./build/nodes/docker-compose.yml up
32+
```
33+
34+
#### Sending a Yo
35+
36+
We will interact with the nodes via their specific shells. When the nodes are up and running, use the following command to send a Yo to another node:
37+
38+
```sh
39+
# find the ssh port for PartyA using docker ps
40+
ssh [email protected] -p 2223
41+
42+
# the password defined in the node config for PartyA is "test"
43+
Password: test
44+
45+
46+
Welcome to the Corda interactive shell.
47+
You can see the available commands by typing 'help'.
48+
49+
# you'll see the corda shell available and can run flows
50+
Fri May 15 18:23:03 GMT 2020>>> flow start YoFlow target: PartyA
51+
52+
✓ Starting
53+
✓ Creating a new Yo!
54+
✓ Signing the Yo!
55+
✓ Verfiying the Yo!
56+
✓ Sending the Yo!
57+
Requesting signature by notary service
58+
Requesting signature by Notary service
59+
Validating response from Notary service
60+
✓ Broadcasting transaction to participants
61+
▶︎ Done
62+
Flow completed with result: SignedTransaction(id=3F92F41B699719B2CDE578959BB09F50D3D4F5D51A496DEAB67E438B2614F48C)
63+
```
64+
65+
Once this runs on your machine you've got everything you would need to run corda for development using docker!
66+
67+
###### Note you can't send a Yo! to yourself because that's not cool!
68+
69+
To see all the Yo's other nodes have sent you in your vault you can run a vault query from the Corda shell:
70+
71+
```bash
72+
run vaultQuery contractStateType: net.corda.examples.yo.states.YoState
73+
```
74+
75+
As a quick note you can shut down your docker containers with the following command
76+
77+
```bash
78+
docker-compose -f ./build/nodes/docker-compose.yml stop
79+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.
2+
3+
For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
4+
https://www.r3.com/trademark-policy/.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
buildscript {
2+
Properties constants = new Properties()
3+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
4+
5+
ext {
6+
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
10+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
12+
junit_version = constants.getProperty("junitVersion")
13+
quasar_version = constants.getProperty("quasarVersion")
14+
log4j_version = constants.getProperty("log4jVersion")
15+
slf4j_version = constants.getProperty("slf4jVersion")
16+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
17+
}
18+
19+
repositories {
20+
mavenLocal()
21+
mavenCentral()
22+
jcenter()
23+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
24+
}
25+
26+
dependencies {
27+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
28+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
29+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
30+
}
31+
}
32+
33+
allprojects {
34+
apply from: "${rootProject.projectDir}/repositories.gradle"
35+
apply plugin: 'java'
36+
37+
repositories {
38+
mavenLocal()
39+
jcenter()
40+
mavenCentral()
41+
maven { url 'https://software.r3.com/artifactory/corda' }
42+
maven { url 'https://jitpack.io' }
43+
}
44+
45+
tasks.withType(JavaCompile) {
46+
options.compilerArgs << "-parameters" // Required for shell commands.
47+
}
48+
49+
jar {
50+
// This makes the JAR's SHA-256 hash repeatable.
51+
preserveFileTimestamps = false
52+
reproducibleFileOrder = true
53+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
54+
}
55+
}
56+
57+
apply plugin: 'net.corda.plugins.cordapp'
58+
apply plugin: 'net.corda.plugins.cordformation'
59+
apply plugin: 'net.corda.plugins.quasar-utils'
60+
61+
sourceSets {
62+
main {
63+
resources {
64+
srcDir rootProject.file("config/dev")
65+
}
66+
}
67+
}
68+
69+
dependencies {
70+
// Corda dependencies.
71+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
72+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
73+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
74+
75+
// CorDapp dependencies.
76+
cordapp project("contracts")
77+
cordapp project("workflows")
78+
79+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
80+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
81+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
82+
}
83+
84+
cordapp {
85+
info {
86+
name "DockerForm Yo Cordapp"
87+
vendor "Corda Open Source"
88+
targetPlatformVersion corda_platform_version
89+
minimumPlatformVersion corda_platform_version
90+
}
91+
}
92+
93+
94+
task deployNodesJava(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
95+
96+
nodeDefaults {
97+
projectCordapp {
98+
deploy = false
99+
}
100+
cordapp project("contracts")
101+
cordapp project("workflows")
102+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
103+
}
104+
105+
node {
106+
name "O=Notary,L=London,C=GB"
107+
notary = [validating: false]
108+
p2pPort 10001
109+
p2pAddress "0.0.0.0"
110+
rpcSettings {
111+
address("0.0.0.0:10011")
112+
adminAddress("0.0.0.0:10041")
113+
}
114+
sshdPort 2221
115+
}
116+
117+
node {
118+
name "O=PartyA,L=London,C=GB"
119+
p2pPort 10002
120+
p2pAddress "0.0.0.0"
121+
rpcSettings {
122+
address("0.0.0.0:10012")
123+
adminAddress("0.0.0.0:10042")
124+
}
125+
sshdPort 2222
126+
}
127+
128+
node {
129+
name "O=PartyB,L=New York,C=US"
130+
p2pPort 10003
131+
p2pAddress "0.0.0.0"
132+
rpcSettings {
133+
address("0.0.0.0:10013")
134+
adminAddress("0.0.0.0:10043")
135+
}
136+
sshdPort 2223
137+
}
138+
}
139+
140+
141+
task prepareDockerNodes(type: net.corda.plugins.Dockerform, dependsOn: ['jar']) {
142+
143+
dockerImage = "corda/corda-zulu-java1.8-" + corda_release_version + ":latest"
144+
145+
nodeDefaults {
146+
projectCordapp {
147+
deploy = false
148+
}
149+
cordapp project("contracts")
150+
cordapp project("workflows")
151+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
152+
}
153+
154+
node {
155+
name "O=Notary,L=London,C=GB"
156+
notary = [validating: false]
157+
p2pPort 10001
158+
p2pAddress "0.0.0.0"
159+
rpcSettings {
160+
address("0.0.0.0:10011")
161+
adminAddress("0.0.0.0:10041")
162+
}
163+
sshdPort 2221
164+
}
165+
166+
node {
167+
name "O=PartyA,L=London,C=GB"
168+
p2pPort 10002
169+
p2pAddress "0.0.0.0"
170+
rpcSettings {
171+
address("0.0.0.0:10012")
172+
adminAddress("0.0.0.0:10042")
173+
}
174+
sshdPort 2222
175+
}
176+
177+
node {
178+
name "O=PartyB,L=New York,C=US"
179+
p2pPort 10003
180+
p2pAddress "0.0.0.0"
181+
rpcSettings {
182+
address("0.0.0.0:10013")
183+
adminAddress("0.0.0.0:10043")
184+
}
185+
sshdPort 2223
186+
}
187+
}
188+
189+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="info">
3+
4+
<Properties>
5+
<Property name="log-path">logs</Property>
6+
<Property name="log-name">node-${hostName}</Property>
7+
<Property name="archive">${log-path}/archive</Property>
8+
</Properties>
9+
10+
<ThresholdFilter level="trace"/>
11+
12+
<Appenders>
13+
<Console name="Console-Appender" target="SYSTEM_OUT">
14+
<PatternLayout>
15+
<pattern>
16+
%highlight{%level{length=1} %d{HH:mm:ss} %T %c{1}.%M - %msg%n}{INFO=white,WARN=red,FATAL=bright red blink}
17+
</pattern>>
18+
</PatternLayout>
19+
</Console>
20+
21+
<!-- Will generate up to 10 log files for a given day. During every rollover it will delete
22+
those that are older than 60 days, but keep the most recent 10 GB -->
23+
<RollingFile name="RollingFile-Appender"
24+
fileName="${log-path}/${log-name}.log"
25+
filePattern="${archive}/${log-name}.%d{yyyy-MM-dd}-%i.log.gz">
26+
27+
<PatternLayout pattern="[%-5level] %d{ISO8601}{GMT+0} [%t] %c{1} - %msg%n"/>
28+
29+
<Policies>
30+
<TimeBasedTriggeringPolicy/>
31+
<SizeBasedTriggeringPolicy size="10MB"/>
32+
</Policies>
33+
34+
<DefaultRolloverStrategy min="1" max="10">
35+
<Delete basePath="${archive}" maxDepth="1">
36+
<IfFileName glob="${log-name}*.log.gz"/>
37+
<IfLastModified age="60d">
38+
<IfAny>
39+
<IfAccumulatedFileSize exceeds="10 GB"/>
40+
</IfAny>
41+
</IfLastModified>
42+
</Delete>
43+
</DefaultRolloverStrategy>
44+
45+
</RollingFile>
46+
</Appenders>
47+
48+
<Loggers>
49+
<Root level="info">
50+
<AppenderRef ref="Console-Appender"/>
51+
<AppenderRef ref="RollingFile-Appender"/>
52+
</Root>
53+
<Logger name="net.corda" level="info" additivity="false">
54+
<AppenderRef ref="Console-Appender"/>
55+
<AppenderRef ref="RollingFile-Appender"/>
56+
</Logger>
57+
</Loggers>
58+
59+
</Configuration>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="info">
3+
<Appenders>
4+
<Console name="Console-Appender" target="SYSTEM_OUT">
5+
<PatternLayout>
6+
<pattern>
7+
[%-5level] %d{HH:mm:ss.SSS} [%t] %c{1}.%M - %msg%n
8+
</pattern>>
9+
</PatternLayout>
10+
</Console>
11+
</Appenders>
12+
<Loggers>
13+
<Root level="info">
14+
<AppenderRef ref="Console-Appender"/>
15+
</Root>
16+
<Logger name="net.corda" level="info" additivity="false">
17+
<AppenderRef ref="Console-Appender"/>
18+
</Logger>
19+
</Loggers>
20+
</Configuration>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: 'net.corda.plugins.cordapp'
2+
3+
cordapp {
4+
targetPlatformVersion corda_platform_version
5+
minimumPlatformVersion corda_platform_version
6+
contract {
7+
name "DockerForm Yo Cordapp"
8+
vendor "Corda Open Source"
9+
licence "Apache License, Version 2.0"
10+
versionId 1
11+
}
12+
}
13+
14+
dependencies {
15+
// Corda dependencies.
16+
cordaCompile "$corda_release_group:corda-core:$corda_release_version"
17+
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
18+
}

0 commit comments

Comments
 (0)