From 8eb0cb66dc94257cedaa40fa198d7041a11faad3 Mon Sep 17 00:00:00 2001 From: gregnuj Date: Thu, 24 Aug 2023 10:00:12 -0500 Subject: [PATCH] add arch --- .github/workflows/base-build.yml | 8 +-- .github/workflows/docker-build.yml | 17 +++-- .github/workflows/gaia-build.yml | 19 ++--- .github/workflows/terra-build.yml | 19 ++--- alpine.Dockerfile | 11 +-- arch.Dockerfile | 111 +++++++++++++++++++++++++++++ bin/install-wasmvm | 4 +- 7 files changed, 155 insertions(+), 34 deletions(-) create mode 100644 arch.Dockerfile diff --git a/.github/workflows/base-build.yml b/.github/workflows/base-build.yml index 602542f..1b9153f 100644 --- a/.github/workflows/base-build.yml +++ b/.github/workflows/base-build.yml @@ -27,9 +27,8 @@ jobs: matrix: platform: ["linux/amd64", "linux/arm64"] name: ["base"] - os: ["alpine"] - os_version: ["3.16"] - go_version: ["1.20"] + distro: ["alpine", "arch"] + go_version: ["1.20.8"] steps: - name: Checkout @@ -73,12 +72,11 @@ jobs: uses: docker/build-push-action@v4 with: target: ${{ matrix.name }} - file: ${{ matrix.os }}.Dockerfile + file: ${{ matrix.distro }}.Dockerfile platforms: ${{ matrix.platform }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }} labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }} build-args: | GO_VERSION=${{ matrix.go_version }} - OS_VERSION=${{ matrix.os_version }} BUILDPLATFORM=${{ matrix.platform }} diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 7c56d5c..844ebc4 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -40,11 +40,15 @@ on: required: true type: string os: - description: "OS" + description: "Os type linux,darwin etc" required: true type: string - os_version: - description: "Alpine version" + arch: + description: "Architecture" + required: true + type: string + distro: + description: "Linux distribution" required: true type: string platform: @@ -108,18 +112,20 @@ jobs: tags: | type=sha type=raw,value=${{ inputs.version }},enable={{ is_default_branch }} - type=raw,value=${{ inputs.version }}-${{ inputs.os }}${{ inputs.os_version }},enable={{ is_default_branch }} + type=raw,value=${{ inputs.version }}-${{ inputs.distro }}${{ inputs.distro_version }},enable={{ is_default_branch }} - name: Build docker image uses: docker/build-push-action@v4 with: target: ${{ inputs.target }} - file: ./${{ inputs.os }}.Dockerfile + file: ./${{ inputs.distro }}.Dockerfile platforms: ${{ inputs.platform }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }} labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }} build-args: | + OS=${{ inputs.os }} + ARCH=${{ inputs.arch }} APP_NAME=${{ inputs.name }} BIN_NAME=${{ inputs.binary }} BUILD_COMMAND=${{ inputs.build_command }} @@ -132,4 +138,3 @@ jobs: GO_VERSION=${{ inputs.go_version }} LDFLAGS=${{ inputs.ldflags }} MIMALLOC_VERSION=${{ inputs.mimalloc_version }} - OS_VERSION=${{ inputs.os_version }} diff --git a/.github/workflows/gaia-build.yml b/.github/workflows/gaia-build.yml index 3dd63f2..6ee0954 100644 --- a/.github/workflows/gaia-build.yml +++ b/.github/workflows/gaia-build.yml @@ -6,6 +6,7 @@ on: - main paths: - 'bin/builder' + - 'arch.Dockerfile' - 'alpine.Dockerfile' - '.github/workflows/docker-build.yml' - '.github/workflows/gaia-build.yml' @@ -15,6 +16,7 @@ on: - main paths: - 'bin/builder' + - 'arch.Dockerfile' - 'alpine.Dockerfile' - '.github/workflows/docker-build.yml' - '.github/workflows/gaia-build.yml' @@ -24,9 +26,11 @@ jobs: uses: ./.github/workflows/docker-build.yml secrets: inherit strategy: + fail-fast: false matrix: #platform: ["linux/amd64", "linux/arm64"] # need arm runners platform: ["linux/amd64"] + distro: ["alpine", "arch"] version: - 11.0.0 - 10.0.2 @@ -41,20 +45,18 @@ jobs: build_tags: "muslc" chain_registry_name: "cosmos" cosmos_build_options: "nostrip" - go_version: "1.20" - ldflags: "" + go_version: "1.20.8" + ldflags: "-linkmode external -extldflags \"-Wl,-z,muldefs -static\"" mimalloc_version: "" name: "gaia" repo: "cosmos/gaia" target: "prod" - - # Include per os - - os: "alpine" - os_version: "3.16" + os: linux + arch: amd64 # Include per version - version: "9.1.1" - go_version: "1.18" + go_version: "1.18.10" with: name: ${{ matrix.name }} @@ -67,7 +69,8 @@ jobs: ldflags: ${{ matrix.ldflags }} mimalloc_version: ${{ matrix.mimalloc_version }} os: ${{ matrix.os }} - os_version: ${{ matrix.os_version }} + arch: ${{ matrix.arch }} + distro: ${{ matrix.distro }} platform: ${{ matrix.platform }} repo: ${{ matrix.repo }} target: ${{ matrix.target }} diff --git a/.github/workflows/terra-build.yml b/.github/workflows/terra-build.yml index 144f842..2d60a4c 100644 --- a/.github/workflows/terra-build.yml +++ b/.github/workflows/terra-build.yml @@ -6,6 +6,7 @@ on: - main paths: - 'bin/builder' + - 'arch.Dockerfile' - 'alpine.Dockerfile' - '.github/workflows/docker-build.yml' - '.github/workflows/terra-build.yml' @@ -15,6 +16,7 @@ on: - main paths: - 'bin/builder' + - 'arch.Dockerfile' - 'alpine.Dockerfile' - '.github/workflows/docker-build.yml' - '.github/workflows/terra-build.yml' @@ -24,9 +26,11 @@ jobs: uses: ./.github/workflows/docker-build.yml secrets: inherit strategy: + fail-fast: false matrix: #platform: ["linux/amd64", "linux/arm64"] # need arm runners platform: ["linux/amd64"] + distro: ["alpine", "arch"] version: - 2.4.1 - 2.4.0 @@ -40,19 +44,17 @@ jobs: build_tags: "muslc" chain_registry_name: "terra2" cosmos_build_options: "nostrip" - go_version: "1.20" - ldflags: "-extldflags \"-Wl,-z,muldefs -static\"" + go_version: "1.20.8" + ldflags: "-linkmode external -extldflags \"-Wl,-z,muldefs -static\"" mimalloc_version: repo: "terra-money/core" target: "prod" - - # Includes per os - - os: "alpine" - os_version: "3.16" + os: "linux" + arch: "amd64" # Includes per version - version: "2.3.5" - go_version: "1.19" + go_version: "1.19.13" with: binary: ${{ matrix.binary }} @@ -65,7 +67,8 @@ jobs: mimalloc_version: ${{ matrix.mimalloc_version }} name: ${{ matrix.name }} os: ${{ matrix.os }} - os_version: ${{ matrix.os_version }} + arch: ${{ matrix.arch }} + distro: ${{ matrix.distro }} platform: ${{ matrix.platform }} repo: ${{ matrix.repo }} target: ${{ matrix.target }} diff --git a/alpine.Dockerfile b/alpine.Dockerfile index 5c0e306..964d270 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -1,9 +1,8 @@ -ARG GO_VERSION="1.20" -ARG OS_VERESION="3.16" +ARG GO_VERSION="1.20.8" ARG BUILDPLATFORM=linux/amd64 ################################################################################ -FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${OS_VERESION} as base +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine as base # NOTE: add libusb-dev to run with LEDGER_ENABLED=true RUN set -eux &&\ @@ -12,8 +11,10 @@ RUN set -eux &&\ ca-certificates \ linux-headers \ build-base \ + gcompat \ cmake \ bash \ + curl \ git COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/ @@ -29,7 +30,7 @@ ARG COSMOS_BUILD_OPTIONS="nostrip" ARG GIT_TAG="v2.4.1" ARG GIT_REPO="terra-money/core" #ARG LDFLAGS="-extldflags '-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static'" -ARG LDFLAGS='-extldflags "-Wl,-z,muldefs -static"' +ARG LDFLAGS='-linkmode external -extldflags "-Wl,-z,muldefs -static"' ARG MIMALLOC_VERSION ENV MIMALLOC_VERSION=${MIMALLOC_VERSION} @@ -73,7 +74,7 @@ RUN set -eux && \ # (file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked") ################################################################################ -FROM --platform=${BUILDPLATFORM} alpine:${OS_VERESION} as prod +FROM --platform=${BUILDPLATFORM} alpine as prod # build args passed down to env var diff --git a/arch.Dockerfile b/arch.Dockerfile new file mode 100644 index 0000000..ac41d00 --- /dev/null +++ b/arch.Dockerfile @@ -0,0 +1,111 @@ +ARG OS=linux +ARG ARCH=amd64 +ARG BUILDPLATFORM=${OS}/${ARCH} +ARG DISTRO_VERSION="2023091804" +ARG BASE_IMAGE="binhex/arch-base:${DISTRO_VERSION}" + +# ################################################################################ +FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base + +ARG OS +ARG ARCH +ARG GO_VERESION="1.20.8" + +# # NOTE: add libusb-dev to run with LEDGER_ENABLED=true +RUN set -eux & \ + pacman -Syyu --noconfirm linux-headers base-devel glibc git && \ + curl -sSL https://go.dev/dl/go${GO_VERESION}.${OS}-${ARCH}.tar.gz | \ + tar -C / -xz && \ + ln -s /go/bin/go /usr/local/bin/go + +COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/ + +# ################################################################################ +FROM base as builder + +ARG APP_NAME="terra" +ARG BIN_NAME="${APP_NAME}d" +ARG BUILD_COMMAND="make install" +ARG BUILD_TAGS="muslc" +ARG COSMOS_BUILD_OPTIONS="nostrip" +ARG GIT_TAG="v2.4.1" +ARG GIT_REPO="terra-money/core" +# ARG LDFLAGS="-extldflags '-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static'" +ARG LDFLAGS='-extldflags "-Wl,-z,muldefs -static"' +ARG MIMALLOC_VERSION +# ARG MIMALLOC_VERSION="v2.1.2" + +ENV GOPATH=/go/bin +ENV MIMALLOC_VERSION=${MIMALLOC_VERSION} +# install mimalloc if version is specified +RUN set -eux && \ + if [ -n "${MIMALLOC_VERSION}" ]; then install-mimalloc "${MIMALLOC_VERSION}"; fi + +# download dependencies to cache as layer +WORKDIR ${GOPATH}/src/app + +ENV GIT_TAG=${GIT_TAG} \ + GIT_REPO=${GIT_REPO} + +RUN set -eux && \ + git clone -b ${GIT_TAG} https://github.com/${GIT_REPO}.git ./ && \ + go mod download -x + +# download wasmvm if version is specified +RUN set -ux && \ + WASMVM_VERSION="$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2)" && \ + [ -n "${WASMVM_VERSION}" ] && install-wasmvm "${WASMVM_VERSION}" || true + +# build the binary +ENV APP_NAME=${APP_NAME} \ + BUILD_TAGS=${BUILD_TAGS} \ + DENOM=${DENOM} \ + LDFLAGS=${LDFLAGS} \ + LEDGER_ENABLED=false \ + LINK_STATICALLY=true + +RUN set -eux && \ + export COMMIT=GIT_COMMIT="$(git log -1 --format='%h')" && \ + export VERSION=GIT_VERSION="$(git describe --tags --dirty --always)" && \ + export DENOM=${DENOM:-"u$(echo ${APP_NAME} | head -c 4)"} && \ + ${BUILD_COMMAND} + +# verify static binary +RUN set -x && \ + file ${GOPATH}/bin/${BIN_NAME} && \ + echo "Ensuring binary is statically linked ..." && \ + (file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked") + +# ################################################################################ +FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as prod + +# build args passed down to env var + +ARG APP_NAME="terra" +ARG BIN_NAME="${APP_NAME}d" +ARG CHAIN_REGISTRY_NAME + +ENV APP_NAME=${APP_NAME} \ + BIN_NAME=${BIN_NAME} \ + CHAIN_REGISTRY_NAME=${CHAIN_REGISTRY_NAME} + +# copy binary and entrypoint +COPY --from=builder /go/bin/${BIN_NAME} /usr/local/bin/${BIN_NAME} +COPY ./bin/entrypoint.sh /usr/local/bin/ + +# install jq and create user +RUN set -eux && \ + apk update && \ + apk add --no-cache bash curl jq && \ + addgroup -g 1000 ${APP_NAME} && \ + adduser -u 1000 -G ${APP_NAME} -D -s /bin/bash -h /home/${APP_NAME} ${APP_NAME} && \ + ln -s /usr/local/bin/${BIN_NAME} /usr/local/bin/chaind + +# setup execution environment +USER ${APP_NAME} +SHELL [ "/bin/bash" ] +WORKDIR /home/${APP_NAME} +ENTRYPOINT [ "entrypoint.sh" ] +CMD ["chaind", "start"] + + diff --git a/bin/install-wasmvm b/bin/install-wasmvm index 9d55eb6..55f2f22 100755 --- a/bin/install-wasmvm +++ b/bin/install-wasmvm @@ -5,7 +5,7 @@ WASMVM_VERSION="$1" if [ -n "${WASMVM_VERSION}" ]; then WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}" - wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt + curl -o /tmp/checksums.txt ${WASMVM_DOWNLOADS}/checksums.txt ARCH=$(uname -m) if [ ${ARCH} = "amd64" ] || [ ${ARCH} = "x86_64" ]; then WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a" @@ -16,7 +16,7 @@ if [ -n "${WASMVM_VERSION}" ]; then exit 1 fi - wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a + curl -o /lib/libwasmvm_muslc.a ${WASMVM_URL} CHECKSUM=$(sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1) grep ${CHECKSUM} /tmp/checksums.txt rm /tmp/checksums.txt