Skip to content

Commit

Permalink
Switch base docker image from golang-alpine to ubuntu:20.04
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>
  • Loading branch information
jkneubuh committed Dec 21, 2022
1 parent 12625f5 commit 0175e46
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 125 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ on:

env:
GO_VER: 1.18.9
ALPINE_VER: 3.16
UBUNTU_VER: 20.04
FABRIC_VER: ${{ github.ref_name }}
DOCKER_REGISTRY: docker.io # or ghcr.io
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}

permissions:
contents: read
Expand Down Expand Up @@ -101,8 +101,8 @@ jobs:
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ contains(env.DOCKER_REGISTRY, 'docker.io') && secrets.DOCKERHUB_USERNAME || github.actor }}
password: ${{ contains(env.DOCKER_REGISTRY, 'docker.io') && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
Expand All @@ -126,7 +126,7 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
FABRIC_VER=${{ env.FABRIC_VER }}
ALPINE_VER=${{ env.ALPINE_VER }}
UBUNTU_VER=${{ env.UBUNTU_VER }}
GO_VER=${{ env.GO_VER }}
GO_TAGS=
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# - unit-test - runs the go-test based unit tests
# - verify - runs unit tests for only the changed package tree

ALPINE_VER ?= 3.16
UBUNTU_VER ?= 20.04
FABRIC_VER ?= 2.5.0

# 3rd party image version
Expand Down Expand Up @@ -248,7 +248,7 @@ $(BUILD_DIR)/images/%/$(DUMMY):
@mkdir -p $(@D)
$(DBUILD) -f images/$*/Dockerfile \
--build-arg GO_VER=$(GO_VER) \
--build-arg ALPINE_VER=$(ALPINE_VER) \
--build-arg UBUNTU_VER=$(UBUNTU_VER) \
--build-arg FABRIC_VER=$(FABRIC_VER) \
--build-arg TARGETARCH=$(ARCH) \
--build-arg TARGETOS=linux \
Expand Down
31 changes: 25 additions & 6 deletions images/baseos/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# Copyright IBM Corp. All Rights Reserved.
#
# Copyright contributors to the Hyperledger Fabric project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ARG GO_VER
ARG ALPINE_VER
ARG UBUNTU_VER

FROM ubuntu:${UBUNTU_VER} as base

RUN apt update
RUN apt install -y tzdata

RUN addgroup --gid 500 chaincode
RUN adduser --disabled-password --gecos "" --uid 500 --gid 500 --home /home/chaincode chaincode

FROM alpine:${ALPINE_VER} as base
RUN apk add --no-cache tzdata
RUN addgroup -g 500 chaincode && adduser -u 500 -D -h /home/chaincode -G chaincode chaincode
USER chaincode
USER chaincode
52 changes: 39 additions & 13 deletions images/ccenv/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
# Copyright IBM Corp. All Rights Reserved.
#
# Copyright contributors to the Hyperledger Fabric project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER}

ARG TARGETARCH
ARG TARGETOS
ARG GO_VER
ARG ALPINE_VER
FROM golang:${GO_VER}-alpine${ALPINE_VER}
RUN apk add --no-cache \
binutils-gold \
g++ \
gcc \
git \
musl-dev

RUN mkdir -p /chaincode/output /chaincode/input
RUN addgroup -g 500 chaincode && adduser -u 500 -D -h /home/chaincode -G chaincode chaincode
RUN chown -R chaincode:chaincode /chaincode

RUN apt update
RUN apt install -y binutils-gold
RUN apt install -y curl
RUN apt install -y g++
RUN apt install -y gcc
RUN apt install -y git

RUN curl -sL https://go.dev/dl/go${GO_VER}.${TARGETOS}-${TARGETARCH}.tar.gz | tar zxvf - -C /usr/local
ENV PATH="/usr/local/go/bin:$PATH"

RUN addgroup --gid 500 chaincode
RUN adduser --disabled-password --gecos "" --uid 500 --gid 500 --home /home/chaincode chaincode

RUN mkdir -p /chaincode/output /chaincode/input
RUN chown -R chaincode:chaincode /chaincode

USER chaincode


91 changes: 58 additions & 33 deletions images/orderer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
# Copyright IBM Corp. All Rights Reserved.
#
# Copyright contributors to the Hyperledger Fabric project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

###############################################################################
# Build image
###############################################################################

ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER} as builder

ARG TARGETARCH
ARG TARGETOS
ARG GO_VER
ARG ALPINE_VER
ARG GO_TAGS

RUN apt update
RUN apt install -y git
RUN apt install -y gcc
RUN apt install -y curl
RUN apt install -y make
RUN curl -sL https://go.dev/dl/go${GO_VER}.${TARGETOS}-${TARGETARCH}.tar.gz | tar zxvf - -C /usr/local
ENV PATH="/usr/local/go/bin:$PATH"

ADD . .

RUN make orderer GO_TAGS=${GO_TAGS}


###############################################################################
# Runtime image
###############################################################################

ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER}

ARG FABRIC_VER

FROM alpine:${ALPINE_VER} as base
RUN apk add --no-cache tzdata
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN echo 'hosts: files dns' > /etc/nsswitch.conf

FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
RUN apk add --no-cache \
bash \
binutils-gold \
gcc \
git \
make \
musl-dev
ADD . $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric

FROM golang as orderer
ARG GO_TAGS
ARG FABRIC_VER
ENV FABRIC_VER ${FABRIC_VER}
ENV FABRIC_CFG_PATH /var/hyperledger/fabric/config
ENV FABRIC_VER ${FABRIC_VER}

# Disable cgo when building in the container. This will create a static binary, which can be
# copied and run in the base alpine container without the libc/musl runtime.
ENV CGO_ENABLED 0
COPY --from=builder build/bin/orderer /usr/local/bin
COPY --from=builder sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=builder sampleconfig/orderer.yaml ${FABRIC_CFG_PATH}
COPY --from=builder sampleconfig/configtx.yaml ${FABRIC_CFG_PATH}

RUN make orderer GO_TAGS=${GO_TAGS}
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
EXPOSE 7050

FROM base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=orderer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/orderer.yaml ${FABRIC_CFG_PATH}
COPY --from=orderer /go/src/github.com/hyperledger/fabric/sampleconfig/configtx.yaml ${FABRIC_CFG_PATH}
EXPOSE 7050
CMD ["orderer"]
ENTRYPOINT [ "orderer" ]
CMD [ "start" ]
100 changes: 64 additions & 36 deletions images/peer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,76 @@
# Copyright IBM Corp. All Rights Reserved.
#
# Copyright contributors to the Hyperledger Fabric project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

###############################################################################
# Build image
###############################################################################

ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER} as builder

ARG TARGETARCH
ARG TARGETOS
ARG GO_VER
ARG ALPINE_VER
FROM alpine:${ALPINE_VER} as peer-base
RUN apk add --no-cache tzdata
ARG GO_TAGS

RUN apt update
RUN apt install -y git
RUN apt install -y gcc
RUN apt install -y curl
RUN apt install -y make
RUN curl -sL https://go.dev/dl/go${GO_VER}.${TARGETOS}-${TARGETARCH}.tar.gz | tar zxvf - -C /usr/local
ENV PATH="/usr/local/go/bin:$PATH"

ADD . .

RUN make peer GO_TAGS=${GO_TAGS}
RUN make ccaasbuilder


###############################################################################
# Runtime image
###############################################################################

ARG UBUNTU_VER
FROM ubuntu:${UBUNTU_VER}

ARG TARGETOS
ARG TARGETARCH
ARG FABRIC_VER

# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN echo 'hosts: files dns' > /etc/nsswitch.conf

FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
RUN apk add --no-cache \
bash \
binutils-gold \
gcc \
git \
make \
musl-dev
ADD . $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric

FROM golang as peer
ARG GO_TAGS
ARG FABRIC_VER
ENV FABRIC_VER ${FABRIC_VER}
ENV FABRIC_CFG_PATH /var/hyperledger/fabric/config
ENV FABRIC_VER ${FABRIC_VER}

# Disable cgo when building in the container. This will create a static binary, which can be
# copied and run in the base alpine container without the libc/musl runtime.
ENV CGO_ENABLED 0
COPY --from=builder build/bin/peer /usr/local/bin
COPY --from=builder sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=builder sampleconfig/core.yaml ${FABRIC_CFG_PATH}/core.yaml

RUN make peer GO_TAGS=${GO_TAGS}
RUN make ccaasbuilder
COPY --from=builder release/${TARGETOS}-${TARGETARCH}/builders/ccaas/bin /opt/hyperledger/ccaas_builder/bin

FROM peer-base
ARG TARGETARCH
ARG TARGETOS
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}/core.yaml
COPY --from=peer /go/src/github.com/hyperledger/fabric/release/${TARGETOS}-${TARGETARCH}/builders/ccaas/bin/ /opt/hyperledger/ccaas_builder/bin/
EXPOSE 7051
CMD ["peer","node","start"]
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger

EXPOSE 7051

ENTRYPOINT [ "peer" ]
CMD [ "node", "start" ]
Loading

0 comments on commit 0175e46

Please sign in to comment.