Skip to content

Commit

Permalink
Add muti-arch build (#2)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
gartnera and swift1337 authored Sep 13, 2024
1 parent 8c8b59e commit dae763a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
.git

sidecar/main_test.go
scripts/download-jar.sh
19 changes: 13 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ 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/

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 \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
27 changes: 17 additions & 10 deletions scripts/download-jar.sh
Original file line number Diff line number Diff line change
@@ -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"
Empty file modified scripts/entrypoint.sh
100644 → 100755
Empty file.

0 comments on commit dae763a

Please sign in to comment.