From aa01c967d3e711f75b2e00a4626f7f0de47157b7 Mon Sep 17 00:00:00 2001
From: Carlton Hanna <nullpointer0x00@gmail.com>
Date: Tue, 31 Oct 2023 10:52:35 -0600
Subject: [PATCH] Add arm64 to docker publish workflow (#1709)

* add arm64 to docker publish workflow

* add comments back to file

* Add changelog entry

* temp add of my branch

* remove test

* second attempt

* remove test

* add a fix and temp publish docker from branch

* better logic

* try setting arg another way

* remove ARCH arg from build, use uname from container to copy over correct wasm file

* remove temp wasm files

* Add arch check and error message for clarity

* remove custom branch from workflow

* test build platform

* remove cleveldb, check build archs

* remove branch
---
 .github/workflows/docker.yml | 12 +++++++++---
 CHANGELOG.md                 |  1 +
 Makefile                     |  7 ++-----
 docker/blockchain/Dockerfile | 21 +++++++++++++++++----
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 6b2ba6ada2..cae8de7780 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -8,7 +8,7 @@ on:
     tags:
       - "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10
       - "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
-
+      
 # Set concurrency for this workflow to cancel in-progress jobs if retriggered.
 # The github.ref is only available when triggered by a PR so fall back to github.run_id for other cases.
 # The github.run_id is unique for each run, giving each such invocation it's own unique concurrency group.
@@ -17,7 +17,6 @@ on:
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
   cancel-in-progress: true
-
 jobs:
   docker:
     runs-on: ubuntu-latest
@@ -25,13 +24,16 @@ jobs:
       - uses: actions/checkout@v4
         with:
           fetch-depth: 0
+
       - name: Setup go
         uses: actions/setup-go@v4
         with:
           go-version: '1.20'
+
       - name: Go mod vendor
         run: |
          go mod vendor
+
       - name: Prepare
         id: prep
         run: |
@@ -56,16 +58,20 @@ jobs:
           created="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
           echo "Setting output: created=$created"
           echo "created=$created" >> "$GITHUB_OUTPUT"
+
       - name: Set up Docker Buildx
         id: buildx
         uses: docker/setup-buildx-action@v3
+
       - name: Available platforms
         run: echo ${{ steps.buildx.outputs.platforms }}
+
       - name: Login to DockerHub
         uses: docker/login-action@v3
         with:
           username: ${{ secrets.DOCKERHUB_USERNAME }}
           password: ${{ secrets.DOCKERHUB_TOKEN }}
+
       - name: Publish to Docker Hub
         uses: docker/build-push-action@v5
         with:
@@ -73,7 +79,7 @@ jobs:
           target: run
           build-args: |
             VERSION=${{ steps.prep.outputs.version }}
-          platforms: linux/amd64
+          platforms: linux/amd64,linux/arm64
           file: docker/blockchain/Dockerfile
           push: ${{ github.event_name != 'pull_request' }}
           tags: ${{ steps.prep.outputs.tags }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e69b91bfb2..e225682b94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
 * Bump cometbft to v0.34.29 (from v0.34.28) [PR 1649](https://github.com/provenance-io/provenance/pull/1649).
 * Add genesis/init for Marker module send deny list addresses. [#1660](https://github.com/provenance-io/provenance/issues/1660)
 * Add automatic changelog entries for dependabot. [#1674](https://github.com/provenance-io/provenance/issues/1674)
+* Add publishing of docker arm64 container builds [#1634](https://github.com/provenance-io/provenance/issues/1634)
 * Ensure IBC marker has matching supply [#1706](https://github.com/provenance-io/provenance/issues/1706).
 
 ### Bug Fixes
diff --git a/Makefile b/Makefile
index 41806cf750..43282b4424 100644
--- a/Makefile
+++ b/Makefile
@@ -454,11 +454,8 @@ vendor:
 
 # Full build inside a docker container for a clean release build
 docker-build: vendor
-ifeq ($(UNAME_M),x86_64)
-	docker build --build-arg VERSION=$(VERSION) --build-arg ARCH=$(UNAME_M) -t provenance-io/blockchain . -f docker/blockchain/Dockerfile
-else
-	docker build --build-arg VERSION=$(VERSION) --build-arg ARCH=aarch64 -t provenance-io/blockchain . -f docker/blockchain/Dockerfile
-endif
+	docker build --build-arg VERSION=$(VERSION) -t provenance-io/blockchain . -f docker/blockchain/Dockerfile
+
 
 # Quick build using local environment and go platform target options.
 docker-build-local: vendor
diff --git a/docker/blockchain/Dockerfile b/docker/blockchain/Dockerfile
index 6fa632a18d..832d56cb5d 100644
--- a/docker/blockchain/Dockerfile
+++ b/docker/blockchain/Dockerfile
@@ -1,6 +1,5 @@
 FROM golang:1.20-bullseye as build
 ARG VERSION
-ARG ARCH=x86_64
 
 WORKDIR /go/src/github.com/provenance-io/provenance
 
@@ -23,21 +22,35 @@ COPY Makefile sims.mk ./
 
 # Build and install provenanced
 ENV VERSION=$VERSION
-RUN make VERSION=${VERSION} WITH_CLEVELDB=true install
+RUN ARCH=$(uname -m) && \
+    if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "aarch64" ]; then \
+        echo "Unsupported architecture (required: x86_64 or aarch64): $ARCH"; \
+        exit 1; \
+    fi && \
+    echo "Building and installing provenance for Arch: $ARCH"; \
+    make VERSION=${VERSION} install
 
 ###
 FROM debian:bullseye-slim as run
-ARG ARCH=x86_64
 ENV LD_LIBRARY_PATH="/usr/local/lib"
 RUN apt-get update && \
     apt-get upgrade -y && \
     apt-get install -y curl jq libleveldb-dev && \
     apt-get clean && \
     rm -rf /var/lib/apt/lists/
+    
 
-COPY --from=build /go/src/github.com/provenance-io/provenance/vendor/github.com/CosmWasm/wasmvm/internal/api/libwasmvm.$ARCH.so /usr/local/lib
+COPY --from=build /go/src/github.com/provenance-io/provenance/vendor/github.com/CosmWasm/wasmvm/internal/api/libwasmvm.*.so /tmp
 COPY --from=build /go/bin/provenanced /usr/bin/provenanced
 
+RUN ARCH=$(uname -m) && \
+    if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "aarch64" ]; then \
+        echo "Unsupported architecture (required: x86_64 or aarch64): $ARCH"; \
+        exit 1; \
+    fi && \
+    cp /tmp/libwasmvm.$ARCH.so /usr/local/lib/. && \
+    rm /tmp/libwasmvm.*.so
+
 ENV PIO_HOME=/home/provenance
 WORKDIR /home/provenance