Skip to content

Commit 6f54c1c

Browse files
committed
feat: add to linux binary in release
1 parent 4b0c5ce commit 6f54c1c

6 files changed

+181
-71
lines changed

.github/release-drafter-config.yaml

-37
This file was deleted.

.github/workflows/integration-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@v3
2626
with:
27-
go-version: 1.18.x
27+
go-version: 1.19.x
2828

2929
- name: End-to-end test
3030
run: cd tests/e2e && go test

.github/workflows/release-drafter.yaml

-13
This file was deleted.

.github/workflows/release.yaml

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: "Release"
2+
3+
on:
4+
# can be used to re-release an existing tag
5+
workflow_dispatch:
6+
7+
push:
8+
tags:
9+
- "v[0-9]+\\.[0-9]+\\.[0-9]+"
10+
- "v[0-9]+\\.[0-9]+\\.[0-9]+-*"
11+
12+
jobs:
13+
release:
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
if: startsWith(github.ref, 'refs/tags/')
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Create release for ${{ github.ref_name }}
20+
run: gh release create ${{ github.ref_name }} --prerelease --generate-notes --repo ${{ github.repository }}
21+
22+
23+
artifacts:
24+
if: startsWith(github.ref, 'refs/tags/')
25+
needs: release
26+
runs-on: ubuntu-latest
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
strategy:
30+
matrix:
31+
build_type: ['build-release-arm64', 'build-release-amd64']
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
- name: Set version tag
36+
run: echo "VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_ENV
37+
- name: Create build directory
38+
run: mkdir -p build/release
39+
- name: Build ${{ matrix.build_type }}
40+
run: make ${{ matrix.build_type }}
41+
- name: Upload the artifacts to release
42+
run: gh release upload ${{ github.ref_name }} ./build/release/*
43+
44+
calculate-checksums:
45+
needs: artifacts
46+
env:
47+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
if: startsWith(github.ref, 'refs/tags/')
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Create build directory
52+
run: mkdir -p build/release
53+
- name: Download artifacts
54+
run: gh release download ${{ github.ref_name }} --pattern '*.tar.gz' --dir build/release --repo ${{ github.repository }}
55+
- name: Create checksums
56+
run: |
57+
cd build/release
58+
sha256sum *.tar.gz > checksum.txt
59+
- name: Display checksums
60+
run: cat build/release/checksum.txt
61+
- name: Upload the checksum to release
62+
run: gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}}
63+
64+
generate-json:
65+
needs: calculate-checksums
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
if: startsWith(github.ref, 'refs/tags/')
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Install jq
72+
run: sudo apt-get update && sudo apt-get install -y jq
73+
- name: Create build directory
74+
run: mkdir -p build/release
75+
- name: Download artifacts
76+
run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}}
77+
- name: Generate JSON file
78+
run: |
79+
cd build/release
80+
binaries=()
81+
for file in *.tar.gz; do
82+
checksum=$(sha256sum $file | awk '{print $1}')
83+
url="https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/$file?checksum=sha256:$checksum"
84+
declare -A TRANSLATION_MATRIX
85+
TRANSLATION_MATRIX=( ["Linux_x86_64"]="linux/amd64" ["Linux_arm64"]="linux/arm64" ["Darwin_arm64"]="darwin/arm64" )
86+
os_architecture_translated=""
87+
for key in "${!TRANSLATION_MATRIX[@]}"; do
88+
if [[ "$file" == *"$key"* ]]; then
89+
os_architecture_translated="${TRANSLATION_MATRIX[$key]}"
90+
break
91+
fi
92+
done
93+
if [ -z "$os_architecture_translated" ]
94+
then
95+
echo "Could not translate OS and architecture information from binary name: $file"
96+
exit 1
97+
fi
98+
binaries+=(" \"$os_architecture_translated\": \"$url\"")
99+
done
100+
binaries_json=$(IFS=$',\n'; echo "${binaries[*]}")
101+
cat << EOF > binaries.json.raw
102+
{
103+
"binaries": {
104+
$binaries_json
105+
}
106+
}
107+
EOF
108+
109+
- name: Pretty-print JSON file using jq
110+
run: |
111+
cd build/release
112+
jq . < binaries.json.raw > binaries.json && rm binaries.json.raw
113+
114+
- name: Display JSON file
115+
run: cat build/release/binaries.json
116+
- name: Upload the JSON file to release
117+
run: gh release upload ${{ github.ref_name }} build/release/binaries.json --repo ${{ github.repository }}

Dockerfile

+16-20
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,37 @@
88

99
### BUILD
1010
FROM golang:1.19-alpine AS build
11-
WORKDIR /localnet
1211

1312
# Create appuser.
1413
RUN adduser -D -g '' valiuser
1514
# Install required binaries
1615
RUN apk add --update --no-cache zip git make cmake build-base linux-headers musl-dev libc-dev
1716

18-
# Copy source files
19-
COPY . /localnet/
20-
21-
ENV LIBWASMVM_VERSION=v1.3.0
22-
17+
WORKDIR /
2318
RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
2419
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4
2520

26-
# See https://github.com/CosmWasm/wasmvm/releases
27-
ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASMVM_VERSION}/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
28-
ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASMVM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
29-
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep b1610f9c8ad8bdebf5b8f819f71d238466f83521c74a2deb799078932e862722
30-
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep b4aad4480f9b4c46635b4943beedbb72c929eab1d1b9467fe3b43e6dbf617e32
3121

32-
# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
33-
RUN cp /lib/libwasmvm_muslc.`uname -m`.a /lib/libwasmvm_muslc.a
22+
WORKDIR /workspace
23+
# Copy source files
24+
COPY . .
25+
# Download dependencies and CosmWasm libwasmvm if found.
26+
RUN set -eux; \
27+
export ARCH=$(uname -m); \
28+
WASM_VERSION=$(go list -mod=readonly -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
29+
if [ ! -z "${WASM_VERSION}" ]; then \
30+
wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
31+
fi; \
32+
go mod download;
3433

3534
# Build executable
36-
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-L/localnet/mimalloc/build -lmimalloc -Wl,-z,muldefs -static"' make build
35+
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-L/mimalloc/build -lmimalloc -Wl,-z,muldefs -static"' make build
3736

3837
# --------------------------------------------------------
39-
FROM alpine:3.15 AS runtime
40-
41-
WORKDIR /opt
42-
RUN [ "mkdir", "-p", "/opt/tests/integration" ]
38+
FROM alpine:3.18 AS runtime
4339

44-
COPY --from=build /localnet/build/xplad /usr/bin/xplad
45-
COPY --from=build /localnet/tests/e2e /opt/tests/e2e
40+
COPY --from=build /workspace/build/xplad /usr/bin/xplad
41+
COPY --from=build /workspace/tests/e2e /opt/tests/e2e
4642

4743
# Expose Cosmos ports
4844
EXPOSE 9090

Makefile

+47
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ NAME := xpla
1616
APPNAME := xplad
1717
LEDGER_ENABLED ?= true
1818
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7"
19+
BUILDDIR ?= $(CURDIR)/build
20+
GO_VERSION ?= "1.19"
1921

2022
# for dockerized protobuf tools
2123
DOCKER := $(shell which docker)
24+
DOCKER_COMPOSE := $(shell which docker-compose)
2225
BUF_IMAGE=bufbuild/buf@sha256:3cb1f8a4b48bd5ad8f09168f10f607ddc318af202f5c057d52a45216793d85e5 #v1.4.0
2326
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(BUF_IMAGE)
2427

@@ -87,12 +90,56 @@ endif
8790

8891
all: install
8992

93+
.PHONY: install
9094
install: go.sum
9195
go install -mod=readonly $(BUILD_FLAGS) ./cmd/xplad
9296

97+
.PHONY: build
9398
build: go.sum
9499
go build -mod=readonly $(BUILD_FLAGS) -o build/xplad ./cmd/xplad
95100

101+
build-release: build/linux/amd64 build/linux/arm64
102+
103+
build-release-amd64: go.sum $(BUILDDIR)/
104+
$(DOCKER) buildx create --name xpla-builder || true
105+
$(DOCKER) buildx use xpla-builder
106+
$(DOCKER) buildx build \
107+
--build-arg GO_VERSION=$(GO_VERSION) \
108+
--build-arg GIT_VERSION=$(VERSION) \
109+
--build-arg GIT_COMMIT=$(COMMIT) \
110+
--build-arg GOOS=linux \
111+
--build-arg GOARCH=amd64 \
112+
--platform linux/amd64 \
113+
-t xpla:local-amd64 \
114+
--load \
115+
-f Dockerfile .
116+
$(DOCKER) rm -f xpla-builder || true
117+
$(DOCKER) create -ti --name xpla-builder xpla:local-amd64
118+
$(DOCKER) cp xpla-builder:/usr/bin/xplad $(BUILDDIR)/release/xplad
119+
tar -czvf $(BUILDDIR)/release/xpla_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ xplad
120+
rm $(BUILDDIR)/release/xplad
121+
$(DOCKER) rm -f xpla-builder
122+
123+
build-release-arm64: go.sum $(BUILDDIR)/
124+
$(DOCKER) buildx create --name xpla-builder || true
125+
$(DOCKER) buildx use xpla-builder
126+
$(DOCKER) buildx build \
127+
--build-arg GO_VERSION=$(GO_VERSION) \
128+
--build-arg GIT_VERSION=$(VERSION) \
129+
--build-arg GIT_COMMIT=$(COMMIT) \
130+
--build-arg GOOS=linux \
131+
--build-arg GOARCH=arm64 \
132+
--platform linux/arm64 \
133+
-t xpla:local-arm64 \
134+
--load \
135+
-f Dockerfile .
136+
$(DOCKER) rm -f xpla-builder || true
137+
$(DOCKER) create -ti --name xpla-builder xpla:local-arm64
138+
$(DOCKER) cp xpla-builder:/usr/bin/xplad $(BUILDDIR)/release/xplad
139+
tar -czvf $(BUILDDIR)/release/xpla_$(VERSION)_Linux_arm64.tar.gz -C $(BUILDDIR)/release/ xplad
140+
rm $(BUILDDIR)/release/xplad
141+
$(DOCKER) rm -f xpla-builder
142+
96143
.PHONY: test
97144
test: go.sum
98145
go test -short ./...

0 commit comments

Comments
 (0)