Skip to content

Commit

Permalink
add arch
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnuj committed Sep 20, 2023
1 parent 5ae071c commit e4318b1
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 30 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/base-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
17 changes: 11 additions & 6 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -132,4 +138,3 @@ jobs:
GO_VERSION=${{ inputs.go_version }}
LDFLAGS=${{ inputs.ldflags }}
MIMALLOC_VERSION=${{ inputs.mimalloc_version }}
OS_VERSION=${{ inputs.os_version }}
15 changes: 9 additions & 6 deletions .github/workflows/gaia-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- 'bin/builder'
- 'arch.Dockerfile'
- 'alpine.Dockerfile'
- '.github/workflows/docker-build.yml'
- '.github/workflows/gaia-build.yml'
Expand All @@ -15,6 +16,7 @@ on:
- main
paths:
- 'bin/builder'
- 'arch.Dockerfile'
- 'alpine.Dockerfile'
- '.github/workflows/docker-build.yml'
- '.github/workflows/gaia-build.yml'
Expand All @@ -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
Expand All @@ -47,14 +51,12 @@ jobs:
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 }}
Expand All @@ -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 }}
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/terra-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- 'bin/builder'
- 'arch.Dockerfile'
- 'alpine.Dockerfile'
- '.github/workflows/docker-build.yml'
- '.github/workflows/terra-build.yml'
Expand All @@ -15,6 +16,7 @@ on:
- main
paths:
- 'bin/builder'
- 'arch.Dockerfile'
- 'alpine.Dockerfile'
- '.github/workflows/docker-build.yml'
- '.github/workflows/terra-build.yml'
Expand All @@ -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
Expand All @@ -45,14 +49,12 @@ jobs:
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 }}
Expand All @@ -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 }}
Expand Down
12 changes: 7 additions & 5 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
ARG GO_VERSION="1.20"
ARG OS_VERESION="3.16"
ARG GO_VERSION="1.20.8"
ARG DISTRO_VERSION="3.18"
ARG BUILDPLATFORM=linux/amd64

################################################################################
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${OS_VERESION} as base
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${DISTRO_VERSION} as base

# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
musl-dev \
build-base \
cmake \
bash \
curl \
git

COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/
Expand All @@ -29,7 +31,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}
Expand Down Expand Up @@ -73,7 +75,7 @@ RUN set -eux && \
# (file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked")

################################################################################
FROM --platform=${BUILDPLATFORM} alpine:${OS_VERESION} as prod
FROM --platform=${BUILDPLATFORM} alpine:${DISTRO_VERSION} as prod

# build args passed down to env var

Expand Down
111 changes: 111 additions & 0 deletions arch.Dockerfile
Original file line number Diff line number Diff line change
@@ -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 cmake git && \
curl -sSL https://go.dev/dl/go${GO_VERESION}.${OS}-${ARCH}.tar.gz | \
tar -C /usr/local -xz && \
ln -s /usr/local/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=/usr/local/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"]


4 changes: 2 additions & 2 deletions bin/install-wasmvm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit e4318b1

Please sign in to comment.