Skip to content

Commit 7fd9e21

Browse files
authored
Improve Dockerfile and .dockerignore to minimize files being copied (#479)
* improve `Dockerfile` for prod-ready image Signed-off-by: pco <[email protected]> * improved `.dockerignore` and removed `.travis.yml` since not needed on github.com Signed-off-by: pco <[email protected]> * added script to build multiplatform image Signed-off-by: pco <[email protected]> * fixed help in script Signed-off-by: pco <[email protected]> * added missing header Signed-off-by: pco <[email protected]> * improve `Dockerfile` for prod-ready image Signed-off-by: pco <[email protected]> * improved `.dockerignore` and removed `.travis.yml` since not needed on github.com Signed-off-by: pco <[email protected]> * added script to build multiplatform image Signed-off-by: pco <[email protected]> * fixed help in script Signed-off-by: pco <[email protected]> * added missing header Signed-off-by: pco <[email protected]> --------- Signed-off-by: pco <[email protected]>
1 parent efea478 commit 7fd9e21

File tree

7 files changed

+365
-130
lines changed

7 files changed

+365
-130
lines changed

.dockerignore

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,26 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6-
.github
6+
# git
7+
.git
8+
.gitignore
9+
.github
10+
11+
# docs
12+
README.md
13+
CODE_OF_CONDUCT.md
14+
MAINTAINERS.md
15+
LICENSE
16+
17+
# docker/podman
18+
Dockerfile
19+
20+
# go
21+
staticcheck.conf
22+
.golangci.yml
23+
.whitesource
24+
25+
# misc
26+
.DS_Store
27+
.env
28+
deployment

.github/workflows/docker-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
context: .
6767
file: ./images/multi-platform/Dockerfile
6868
platforms: linux/amd64,linux/arm64,linux/s390x
69+
build-args: |
70+
VERSION=${{ env.VERSION }}
6971
push: true
7072
tags: |
7173
docker.io/${{ env.IMAGE_PREFIX }}/fabric-x-orderer:${{ env.VERSION }}

.travis.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

Makefile

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
# - docker-local: builds a single-platform image for the host’s OS/architecture
1717
# - docker-multiarch: wrapper that triggers docker builds for multiple platforms
1818

19-
TAG ?= latest
19+
# Docker image vars
2020
DOCKERFILE ?= images/multi-platform/Dockerfile
21-
DOCKER_IMAGE ?= arma
21+
IMAGE_NAMESPACE = docker.io/hyperledger
22+
IMAGE_NAME = fabric-x-orderer
23+
VERSION = latest
2224

2325
.PHONY: basic-checks
2426
basic-checks: check-license check-dco check-protos linter
@@ -79,46 +81,14 @@ sample-tests:
7981
(cd node/examples; bash ./scripts/build_docker.sh)
8082
(bash ./node/examples/scripts/run_sample.sh)
8183

82-
.PHONY: docker
83-
docker:
84-
docker build -t $(DOCKER_IMAGE) --no-cache -f $(DOCKERFILE) .
85-
86-
# Build for current OS/architecture
87-
.PHONY: docker-local
88-
docker-local:
89-
@echo "Building local Docker image: $(DOCKER_IMAGE):$(TAG)"
90-
docker build \
91-
-f images/multi-platform/Dockerfile \
92-
-t $(DOCKER_IMAGE):$(TAG) \
93-
.
94-
95-
.PHONY: docker-multiarch
96-
docker-multiarch:
97-
@echo "Building images for all platforms locally..."
98-
make docker-linux-amd64
99-
make docker-linux-arm64
100-
make docker-linux-s390x
101-
102-
.PHONY: docker-linux-amd64
103-
docker-linux-amd64:
104-
@echo "Building linux/amd64"
105-
docker buildx build --platform linux/amd64 -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-amd64 --load .
106-
107-
.PHONY: docker-linux-arm64
108-
docker-linux-arm64:
109-
@echo "Building linux/arm64"
110-
docker buildx build --platform linux/arm64 -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-arm64 --load .
111-
112-
.PHONY: docker-linux-s390x
113-
docker-linux-s390x:
114-
@echo "Building linux/s390x"
115-
docker buildx build --platform linux/s390x -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-s390x --load .
116-
117-
118-
119-
120-
121-
122-
123-
124-
84+
# Build the HLFX Orderer image
85+
.PHONY: build-image
86+
build-image:
87+
@echo "Building the image ${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}..."
88+
@./scripts/build_image.sh -t ${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION} -f ${DOCKERFILE} --build-arg VERSION=${VERSION}
89+
90+
# Build the HLFX Orderer multiplatform image
91+
.PHONY: build-multiplatform-image
92+
build-multiplatform-image:
93+
@echo "Building the multiplatform image ${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}..."
94+
@./scripts/build_image.sh -t ${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION} -f ${DOCKERFILE} --multiplatform --build-arg VERSION=${VERSION}

README.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Hyperledger Fabric-X Orderer
22

3-
This repository contains the ordering service of fabric-x.
3+
This repository contains the ordering service of fabric-x.
44
The ordering service is based on the Arma protocol:
55

66
"Arma: a scalable Byzantine Fault Tolerant ordering service".
77

8-
98
## Abstract
109

1110
Arma is a Byzantine Fault Tolerant (BFT) consensus system designed to achieve horizontal scalability across all hardware
@@ -36,15 +35,15 @@ Clients submit transactions to the routers, whereas blocks are consumed from the
3635

3736
More details on the internal architecture and inner workings of Arma can be found in the white paper: [https://ia.cr/2024/808]
3837

39-
4038
## Client API
4139

4240
Arma provides a gRPC service for submitting transactions and consuming blocks. This service is identical to Fabric's "Atomic Broadcast API".
4341
The gRPC service is defined here: [https://github.com/hyperledger/fabric-protos/blob/main/orderer/ab.proto]
4442

4543
It defines two services:
46-
- The `Broadcast` service allows a client to submit transactions for ordering by the ordering servers.
47-
- The `Deliver` service allows clients to consume ordered blocks.
44+
45+
- The `Broadcast` service allows a client to submit transactions for ordering by the ordering servers.
46+
- The `Deliver` service allows clients to consume ordered blocks.
4847

4948
```protobuf
5049
service AtomicBroadcast {
@@ -88,41 +87,53 @@ signatures.
8887
Arma is composed of 4 types of servers: `router`, `batcher`, `consensus` and `assembler`; also known as "server roles".
8988
To start a server use the arma CLI tool:
9089

91-
* To run a router node:
92-
```bash
93-
./arma router --config=arma-config/Party1/router_node_config.yaml
94-
```
95-
* To run a batcher node:
96-
```bash
97-
./arma batcher --config=arma-config/Party1/batcher_node_1_config.yaml
98-
```
99-
* To run a consenter node:
100-
```bash
101-
./arma consensus --config=arma-config/Party1/consenter_node_config.yaml
102-
```
103-
* To run an assembler node:
104-
```bash
105-
./arma assembler --config=arma-config/Party1/assembler_node_config.yaml
106-
```
90+
- To run a router node:
91+
92+
```bash
93+
./arma router --config=arma-config/Party1/router_node_config.yaml
94+
```
95+
96+
- To run a batcher node:
97+
98+
```bash
99+
./arma batcher --config=arma-config/Party1/batcher_node_1_config.yaml
100+
```
101+
102+
- To run a consenter node:
103+
104+
```bash
105+
./arma consensus --config=arma-config/Party1/consenter_node_config.yaml
106+
```
107+
108+
- To run an assembler node:
109+
110+
```bash
111+
./arma assembler --config=arma-config/Party1/assembler_node_config.yaml
112+
```
107113

108114
Each server role expects a config file, specified in the command line (mandatory).
109115
For more details please refer to [arma-deployment](deployment/README.md).
110116

117+
## Build Docker image locally
118+
119+
To build the Docker image locally with either `Docker` or `Podman`, run:
120+
121+
```bash
122+
make build-image
123+
```
124+
111125
### Starting with a genesis block
112126

113127
The local configuration of each node points to the location of the genesis block.
114-
That way, when a node starts up, it bootstraps from the genesis block and extract its shared configuration.
128+
That way, when a node starts up, it bootstraps from the genesis block and extract its shared configuration.
115129

116130
NOTE: All parties and all servers must be given the same genesis block.
117131
If a genesis block is not found, Arma will fail to start.
118132

119-
120133
## Configuration and deployment
121134

122135
For more information about deployment of Arma, please refer to [arma-deployment](deployment/README.md).
123136

124-
125-
126137
## Tools
127-
Armageddon is a command-line tool that provides a simple way to config an ARMA network, for more information please refer to [armageddon](cmd/armageddon/README.md).
128138

139+
Armageddon is a command-line tool that provides a simple way to config an ARMA network, for more information please refer to [armageddon](cmd/armageddon/README.md).

images/multi-platform/Dockerfile

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Copyright IBM Corp. All Rights Reserved.
23
#
34
# SPDX-License-Identifier: Apache-2.0
@@ -7,37 +8,51 @@ FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.25.5 AS builder
78
# Build arguments used for cross-compiling
89
ARG TARGETOS
910
ARG TARGETARCH
11+
12+
# Environment vars
1013
ENV GOOS=${TARGETOS}
1114
ENV GOARCH=${TARGETARCH}
12-
ENV CGO_ENABLED=0 \
13-
GO111MODULE=on
15+
ENV GO111MODULE=on
16+
ENV CGO_ENABLED=0
17+
1418
WORKDIR /src
1519

16-
# Now copy rest of the source
20+
# Copy build files (managed through .dockerignore)
1721
COPY . .
1822

23+
RUN ls -la .
24+
1925
# Build using your Makefile target
2026
RUN make binary
2127

22-
# -----------------------------------------------------------------------------
23-
# Stage 2: Production Image (UBI-micro)
24-
# -----------------------------------------------------------------------------
25-
FROM registry.access.redhat.com/ubi9/ubi-micro:9.5 AS prod
28+
###########################################
29+
# Stage 2: Production runtime image
30+
###########################################
31+
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.6 AS prod
2632

27-
# Add a non-root user for security (UBI-micro has no useradd)
33+
ARG VERSION=1.0
2834

29-
USER 10001
30-
WORKDIR /app
35+
# Add non-root user (10001) without installing extra packages
36+
RUN /usr/sbin/useradd -u 10001 -r -g root -s /sbin/nologin -c "Hyperledger Fabric-X Orderer user" orderer && \
37+
mkdir -p /home/orderer && \
38+
chown -R 10001:0 /home/orderer && \
39+
chmod 0755 /home/orderer
3140

3241
# Copy in the statically built binaries from builder
3342
COPY --from=builder /src/bin/arma /usr/local/bin/arma
3443
COPY --from=builder /src/bin/armageddon /usr/local/bin/armageddon
3544

36-
# OCI labels (strongly recommended for prod images)
37-
LABEL name="arma-service" \
38-
vendor="IBM" \
39-
maintainer="IBM Research Decentralized Trust Group" \
40-
summary="ARMA Service Production Image" \
41-
description="Lightweight and secure Go application running on UBI-micro" \
42-
license="Apache-2.0"
45+
# OCI metadata labels
46+
LABEL name="fabric-x-orderer" \
47+
maintainer="IBM Research Decentralized Trust Group" \
48+
version="${VERSION}" \
49+
description="Hyperledger Fabric-X Orderer service packaged in a UBI image" \
50+
license="Apache-2.0" \
51+
vendor="IBM"
52+
53+
# Use non-root user and set workdir using BIN argument
54+
USER 10001
55+
WORKDIR /home/orderer
56+
57+
# Default entrypoint
4358
ENTRYPOINT ["/usr/local/bin/arma"]

0 commit comments

Comments
 (0)