Skip to content

Commit

Permalink
download jar in Dockerfile
Browse files Browse the repository at this point in the history
add multiplatform build

update version logic

add tag push trigger
  • Loading branch information
gartnera committed Sep 12, 2024
1 parent 8c8b59e commit 1a97fa8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 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 }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ RUN apt-get update \
openjdk-21-jre-headless curl jq vim lsb-release \
&& 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
27 changes: 16 additions & 11 deletions scripts/download-jar.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/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)
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"

if [ -f "$jar_file" ]; then
echo "File $jar_file already exists. Skipping download."
exit 0
fi

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 1a97fa8

Please sign in to comment.