Skip to content

Commit a63e098

Browse files
committed
External builder build should not parse flags
FAB-16215 #done Change-Id: Id60dba4c52b94165632a7518a6b1df785badab4f Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 36b1576 commit a63e098

File tree

4 files changed

+34
-72
lines changed

4 files changed

+34
-72
lines changed

core/container/externalbuilders/externalbuilders.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ func (b *Builder) Build(buildContext *BuildContext) error {
205205
build := filepath.Join(b.Location, "bin", "build")
206206
cmd := NewCommand(
207207
build,
208-
"--package-id", buildContext.CCID,
209-
"--path", buildContext.Metadata.Path,
210-
"--type", buildContext.Metadata.Type,
211-
"--source", buildContext.SourceDir,
212-
"--output", buildContext.OutputDir,
208+
buildContext.SourceDir,
209+
buildContext.MetadataDir,
210+
buildContext.OutputDir,
213211
)
214212

215213
err := RunCommand(b.Logger, cmd)

core/container/externalbuilders/externalbuilders_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,40 +168,52 @@ var _ = Describe("Externalbuilders", func() {
168168

169169
Context("when the builder exits with a non-zero status", func() {
170170
BeforeEach(func() {
171-
buildContext.CCID = "unsupported-package-id"
171+
md.Path = "bar"
172+
173+
var err error
174+
codePackage, err = os.Open("testdata/normal_archive.tar.gz")
175+
Expect(err).NotTo(HaveOccurred())
176+
buildContext, err = externalbuilders.NewBuildContext("fake-package-id", md, codePackage)
177+
Expect(err).NotTo(HaveOccurred())
172178
})
173179

174180
It("returns an error", func() {
175181
err := builder.Build(buildContext)
176-
Expect(err).To(MatchError("builder 'testdata' failed: exit status 3"))
182+
Expect(err).To(MatchError("builder 'testdata' failed: exit status 1"))
177183
})
178184
})
179185
})
180186

181187
Describe("Launch", func() {
182-
It("launches the package by invoking external builder", func() {
183-
err := builder.Launch(buildContext, &ccintf.PeerConnection{
188+
var fakeConnection *ccintf.PeerConnection
189+
190+
BeforeEach(func() {
191+
fakeConnection = &ccintf.PeerConnection{
184192
Address: "fake-peer-address",
185193
TLSConfig: &ccintf.TLSConfig{
186194
ClientCert: []byte("fake-client-cert"),
187195
ClientKey: []byte("fake-client-key"),
188196
RootCert: []byte("fake-root-cert"),
189197
},
190-
})
198+
}
199+
})
200+
201+
It("launches the package by invoking external builder", func() {
202+
err := builder.Launch(buildContext, fakeConnection)
191203
Expect(err).NotTo(HaveOccurred())
192204

193205
data1, err := ioutil.ReadFile(filepath.Join(buildContext.LaunchDir, "chaincode.json"))
194206
Expect(err).NotTo(HaveOccurred())
195207
Expect(data1).To(MatchJSON(`{"PeerAddress":"fake-peer-address","ClientCert":"ZmFrZS1jbGllbnQtY2VydA==","ClientKey":"ZmFrZS1jbGllbnQta2V5","RootCert":"ZmFrZS1yb290LWNlcnQ="}`))
196208
})
197209

198-
Context("when the builder exits with a non-zero status", func() {
210+
Context("when the launch exits with a non-zero status", func() {
199211
BeforeEach(func() {
200212
buildContext.CCID = "unsupported-package-id"
201213
})
202214

203215
It("returns an error", func() {
204-
err := builder.Build(buildContext)
216+
err := builder.Launch(buildContext, fakeConnection)
205217
Expect(err).To(MatchError("builder 'testdata' failed: exit status 3"))
206218
})
207219
})
Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,7 @@
11
#!/bin/bash
22

3-
# Used to test that the args match
4-
# "--package-id", string(buildContext.CCCI.PackageID),
5-
# "--path", buildContext.CCCI.Path,
6-
# "--type", buildContext.CCCI.Type,
7-
# "--source", buildContext.SourceDir,
8-
# "--output", buildContext.OutputDir,
9-
10-
if [ "$1" != "--package-id" ] ; then
11-
echo "Expected arg1 to be '--package-id' got '$1'"
12-
exit 2
13-
fi
14-
15-
if [ "$2" != "fake-package-id" ] ; then
16-
echo "Expected arg2 to be 'fake-package-id' got '$2'"
17-
exit 3
18-
fi
19-
20-
if [ "$3" != "--path" ] ; then
21-
echo "Expected arg3 to be '--path' got '$3'"
22-
exit 4
23-
fi
24-
25-
if [ "$4" != "fake-path" ] ; then
26-
echo "Expected arg4 to be 'fake-path' got '$4'"
27-
exit 5
28-
fi
29-
30-
if [ "$5" != "--type" ] ; then
31-
echo "Expected arg5 to be '--type' got '$5'"
32-
exit 6
33-
fi
34-
35-
if [ "$6" != "fake-type" ] ; then
36-
echo "Expected arg6 to be 'fake-type' got '$6'"
37-
exit 7
38-
fi
39-
40-
if [ "$7" != "--source" ] ; then
41-
echo "Expected arg7 to be '--source' got '$7'"
42-
exit 8
43-
fi
44-
45-
if [ "$(basename $8)" != "src" ] ; then
46-
echo "Expected arg8 to be a path ending in 'src' got '$8'"
47-
exit 9
48-
fi
49-
50-
if [ "$9" != "--output" ] ; then
51-
echo "Expected arg9 to be '--source' got '$9'"
52-
exit 10
53-
fi
54-
55-
if [ "$(basename ${10})" != "bld" ] ; then
56-
echo "Expected arg10 to be a path ending in 'bld' got '${10}'"
57-
exit 11
3+
if grep -q "fake-path" "$2/metadata.json" ; then
4+
exit 0
585
fi
596

60-
exit 0
7+
exit 1

integration/externalbuilders/golang/bin/build

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
set -euo pipefail
88

9-
DIR="${BASH_SOURCE%/*}"
10-
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
11-
. "$DIR/parse.sh"
9+
if [ "$#" -ne 3 ]; then
10+
echo "Expected 3 directories got $#"
11+
exit 1
12+
fi
1213

13-
GOPATH=$SOURCE:$GOPATH go build -o "$OUTPUT/chaincode" -ldflags "-linkmode external -extldflags '-static'" "$GO_PACKAGE_PATH"
14+
SOURCE=$1
15+
GO_PACKAGE_PATH="$(grep -o '"Path": *"[^"]*"' "$2/metadata.json"| grep -o '"[^"]*"$')"
16+
OUTPUT=$3
17+
18+
GOPATH=$SOURCE:$GOPATH go build -o "$OUTPUT/chaincode" -ldflags "-linkmode external -extldflags '-static'" $GO_PACKAGE_PATH

0 commit comments

Comments
 (0)