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..4b87902 100755 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ 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/ @@ -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/scripts/download-jar.sh b/scripts/download-jar.sh index 762ff3f..955bc67 100755 --- a/scripts/download-jar.sh +++ b/scripts/download-jar.sh @@ -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" diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh old mode 100644 new mode 100755