Skip to content

Commit d496c33

Browse files
Github Action Pipeline For ChainCode Builder (#9)
* Initial Github Action Changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * GitHub Action Intial Draft Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * License Scripts Added Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * License Scripts Added Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Removed the .DS_Store Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Permission changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Add Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Gi Version Changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Gi Version Changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> * Docker File Changes Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com> --------- Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com>
1 parent 8d4401c commit d496c33

File tree

6 files changed

+352
-1
lines changed

6 files changed

+352
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# Copyright contributors to the Hyperledger Fabric Operator project
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at:
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
name: Chaincode Builder Image Build and Checks
20+
21+
on:
22+
push:
23+
branches: [main]
24+
pull_request:
25+
branches: [main]
26+
workflow_dispatch:
27+
28+
env:
29+
GO_VER: 1.24.3
30+
GOPROXY: "https://proxy.golang.org,direct" # Bypass all proxies to avoid TLS issues
31+
GO111MODULE: on # Ensure module-aware mode
32+
GOPATH: /opt/go
33+
jobs:
34+
build-image:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Set up go
39+
uses: actions/setup-go@v4
40+
with:
41+
go-version: ${{ env.GO_VER }}
42+
- name: Ensure Go is in PATH
43+
run: |
44+
echo "GOPATH: $GOPATH"
45+
echo "PATH: $PATH"
46+
- name: Check Go version
47+
run: |
48+
echo "*********************Go version:***************************"
49+
go version
50+
echo "************************************************************"
51+
- name: unit-tests
52+
run: go test `go list ./... | grep -v integration`
53+
- name: checks
54+
run: |
55+
echo "*********************Running checks*************************"
56+
chmod +x scripts/*
57+
make checks
58+
- name: gosec
59+
run: make gosec
60+
- name: build
61+
run: make image
62+

.github/workflows/image.build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build and Push Chaincode Builder image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
image:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Push
14+
run: |
15+
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
16+
make image image-push

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ build/
33
.env
44
golang_copyright.txt
55
shell_copyright.txt
6-
launch.json
6+
launch.json
7+
.DS_Store

Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright contributors to the Hyperledger Fabric Operations Console project
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at:
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
ARG ARCH
19+
ARG GO_VER
20+
21+
FROM registry.access.redhat.com/ubi9/ubi-minimal as builder
22+
ARG GO_VER
23+
ARG ARCH
24+
# gcc required for cgo
25+
RUN microdnf install -y make gcc tar gzip gcc-c++ && microdnf clean all
26+
RUN echo "GO_VER=${GO_VER}" && echo "ARCH=${ARCH}"
27+
RUN test -n "$GO_VER" && test -n "$ARCH" || (echo "GO_VER or ARCH not set!" && exit 1)
28+
29+
RUN curl -sSL https://go.dev/dl/go${GO_VER}.linux-${ARCH}.tar.gz | tar zxf - -C /usr/local
30+
31+
ENV PATH="/usr/local/go/bin:$PATH"
32+
COPY . /go/src/github.ibm.com/fabric/fabric-chaincode-builder
33+
WORKDIR /go/src/github.ibm.com/fabric/fabric-chaincode-builder
34+
RUN GOOS=linux GOARCH=$(go env GOARCH) go build -o build/fabric-chaincode-builder ./cmd/ibp-builder
35+
36+
FROM registry.access.redhat.com/ubi9/ubi-minimal
37+
ARG IBP_VER
38+
ARG BUILD_ID
39+
ARG BUILD_DATE
40+
41+
42+
ENV BUILDER=/usr/local/bin/fabric-chaincode-builder \
43+
USER_UID=1001 \
44+
USER_NAME=fabric-chaincode-builder \
45+
CLIENT_TIMEOUT=5m \
46+
FILE_SERVER_LISTEN_IP=0.0.0.0 \
47+
FILE_SERVER_LISTEN_PORT=22222 \
48+
SHARED_VOLUME_PATH=/data \
49+
SIDECAR_LISTEN_ADDRESS=0.0.0.0:11111
50+
51+
RUN microdnf update -y
52+
RUN microdnf install -y shadow-utils iputils
53+
RUN groupadd -g 7051 ibp-user \
54+
&& useradd -u 7051 -g ibp-user -s /bin/bash ibp-user \
55+
&& microdnf remove -y shadow-utils \
56+
&& microdnf clean -y all;
57+
58+
COPY --from=builder /go/src/github.ibm.com/fabric/fabric-chaincode-builder/build/fabric-chaincode-builder ${BUILDER}
59+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
60+
61+
USER ibp-user
62+
63+
ENTRYPOINT ["docker-entrypoint.sh"]
64+
CMD [ "sh", "-c", "fabric-chaincode-builder --kubeconfig \"${KUBECONFIG}\" --kubeNamespace \"${KUBE_NAMESPACE}\" --clientTimeout \"${CLIENT_TIMEOUT}\" --peerID \"${PEER_ID}\" --sharedVolumePath \"${SHARED_VOLUME_PATH}\" --fileServerListenAddress \"${FILE_SERVER_LISTEN_IP}:${FILE_SERVER_LISTEN_PORT}\" --sidecarListenAddress \"${SIDECAR_LISTEN_ADDRESS}\" --fileServerBaseURL \"${FILE_SERVER_BASE_URL}\"" ]

Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# Copyright contributors to the Hyperledger Fabric Operator project
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at:
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
20+
IMAGE ?= ghcr.io/hyperledger-labs/fabric-chaincode-builder
21+
TAG ?= $(shell git rev-parse --short HEAD)
22+
ARCH ?= $(shell go env GOARCH)
23+
BRANCH ?= $(shell git branch --show-current)
24+
DOCKER_IMAGE_REPO ?= ghcr.io
25+
REGISTRY ?= $(DOCKER_IMAGE_REPO)/ibp-golang
26+
GO_VER ?= 1.24.3
27+
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
28+
GOOS ?= $(shell go env GOOS)
29+
30+
31+
BUILD_ARGS=--build-arg ARCH=$(ARCH)
32+
BUILD_ARGS+=--build-arg REGISTRY=$(REGISTRY)
33+
BUILD_ARGS+=--build-arg BUILD_ID=$(TAG)
34+
BUILD_ARGS+=--build-arg BUILD_DATE=$(BUILD_DATE)
35+
BUILD_ARGS+=--build-arg GO_VER=$(GO_VER)
36+
37+
38+
.PHONY: build login
39+
40+
int-tests:
41+
@ginkgo -v ./integration
42+
43+
build:
44+
GOOS=$(GOOS) GOARCH=$(ARCH) go build -o build/fabric-chaincode-builder ./cmd/ibp-builder
45+
GOOS=$(GOOS) GOARCH=$(ARCH) go build -o build/fabric-chaincode-builder-client ./cmd/ibp-builder-client
46+
47+
image: ## Builds a x86 based image
48+
@go mod vendor
49+
docker build --rm . -f Dockerfile $(BUILD_ARGS) -t $(IMAGE):$(TAG)-$(ARCH)
50+
docker tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest-$(ARCH)
51+
52+
image-nologin:
53+
@go mod vendor
54+
docker build --rm . -f Dockerfile $(BUILD_ARGS) -t $(IMAGE):$(TAG)-$(ARCH)
55+
docker tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest-$(ARCH)
56+
image-push:
57+
docker push $(IMAGE):$(TAG)-$(ARCH)
58+
59+
unit-tests:
60+
go test `go list ./... | grep -v integration`
61+
62+
gosec:
63+
@scripts/go-sec.sh
64+
65+
checks: license
66+
@scripts/checks
67+
68+
.PHONY: license
69+
license:
70+
@scripts/check-license.sh

scripts/check-license.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
#
3+
# Copyright contributors to the Hyperledger Fabric Operations Console project
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at:
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
cat << EOB > golang_copyright.txt
21+
/*
22+
* Copyright contributors to the Hyperledger Fabric Operations Console project
23+
*
24+
* SPDX-License-Identifier: Apache-2.0
25+
*
26+
* Licensed under the Apache License, Version 2.0 (the "License");
27+
* you may not use this file except in compliance with the License.
28+
* You may obtain a copy of the License at:
29+
*
30+
* http://www.apache.org/licenses/LICENSE-2.0
31+
*
32+
* Unless required by applicable law or agreed to in writing, software
33+
* distributed under the License is distributed on an "AS IS" BASIS,
34+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35+
* See the License for the specific language governing permissions and
36+
* limitations under the License.
37+
*/
38+
39+
EOB
40+
41+
cat << EOB > shell_copyright.txt
42+
#
43+
# Copyright contributors to the Hyperledger Fabric Operations Console project
44+
#
45+
# SPDX-License-Identifier: Apache-2.0
46+
#
47+
# Licensed under the Apache License, Version 2.0 (the "License");
48+
# you may not use this file except in compliance with the License.
49+
# You may obtain a copy of the License at:
50+
#
51+
# http://www.apache.org/licenses/LICENSE-2.0
52+
#
53+
# Unless required by applicable law or agreed to in writing, software
54+
# distributed under the License is distributed on an "AS IS" BASIS,
55+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56+
# See the License for the specific language governing permissions and
57+
# limitations under the License.
58+
#
59+
60+
EOB
61+
62+
function filterGeneratedFiles {
63+
for f in $@; do
64+
head -n5 $f | grep -qE 'Code generated by.*DO NOT EDIT' || echo $f
65+
done
66+
}
67+
68+
function filterExcludedFiles {
69+
CHECK=`echo "$CHECK" \
70+
| grep -v "^\.build/" \
71+
| grep -v "^\.git/" \
72+
| grep -v "^\.gitignore" \
73+
| grep -v "\.json$" \
74+
| grep -v "\.pem$" \
75+
| grep -v "\.crt$" \
76+
| grep -v "\.txt$" \
77+
| grep -v "\.md$" \
78+
| grep -v "_sk$" \
79+
| grep -v "\.key$" \
80+
| grep -v "\.gen\.go$" \
81+
| grep -v "tools/" \
82+
| grep -v "testdata/" \
83+
| grep -v "vendor/" \
84+
| grep -v "go.mod" \
85+
| grep -v "go.sum" \
86+
| grep -v .secrets.baseline \
87+
| grep -v .pre-commit-config.yaml \
88+
| sort -u`
89+
90+
CHECK=$(filterGeneratedFiles "$CHECK")
91+
}
92+
93+
CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
94+
filterExcludedFiles
95+
if [[ -z "$CHECK" ]]; then
96+
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r "HEAD^..HEAD")
97+
filterExcludedFiles
98+
fi
99+
100+
if [[ -z "$CHECK" ]]; then
101+
echo "All files are excluded from having license headers"
102+
exit 0
103+
fi
104+
105+
missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier: Apache-2.0"`
106+
if [[ -z "$missing" ]]; then
107+
echo "All files have SPDX-License-Identifier: Apache-2.0"
108+
exit 0
109+
fi
110+
111+
TMPFILE="./tmpfile"
112+
113+
for FILE in ${missing}; do
114+
EXT="${FILE##*.}"
115+
echo "Adding copyright notice to $FILE"
116+
if [ "${EXT}" = "go" ]; then
117+
cat golang_copyright.txt ${FILE} > ${TMPFILE}
118+
cat ${TMPFILE} > ${FILE}
119+
rm -f ${TMPFILE}
120+
echo " ${FILE} copyright notice added"
121+
elif [ "${EXT}" = "yaml" ]; then
122+
cat shell_copyright.txt ${FILE} > ${TMPFILE}
123+
cat ${TMPFILE} > ${FILE}
124+
rm -f ${TMPFILE}
125+
echo " ${FILE} copyright notice added"
126+
elif [ "${EXT}" = "sh" ]; then
127+
cat shell_copyright.txt ${FILE} > ${TMPFILE}
128+
cat ${TMPFILE} > ${FILE}
129+
rm -f ${TMPFILE}
130+
echo " ${FILE} copyright notice added"
131+
else
132+
echo "invalid file extension"
133+
fi
134+
done
135+
136+
rm golang_copyright.txt shell_copyright.txt
137+
138+
exit 0

0 commit comments

Comments
 (0)