From 5e89045cfdfdce3a05110e1b7120f922edf80e00 Mon Sep 17 00:00:00 2001 From: Chung Wu Date: Mon, 3 Jan 2022 14:58:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Write=20Docker=20image=20build?= =?UTF-8?q?=20process=20into=20Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - Dockerfile | 36 ++++++++++-------------------------- Makefile | 15 ++++++++++++--- build.sh | 13 ------------- 4 files changed, 22 insertions(+), 43 deletions(-) delete mode 100755 build.sh diff --git a/.dockerignore b/.dockerignore index f3aac7c12d..75e677a715 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -.git .liked .likecli Dockerfile diff --git a/Dockerfile b/Dockerfile index ce231986b7..5bf0721443 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,17 @@ -FROM golang:1.16-buster as base +FROM likecoin/rbuilder:latest as builder -WORKDIR / -RUN mkdir -p ./likechain -COPY ./go.mod ./likechain/go.mod -COPY ./go.sum ./likechain/go.sum -WORKDIR /likechain -RUN go mod download - - -FROM base as builder - -WORKDIR /likechain -COPY . . -ARG VERSION="fotan-1" -ARG COMMIT="" -RUN go build \ - -ldflags "\ - -X \"github.com/cosmos/cosmos-sdk/version.Name=likecoin-chain\" \ - -X \"github.com/cosmos/cosmos-sdk/version.AppName=liked\" \ - -X \"github.com/cosmos/cosmos-sdk/version.BuildTags=netgo ledger\" \ - -X \"github.com/cosmos/cosmos-sdk/version.Version=${VERSION}\" \ - -X \"github.com/cosmos/cosmos-sdk/version.Commit=${COMMIT}\" \ - " \ - -tags "netgo ledger" \ - -o /go/bin/liked cmd/liked/main.go +COPY . /sources +ARG VERSION +ARG COMMIT +WORKDIR /sources +ENV TARGET_PLATFORMS='linux/amd64' +ENV APP='liked' +ENV LEDGER_ENABLED=true +RUN /bin/bash -c /sources/.build.sh FROM debian:buster WORKDIR /usr/bin RUN apt-get update && apt-get install -y curl -COPY --from=builder /go/bin/liked . +COPY --from=builder /sources/artifacts/liked-*-linux-amd64 /usr/bin/liked diff --git a/Makefile b/Makefile index 1c21dc33df..16e34c0bf7 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,10 @@ NAME := likecoin-chain APP := liked VERSION := $(shell git describe --tags) -COMMIT=$(shell git rev-parse HEAD) +COMMIT := $(shell git rev-parse HEAD) LEDGER_ENABLED ?= true DOCKER := $(shell which docker) +IMAGE_TAG = likecoin/likecoin-chain:$(VERSION) BUILDDIR ?= $(CURDIR)/build export GO111MODULE = on @@ -94,6 +95,14 @@ build-reproducible: go.sum --name latest-build likecoin/rbuilder:latest $(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/ +build-docker: go.sum + echo "Building image for $(VERSION) using commit $(COMMIT)" + $(DOCKER) build \ + --build-arg VERSION=$(VERSION) \ + --build-arg COMMIT=$(COMMIT) \ + --tag $(IMAGE_TAG) \ + . + build: go.sum $(BUILDDIR)/ go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./... @@ -101,9 +110,9 @@ install: go.sum $(BUILDDIR)/ go install -mod=readonly $(BUILD_FLAGS) ./... test: - go test -v ./x/... + go test -v ./... clean: rm -rf $(BUILDDIR)/ artifacts/ -.PHONY: go-mod-cache build-reproducible build install test clean +.PHONY: go-mod-cache build-reproducible build-docker build install test clean diff --git a/build.sh b/build.sh deleted file mode 100755 index 74f73bd58f..0000000000 --- a/build.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -e - -pushd "$(dirname "$0")" > /dev/null - -VERSION="fotan-1.1" -COMMIT=$(git rev-parse HEAD) - -echo "Building image for $VERSION using commit $COMMIT" -docker build --build-arg "VERSION=$VERSION" --build-arg "COMMIT=$COMMIT" -t "likecoin/likecoin-chain:$VERSION" . - -popd > /dev/null