Skip to content

Commit

Permalink
Generalize dockerfile arch
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-at-luther committed Jul 7, 2024
1 parent 3da7498 commit 452d392
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 21 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,31 @@ on:
tags:
- "*"
jobs:
build-push:
build-push-docker:
name: ${{ matrix.image }} - ${{ matrix.arch }} docker build push
runs-on: ${{ fromJSON('{"arm64":"buildjet-2vcpu-ubuntu-2204-arm","amd64":"ubuntu-22.04"}')[matrix.arch] }}
strategy:
matrix:
arch:
- amd64
- arm64
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Configure DockerHub
uses: ./.github/actions/configure-dockerhub
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
- name: Publish
run: make docker-push VERSION=$GITHUB_REF_NAME TAG_SUFFIX=-${{ matrix.arch }}
push-docker-manifests:
runs-on: ubuntu-22.04
needs:
- build-push-docker
steps:
- uses: actions/checkout@v4.1.5
- uses: actions/checkout@v4
with:
lfs: true
- name: Configure DockerHub
Expand All @@ -16,4 +37,4 @@ jobs:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
- name: Publish
run: make docker-push VERSION=$GITHUB_REF_NAME
run: make push-manifests VERSION=$GITHUB_REF_NAME
30 changes: 19 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# byfn-vars builder
#
FROM debian:bullseye as byfn-vars-builder
FROM debian:bullseye AS byfn-vars-builder

ARG BASEIMAGETAG=0.4.20
ARG IMAGETAG=2.5.4
Expand All @@ -22,29 +22,37 @@ RUN envsubst < /tmp/byfn-vars.sh.template > /tmp/byfn-vars.sh
#
# fabric artifacts builder
#
FROM --platform=linux/$TARGETARCH debian:bullseye as fabric-artifacts-builder
ARG TARGETARCH
FROM debian:bullseye AS fabric-artifacts-builder

ARG FABRIC_VERSION=2.5.4
ARG FABRIC_CRYPTOGEN_VERSION=${FABRIC_VERSION}

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Function to map uname -m to amd64 or arm64
RUN ARCH=$(uname -m) && \
case "$ARCH" in \
x86_64) ARCH="amd64" ;; \
aarch64) ARCH="arm64" ;; \
arm64) ARCH="arm64" ;; \
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
esac && \
apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /tmp/hyperledger/fabric \
&& cd /tmp/hyperledger/fabric \
&& curl -sSL https://github.com/hyperledger/fabric/releases/download/v${FABRIC_VERSION}/hyperledger-fabric-linux-${TARGETARCH}-${FABRIC_VERSION}.tar.gz | tar xz \
&& curl -sSL "https://github.com/hyperledger/fabric/releases/download/v${FABRIC_VERSION}/hyperledger-fabric-linux-${ARCH}-${FABRIC_VERSION}.tar.gz" | tar xz \
&& if [ "${FABRIC_VERSION}" != "${FABRIC_CRYPTOGEN_VERSION}" ]; then \
curl -sSL https://github.com/hyperledger/fabric/releases/download/v${FABRIC_CRYPTOGEN_VERSION}/hyperledger-fabric-linux-${TARGETARCH}-${FABRIC_CRYPTOGEN_VERSION}.tar.gz | tar xz cryptogen; \
curl -sSL "https://github.com/hyperledger/fabric/releases/download/v${FABRIC_CRYPTOGEN_VERSION}/hyperledger-fabric-linux-${ARCH}-${FABRIC_CRYPTOGEN_VERSION}.tar.gz" | tar xz cryptogen; \
fi
#

# FNB image
#
FROM --platform=linux/$TARGETARCH python:3.12-bullseye
ARG TARGETARCH
FROM python:3.12-bullseye

RUN apt-get update && apt-get install --no-install-recommends -y zip rsync gettext-base docker.io && rm -rf /var/lib/apt/lists/*

ARG COMPOSE_VER=2.20.0
RUN curl -L "https://github.com/docker/compose/releases/download/v${COMPOSE_VER}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
RUN curl -sSL "https://github.com/docker/compose/releases/download/v${COMPOSE_VER}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

RUN mkdir /network
WORKDIR /network
Expand All @@ -54,7 +62,7 @@ RUN ln -s /var/lib/fabric-network-builder/network.py /usr/bin/fabric-network-bui
ENV PATH=$PATH:/var/lib/fabric-network-builder/release/linux/bin

COPY requirements.txt /var/lib/fabric-network-builder/
RUN pip install -r /var/lib/fabric-network-builder/requirements.txt
RUN pip install --no-cache-dir -r /var/lib/fabric-network-builder/requirements.txt

COPY byfn.sh /var/lib/fabric-network-builder/
COPY template /var/lib/fabric-network-builder/template
Expand Down
31 changes: 24 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ FABRIC_BASE_IMAGE_TAG=$(FABRIC_BASE_VERSION)
FABRIC_CA_IMAGE_TAG=$(FABRIC_CA_VERSION)
FABRIC_IMAGE_NS=hyperledger

DOCKER_IMAGE_TARGET=build/images/${DOCKER_IMAGE}/${VERSION}/.dummy
DOCKER_IMAGE_TARGET=build/images/${DOCKER_IMAGE}/${BUILD_VERSION}${TAG_SUFFIX}/.dummy
DOCKER_MANIFEST_TARGET=build/manifest/${DOCKER_IMAGE}/${BUILD_VERSION}/.dummy

.PHONY: default
default: docker-build
Expand All @@ -26,18 +27,34 @@ docker-build: ${DOCKER_IMAGE_TARGET}

.PHONY: docker-push
docker-push: docker-build
docker push ${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}
docker push ${DOCKER_IMAGE_PUBLIC_FQN}:latest
${DOCKER} push ${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}${TAG_SUFFIX}
${DOCKER} push ${DOCKER_IMAGE_PUBLIC_FQN}:latest

${DOCKER_IMAGE_TARGET}: Dockerfile Makefile
docker build \
${DOCKER} build \
--build-arg FABRIC_VERSION=${FABRIC_VERSION} \
--build-arg FABRIC_CRYPTOGEN_VERSION=${FABRIC_CRYPTOGEN_VERSION} \
--build-arg BASEIMAGETAG=${FABRIC_BASE_IMAGE_TAG} \
--build-arg IMAGETAG=${FABRIC_IMAGE_TAG} \
--build-arg CAIMAGETAG=${FABRIC_CA_IMAGE_TAG} \
--build-arg IMAGENS=${FABRIC_IMAGE_NS} \
-t ${DOCKER_IMAGE} .
docker tag ${DOCKER_IMAGE}:latest ${DOCKER_IMAGE}:${BUILD_VERSION}
mkdir -p $(dir $@)
touch $@
${DOCKER} tag ${DOCKER_IMAGE}:latest ${DOCKER_IMAGE}:${BUILD_VERSION}${TAG_SUFFIX}
${MKDIR_P} $(dir $@)
${TOUCH} $@

.PHONY: push-manifests
push-manifests: ${DOCKER_MANIFEST_TARGET}
@

${DOCKER_MANIFEST_TARGET}:
${DOCKER} buildx imagetools create \
--tag ${DOCKER_IMAGE_PUBLIC_FQN}:latest \
${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}-arm64 \
${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}-amd64
${DOCKER} buildx imagetools create \
--tag ${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION} \
${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}-arm64 \
${DOCKER_IMAGE_PUBLIC_FQN}:${BUILD_VERSION}-amd64
${MKDIR_P} $(dir $@)
${TOUCH} $@
2 changes: 2 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PACKAGE=${PROJECT_PATH}
FQ_DOCKER_IMAGE ?= luthersystems/$(2)
FABRIC_IMAGE_TAG=${FABRIC_VERSION}

TAG_SUFFIX ?= -amd64

DOCKER_IN_DOCKER_MOUNT?=-v /var/run/docker.sock:/var/run/docker.sock

ifeq ($(OS),Windows_NT)
Expand Down

0 comments on commit 452d392

Please sign in to comment.