From dae763a61a9eb6f39d8be01f923620c157b3202a Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 13 Sep 2024 04:52:26 -0700 Subject: [PATCH] Add muti-arch build (#2) * download jar in Dockerfile add multiplatform build update version logic add tag push trigger * Bump ubuntu LTS; fix arm build --------- Co-authored-by: Dmitry S <11892559+swift1337@users.noreply.github.com> --- .dockerignore | 1 - .github/workflows/docker.yml | 19 +++++++++++++------ Dockerfile | 10 ++++++---- Makefile | 4 ++-- scripts/download-jar.sh | 27 +++++++++++++++++---------- scripts/entrypoint.sh | 0 6 files changed, 38 insertions(+), 23 deletions(-) mode change 100644 => 100755 scripts/entrypoint.sh diff --git a/.dockerignore b/.dockerignore index e4c88bc..ce14953 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,3 @@ .git sidecar/main_test.go -scripts/download-jar.sh \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bbdfbd5..02e8ace 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,13 +3,23 @@ on: # Manual trigger workflow_dispatch: + push: + tags: + - v* + jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Set image name run: | - echo "IMAGE_NAME=ghcr.io/${{ github.repository }}" >> $GITHUB_ENV + # Default tag as commit SHA + VERSION=${GITHUB_SHA::7} + # Use tag name if it's a tag push + if [ "$GITHUB_EVENT_NAME" == "push" ] && [ "$GITHUB_REF_TYPE" == "tag" ]; then + VERSION=${GITHUB_REF_NAME} + fi + echo "IMAGE_NAME=ghcr.io/${{ github.repository }}:${VERSION}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 @@ -27,13 +37,10 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Download required file - run: chmod +x ./scripts/download-jar.sh && ./scripts/download-jar.sh - - name: Build And Push uses: docker/build-push-action@v6 with: + platforms: linux/amd64,linux/arm64 context: . push: true - tags: | - ${{ env.IMAGE_NAME }}:latest + tags: ${{ env.IMAGE_NAME }} diff --git a/Dockerfile b/Dockerfile index ed20f0e..67af599 100755 --- a/Dockerfile +++ b/Dockerfile @@ -4,17 +4,17 @@ WORKDIR /opt/sidecar COPY ./sidecar/ . RUN go build -o /opt/sidecar/sidecar main.go -FROM ubuntu:22.04 AS ton-node +FROM ubuntu:24.04 AS ton-node ARG WORKDIR="/opt/my-local-ton" # Install dependencies && drop apt cache RUN apt-get update \ && apt-get install -y --no-install-recommends \ - openjdk-21-jre-headless curl jq vim lsb-release \ + openjdk-21-jre-headless curl jq vim lsb-release libatomic1 \ && rm -rf /var/lib/apt/lists/* -COPY scripts/my-local-ton.jar $WORKDIR/ +COPY scripts/download-jar.sh $WORKDIR/ COPY scripts/entrypoint.sh $WORKDIR/ COPY scripts/genesis.sh $WORKDIR/ @@ -22,7 +22,9 @@ COPY --from=go-builder /opt/sidecar $WORKDIR/ WORKDIR $WORKDIR -# Ensure whether the build works +RUN ./download-jar.sh + +# Ensure whether the build is working RUN chmod +x entrypoint.sh \ && chmod +x sidecar \ && chmod +x genesis.sh \ diff --git a/Makefile b/Makefile index a9ed436..85d6507 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ help: ## List of commands build: ## Build image @echo "Building ton docker image" scripts/download-jar.sh - docker buildx build --platform linux/amd64 -t ton-local -f Dockerfile . + docker buildx build -t ton-local -f Dockerfile . build-no-cache: # Build w/o cache @echo "Building ton docker image" scripts/download-jar.sh - docker buildx build --no-cache --platform linux/amd64 -t ton-local -f Dockerfile . + docker buildx build --no-cache -t ton-local -f Dockerfile . test-sidecar: ## Test sidecar go test ./sidecar/... diff --git a/scripts/download-jar.sh b/scripts/download-jar.sh index 762ff3f..5c4cbed 100755 --- a/scripts/download-jar.sh +++ b/scripts/download-jar.sh @@ -1,17 +1,24 @@ #!/bin/bash -script_dir=$(cd -- "$(dirname -- "$0")" &> /dev/null && pwd) +set -eo pipefail -# Downloads JAR outside of the Dockerfile to avoid re-downloading it every time during rebuilds. jar_version="v120" -jar_url="https://github.com/neodix42/MyLocalTon/releases/download/${jar_version}/MyLocalTon-x86-64.jar" -jar_file="$script_dir/my-local-ton.jar" +arch=$(uname -m) -if [ -f "$jar_file" ]; then - echo "File $jar_file already exists. Skipping download." - exit 0 -fi +case $arch in + x86_64) + arch_suffix="x86-64" + ;; + aarch64|arm64) + arch_suffix="arm64" + ;; + *) + echo "Unsupported architecture: $arch" + exit 1 + ;; +esac + +jar_url="https://github.com/neodix42/MyLocalTon/releases/download/${jar_version}/MyLocalTon-${arch_suffix}.jar" -echo "File not found. Downloading..." echo "URL: $jar_url" -wget -q --show-progress -O "$jar_file" "$jar_url" +curl -L -o "my-local-ton.jar" "$jar_url" diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh old mode 100644 new mode 100755