Skip to content

Commit

Permalink
Sync Docker build process on v0.34.x with main (#293)
Browse files Browse the repository at this point in the history
* Sync Docker build process on v0.34.x with main

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Remove reference to previous name of workflow

Signed-off-by: Thane Thomson <connect@thanethomson.com>

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson authored Feb 10, 2023
1 parent fd15b98 commit 68bcd3d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/cometbft-docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker
# Build & Push rebuilds the CometBFT docker image on every push to main and creation of tags
# Rebuilds the CometBFT docker image on every push to main and creation of tags
# and pushes the image to https://hub.docker.com/r/cometbft/cometbft
on:
push:
Expand All @@ -12,7 +12,6 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" # e.g. v0.37.0-beta.1, v0.38.0-beta.10
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" # e.g. v0.37.0-rc1, v0.38.0-rc10


jobs:
build:
runs-on: ubuntu-latest
Expand Down
17 changes: 9 additions & 8 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Use a build arg to ensure that both stages use the same,
# hopefully current, go version.
ARG GOLANG_BASE_IMAGE=golang:1.18-alpine

# stage 1 Generate CometBFT Binary
FROM golang:1.18-alpine as builder
FROM --platform=$BUILDPLATFORM $GOLANG_BASE_IMAGE as builder
RUN apk update && \
apk upgrade && \
apk --no-cache add make git
apk --no-cache add make git
COPY / /cometbft
WORKDIR /cometbft
RUN make build-linux

# stage 2
FROM golang:1.18-alpine


RUN TARGETPLATFORM=$TARGETPLATFORM make build-linux

# stage 2
FROM $GOLANG_BASE_IMAGE
LABEL maintainer="hello@informal.systems"


# CometBFT will be looking for the genesis file in /cometbft/config/genesis.json
# (unless you change `genesis_file` in config.toml). You can put your config.toml and
# private validator file into /cometbft/config.
Expand Down
76 changes: 70 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PACKAGES=$(shell go list ./...)
OUTPUT?=build/cometbft
BUILDDIR?=$(CURDIR)/build
OUTPUT?=$(BUILDDIR)/cometbft

BUILD_TAGS?=cometbft

COMMIT_HASH := $(shell git rev-parse --short HEAD)

LD_FLAGS = -X github.com/cometbft/cometbft/version.TMGitCommitHash=$(COMMIT_HASH)
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
HTTPS_GIT := https://github.com/cometbft/cometbft.git
Expand Down Expand Up @@ -47,6 +47,67 @@ endif
# allow users to pass additional flags via the conventional LDFLAGS variable
LD_FLAGS += $(LDFLAGS)

# Process Docker environment varible TARGETPLATFORM
# in order to build binary with correspondent ARCH
# by default will always build for linux/amd64
TARGETPLATFORM ?=
GOOS ?= linux
GOARCH ?= amd64
GOARM ?=

ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm
GOARM=7
endif

ifeq (linux/arm/v6,$(findstring linux/arm/v6,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm
GOARM=6
endif

ifeq (linux/arm64,$(findstring linux/arm64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm64
GOARM=7
endif

ifeq (linux/386,$(findstring linux/386,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=386
endif

ifeq (linux/amd64,$(findstring linux/amd64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=amd64
endif

ifeq (linux/mips,$(findstring linux/mips,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips
endif

ifeq (linux/mipsle,$(findstring linux/mipsle,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mipsle
endif

ifeq (linux/mips64,$(findstring linux/mips64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips64
endif

ifeq (linux/mips64le,$(findstring linux/mips64le,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips64le
endif

ifeq (linux/riscv64,$(findstring linux/riscv64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=riscv64
endif

all: check build test install
.PHONY: all

Expand Down Expand Up @@ -218,10 +279,13 @@ check-docs-toc:
### Docker image ###
###############################################################################

build-docker: build-linux
cp $(OUTPUT) DOCKER/cometbft
docker build --label=cometbft --tag="cometbft/cometbft" --progress=plain DOCKER --no-cache
rm -rf DOCKER/cometbft
# On Linux, you may need to run `DOCKER_BUILDKIT=1 make build-docker` for this
# to work.
build-docker:
docker build \
--label=cometbft \
--tag="cometbft/cometbft" \
-f DOCKER/Dockerfile .
.PHONY: build-docker

###############################################################################
Expand Down

0 comments on commit 68bcd3d

Please sign in to comment.