Skip to content

Commit

Permalink
add arch
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnuj committed Sep 21, 2023
1 parent 5ae071c commit 8406ab2
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 45 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 }}
19 changes: 11 additions & 8 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 @@ -41,20 +45,18 @@ jobs:
build_tags: "muslc"
chain_registry_name: "cosmos"
cosmos_build_options: "nostrip"
go_version: "1.20"
ldflags: ""
mimalloc_version: ""
go_version: "1.20.8"
name: "gaia"
repo: "cosmos/gaia"
target: "prod"

# Include per os
- os: "alpine"
os_version: "3.16"
os: linux
arch: amd64
ldflags: "-linkmode external -extldflags \"-Wl,-z,muldefs -static\""

# 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
28 changes: 18 additions & 10 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,13 +26,15 @@ 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
- 2.3.5
- "2.4.1"
- "2.4.0"
- "2.3.5"

include:
# Include Defaults (keep at top)
Expand All @@ -40,19 +44,22 @@ 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"
mimalloc_version:
repo: "terra-money/core"
target: "prod"
os: "linux"
arch: "amd64"

# Includes per os
- os: "alpine"
os_version: "3.16"
- distro: alpine
ldflags: "-linkmode external -extldflags \"-Wl,-z,muldefs -static\""

- distro: arch
ldflags: ""

# Includes per version
- version: "2.3.5"
go_version: "1.19"
go_version: "1.19.13"

with:
binary: ${{ matrix.binary }}
Expand All @@ -65,7 +72,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
29 changes: 15 additions & 14 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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 &&\
RUN set -eu &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
build-base \
gcompat \
cmake \
bash \
curl \
git

COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/
Expand All @@ -29,12 +30,12 @@ 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}
# install mimalloc if version is specified
RUN set -eux && \
RUN set -eu && \
if [ -n "${MIMALLOC_VERSION}" ]; then install-mimalloc "${MIMALLOC_VERSION}"; fi

# download dependencies to cache as layer
Expand All @@ -43,12 +44,12 @@ WORKDIR ${GOPATH}/src/app
ENV GIT_TAG=${GIT_TAG} \
GIT_REPO=${GIT_REPO}

RUN set -eux && \
RUN set -eu && \
git clone -b ${GIT_TAG} https://github.com/${GIT_REPO}.git ./ && \
go mod download -x
go mod download -x > /dev/null

# download wasmvm if version is specified
RUN set -ux && \
RUN set -u && \
WASMVM_VERSION="$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2)" && \
[ -n "${WASMVM_VERSION}" ] && install-wasmvm "${WASMVM_VERSION}" || true

Expand All @@ -67,13 +68,13 @@ RUN set -eux && \
${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")
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} alpine:${OS_VERESION} as prod
FROM --platform=${BUILDPLATFORM} alpine:3.18 as prod

# build args passed down to env var

Expand Down
110 changes: 110 additions & 0 deletions arch.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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_VERSION="1.20.8"

# # NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eu & \
pacman -Syyu --noconfirm linux-headers base-devel glibc git && \
curl -sSL https://go.dev/dl/go${GO_VERSION}.${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
ENV MIMALLOC_VERSION=${MIMALLOC_VERSION}
# install mimalloc if version is specified
RUN set -eu && \
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 -eu && \
git clone -b ${GIT_TAG} https://github.com/${GIT_REPO}.git ./ && \
go mod download -x > /dev/null

# download wasmvm if version is specified
RUN set -u && \
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 && \
pacman -Syyu --noconfirm jq && \
groupadd -g 1000 ${APP_NAME} && \
useradd -u 1000 -g ${APP_NAME} -s /bin/bash -d /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"]


Loading

0 comments on commit 8406ab2

Please sign in to comment.