Skip to content

Commit 54757dc

Browse files
author
gregnuj
committed
add arch
1 parent 5ae071c commit 54757dc

File tree

7 files changed

+154
-33
lines changed

7 files changed

+154
-33
lines changed

.github/workflows/base-build.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ jobs:
2727
matrix:
2828
platform: ["linux/amd64", "linux/arm64"]
2929
name: ["base"]
30-
os: ["alpine"]
31-
os_version: ["3.16"]
32-
go_version: ["1.20"]
30+
distro: ["alpine", "arch"]
31+
go_version: ["1.20.8"]
3332

3433
steps:
3534
- name: Checkout
@@ -73,12 +72,11 @@ jobs:
7372
uses: docker/build-push-action@v4
7473
with:
7574
target: ${{ matrix.name }}
76-
file: ${{ matrix.os }}.Dockerfile
75+
file: ${{ matrix.distro }}.Dockerfile
7776
platforms: ${{ matrix.platform }}
7877
push: ${{ github.event_name != 'pull_request' }}
7978
tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
8079
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
8180
build-args: |
8281
GO_VERSION=${{ matrix.go_version }}
83-
OS_VERSION=${{ matrix.os_version }}
8482
BUILDPLATFORM=${{ matrix.platform }}

.github/workflows/docker-build.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ on:
4040
required: true
4141
type: string
4242
os:
43-
description: "OS"
43+
description: "Os type linux,darwin etc"
4444
required: true
4545
type: string
46-
os_version:
47-
description: "Alpine version"
46+
arch:
47+
description: "Architecture"
48+
required: true
49+
type: string
50+
distro:
51+
description: "Linux distribution"
4852
required: true
4953
type: string
5054
platform:
@@ -108,18 +112,20 @@ jobs:
108112
tags: |
109113
type=sha
110114
type=raw,value=${{ inputs.version }},enable={{ is_default_branch }}
111-
type=raw,value=${{ inputs.version }}-${{ inputs.os }}${{ inputs.os_version }},enable={{ is_default_branch }}
115+
type=raw,value=${{ inputs.version }}-${{ inputs.distro }}${{ inputs.distro_version }},enable={{ is_default_branch }}
112116
113117
- name: Build docker image
114118
uses: docker/build-push-action@v4
115119
with:
116120
target: ${{ inputs.target }}
117-
file: ./${{ inputs.os }}.Dockerfile
121+
file: ./${{ inputs.distro }}.Dockerfile
118122
platforms: ${{ inputs.platform }}
119123
push: ${{ github.event_name != 'pull_request' }}
120124
tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
121125
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
122126
build-args: |
127+
OS=${{ inputs.os }}
128+
ARCH=${{ inputs.arch }}
123129
APP_NAME=${{ inputs.name }}
124130
BIN_NAME=${{ inputs.binary }}
125131
BUILD_COMMAND=${{ inputs.build_command }}
@@ -132,4 +138,3 @@ jobs:
132138
GO_VERSION=${{ inputs.go_version }}
133139
LDFLAGS=${{ inputs.ldflags }}
134140
MIMALLOC_VERSION=${{ inputs.mimalloc_version }}
135-
OS_VERSION=${{ inputs.os_version }}

.github/workflows/gaia-build.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
paths:
88
- 'bin/builder'
9+
- 'arch.Dockerfile'
910
- 'alpine.Dockerfile'
1011
- '.github/workflows/docker-build.yml'
1112
- '.github/workflows/gaia-build.yml'
@@ -15,6 +16,7 @@ on:
1516
- main
1617
paths:
1718
- 'bin/builder'
19+
- 'arch.Dockerfile'
1820
- 'alpine.Dockerfile'
1921
- '.github/workflows/docker-build.yml'
2022
- '.github/workflows/gaia-build.yml'
@@ -24,9 +26,11 @@ jobs:
2426
uses: ./.github/workflows/docker-build.yml
2527
secrets: inherit
2628
strategy:
29+
fail-fast: false
2730
matrix:
2831
#platform: ["linux/amd64", "linux/arm64"] # need arm runners
2932
platform: ["linux/amd64"]
33+
distro: ["alpine", "arch"]
3034
version:
3135
- 11.0.0
3236
- 10.0.2
@@ -41,20 +45,18 @@ jobs:
4145
build_tags: "muslc"
4246
chain_registry_name: "cosmos"
4347
cosmos_build_options: "nostrip"
44-
go_version: "1.20"
45-
ldflags: ""
48+
go_version: "1.20.8"
49+
ldflags: "-extldflags \"-static\""
4650
mimalloc_version: ""
4751
name: "gaia"
4852
repo: "cosmos/gaia"
4953
target: "prod"
50-
51-
# Include per os
52-
- os: "alpine"
53-
os_version: "3.16"
54+
os: linux
55+
arch: amd64
5456

5557
# Include per version
5658
- version: "9.1.1"
57-
go_version: "1.18"
59+
go_version: "1.18.10"
5860

5961
with:
6062
name: ${{ matrix.name }}
@@ -67,7 +69,8 @@ jobs:
6769
ldflags: ${{ matrix.ldflags }}
6870
mimalloc_version: ${{ matrix.mimalloc_version }}
6971
os: ${{ matrix.os }}
70-
os_version: ${{ matrix.os_version }}
72+
arch: ${{ matrix.arch }}
73+
distro: ${{ matrix.distro }}
7174
platform: ${{ matrix.platform }}
7275
repo: ${{ matrix.repo }}
7376
target: ${{ matrix.target }}

.github/workflows/terra-build.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
paths:
88
- 'bin/builder'
9+
- 'arch.Dockerfile'
910
- 'alpine.Dockerfile'
1011
- '.github/workflows/docker-build.yml'
1112
- '.github/workflows/terra-build.yml'
@@ -15,6 +16,7 @@ on:
1516
- main
1617
paths:
1718
- 'bin/builder'
19+
- 'arch.Dockerfile'
1820
- 'alpine.Dockerfile'
1921
- '.github/workflows/docker-build.yml'
2022
- '.github/workflows/terra-build.yml'
@@ -24,9 +26,11 @@ jobs:
2426
uses: ./.github/workflows/docker-build.yml
2527
secrets: inherit
2628
strategy:
29+
fail-fast: false
2730
matrix:
2831
#platform: ["linux/amd64", "linux/arm64"] # need arm runners
2932
platform: ["linux/amd64"]
33+
distro: ["alpine", "arch"]
3034
version:
3135
- 2.4.1
3236
- 2.4.0
@@ -40,19 +44,17 @@ jobs:
4044
build_tags: "muslc"
4145
chain_registry_name: "terra2"
4246
cosmos_build_options: "nostrip"
43-
go_version: "1.20"
47+
go_version: "1.20.8"
4448
ldflags: "-extldflags \"-Wl,-z,muldefs -static\""
4549
mimalloc_version:
4650
repo: "terra-money/core"
4751
target: "prod"
48-
49-
# Includes per os
50-
- os: "alpine"
51-
os_version: "3.16"
52+
os: "linux"
53+
arch: "amd64"
5254

5355
# Includes per version
5456
- version: "2.3.5"
55-
go_version: "1.19"
57+
go_version: "1.19.13"
5658

5759
with:
5860
binary: ${{ matrix.binary }}
@@ -65,7 +67,8 @@ jobs:
6567
mimalloc_version: ${{ matrix.mimalloc_version }}
6668
name: ${{ matrix.name }}
6769
os: ${{ matrix.os }}
68-
os_version: ${{ matrix.os_version }}
70+
arch: ${{ matrix.arch }}
71+
distro: ${{ matrix.distro }}
6972
platform: ${{ matrix.platform }}
7073
repo: ${{ matrix.repo }}
7174
target: ${{ matrix.target }}

alpine.Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
ARG GO_VERSION="1.20"
2-
ARG OS_VERESION="3.16"
1+
ARG GO_VERSION="1.20.8"
32
ARG BUILDPLATFORM=linux/amd64
43

54
################################################################################
6-
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${OS_VERESION} as base
5+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine as base
76

87
# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
98
RUN set -eux &&\
@@ -12,8 +11,10 @@ RUN set -eux &&\
1211
ca-certificates \
1312
linux-headers \
1413
build-base \
14+
gcompat \
1515
cmake \
1616
bash \
17+
curl \
1718
git
1819

1920
COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/
@@ -29,7 +30,7 @@ ARG COSMOS_BUILD_OPTIONS="nostrip"
2930
ARG GIT_TAG="v2.4.1"
3031
ARG GIT_REPO="terra-money/core"
3132
#ARG LDFLAGS="-extldflags '-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static'"
32-
ARG LDFLAGS='-extldflags "-Wl,-z,muldefs -static"'
33+
ARG LDFLAGS='-linkmode external -extldflags "-Wl,-z,muldefs -static"'
3334
ARG MIMALLOC_VERSION
3435

3536
ENV MIMALLOC_VERSION=${MIMALLOC_VERSION}
@@ -73,7 +74,7 @@ RUN set -eux && \
7374
# (file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked")
7475

7576
################################################################################
76-
FROM --platform=${BUILDPLATFORM} alpine:${OS_VERESION} as prod
77+
FROM --platform=${BUILDPLATFORM} alpine as prod
7778

7879
# build args passed down to env var
7980

arch.Dockerfile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
ARG OS=linux
2+
ARG ARCH=amd64
3+
ARG BUILDPLATFORM=${OS}/${ARCH}
4+
ARG DISTRO_VERSION="2023091804"
5+
ARG BASE_IMAGE="binhex/arch-base:${DISTRO_VERSION}"
6+
7+
# ################################################################################
8+
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base
9+
10+
ARG OS
11+
ARG ARCH
12+
ARG GO_VERESION="1.20.8"
13+
14+
# # NOTE: add libusb-dev to run with LEDGER_ENABLED=true
15+
RUN set -eux & \
16+
pacman -Syyu --noconfirm linux-headers base-devel glibc git && \
17+
curl -sSL https://go.dev/dl/go${GO_VERESION}.${OS}-${ARCH}.tar.gz | \
18+
tar -C /usr/local -xz && \
19+
ln -s /usr/local/go/bin/go /usr/local/bin/go
20+
21+
COPY ./bin/install-mimalloc ./bin/install-wasmvm /usr/local/bin/
22+
23+
# ################################################################################
24+
FROM base as builder
25+
26+
ARG APP_NAME="terra"
27+
ARG BIN_NAME="${APP_NAME}d"
28+
ARG BUILD_COMMAND="make install"
29+
ARG BUILD_TAGS="muslc"
30+
ARG COSMOS_BUILD_OPTIONS="nostrip"
31+
ARG GIT_TAG="v2.4.1"
32+
ARG GIT_REPO="terra-money/core"
33+
# ARG LDFLAGS="-extldflags '-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static'"
34+
ARG LDFLAGS='-extldflags "-Wl,-z,muldefs -static"'
35+
ARG MIMALLOC_VERSION
36+
# ARG MIMALLOC_VERSION="v2.1.2"
37+
38+
ENV GOPATH=/usr/local/go/bin
39+
ENV MIMALLOC_VERSION=${MIMALLOC_VERSION}
40+
# install mimalloc if version is specified
41+
RUN set -eux && \
42+
if [ -n "${MIMALLOC_VERSION}" ]; then install-mimalloc "${MIMALLOC_VERSION}"; fi
43+
44+
# download dependencies to cache as layer
45+
WORKDIR ${GOPATH}/src/app
46+
47+
ENV GIT_TAG=${GIT_TAG} \
48+
GIT_REPO=${GIT_REPO}
49+
50+
RUN set -eux && \
51+
git clone -b ${GIT_TAG} https://github.com/${GIT_REPO}.git ./ && \
52+
go mod download -x
53+
54+
# download wasmvm if version is specified
55+
RUN set -ux && \
56+
WASMVM_VERSION="$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2)" && \
57+
[ -n "${WASMVM_VERSION}" ] && install-wasmvm "${WASMVM_VERSION}" || true
58+
59+
# build the binary
60+
ENV APP_NAME=${APP_NAME} \
61+
BUILD_TAGS=${BUILD_TAGS} \
62+
DENOM=${DENOM} \
63+
LDFLAGS=${LDFLAGS} \
64+
LEDGER_ENABLED=false \
65+
LINK_STATICALLY=true
66+
67+
RUN set -eux && \
68+
export COMMIT=GIT_COMMIT="$(git log -1 --format='%h')" && \
69+
export VERSION=GIT_VERSION="$(git describe --tags --dirty --always)" && \
70+
export DENOM=${DENOM:-"u$(echo ${APP_NAME} | head -c 4)"} && \
71+
${BUILD_COMMAND}
72+
73+
# verify static binary
74+
RUN set -x && \
75+
file ${GOPATH}/bin/${BIN_NAME} && \
76+
echo "Ensuring binary is statically linked ..." && \
77+
(file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked")
78+
79+
# ################################################################################
80+
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as prod
81+
82+
# build args passed down to env var
83+
84+
ARG APP_NAME="terra"
85+
ARG BIN_NAME="${APP_NAME}d"
86+
ARG CHAIN_REGISTRY_NAME
87+
88+
ENV APP_NAME=${APP_NAME} \
89+
BIN_NAME=${BIN_NAME} \
90+
CHAIN_REGISTRY_NAME=${CHAIN_REGISTRY_NAME}
91+
92+
# copy binary and entrypoint
93+
COPY --from=builder /go/bin/${BIN_NAME} /usr/local/bin/${BIN_NAME}
94+
COPY ./bin/entrypoint.sh /usr/local/bin/
95+
96+
# install jq and create user
97+
RUN set -eux && \
98+
apk update && \
99+
apk add --no-cache bash curl jq && \
100+
addgroup -g 1000 ${APP_NAME} && \
101+
adduser -u 1000 -G ${APP_NAME} -D -s /bin/bash -h /home/${APP_NAME} ${APP_NAME} && \
102+
ln -s /usr/local/bin/${BIN_NAME} /usr/local/bin/chaind
103+
104+
# setup execution environment
105+
USER ${APP_NAME}
106+
SHELL [ "/bin/bash" ]
107+
WORKDIR /home/${APP_NAME}
108+
ENTRYPOINT [ "entrypoint.sh" ]
109+
CMD ["chaind", "start"]
110+
111+

bin/install-wasmvm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WASMVM_VERSION="$1"
55

66
if [ -n "${WASMVM_VERSION}" ]; then
77
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"
8-
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt
8+
curl -o /tmp/checksums.txt ${WASMVM_DOWNLOADS}/checksums.txt
99
ARCH=$(uname -m)
1010
if [ ${ARCH} = "amd64" ] || [ ${ARCH} = "x86_64" ]; then
1111
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"
@@ -16,7 +16,7 @@ if [ -n "${WASMVM_VERSION}" ]; then
1616
exit 1
1717
fi
1818

19-
wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a
19+
curl -o /lib/libwasmvm_muslc.a ${WASMVM_URL}
2020
CHECKSUM=$(sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1)
2121
grep ${CHECKSUM} /tmp/checksums.txt
2222
rm /tmp/checksums.txt

0 commit comments

Comments
 (0)