Skip to content

Commit

Permalink
refactor: Move supautils download script to external file
Browse files Browse the repository at this point in the history
  • Loading branch information
jhf committed Oct 29, 2024
1 parent ebfa985 commit 566ceea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
26 changes: 8 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,16 @@ ARG supautils_release_amd64_deb_checksum

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

# Set up a script to download the correct package
RUN echo '#!/bin/sh' > /tmp/download_supautils.sh && \
echo 'set -e' >> /tmp/download_supautils.sh && \
echo 'if [ "$TARGETARCH" = "amd64" ]; then' >> /tmp/download_supautils.sh && \
echo ' CHECKSUM="${supautils_release_amd64_deb_checksum}"' >> /tmp/download_supautils.sh && \
echo ' ARCH="amd64"' >> /tmp/download_supautils.sh && \
echo 'elif [ "$TARGETARCH" = "arm64" ]; then' >> /tmp/download_supautils.sh && \
echo ' CHECKSUM="${supautils_release_arm64_deb_checksum}"' >> /tmp/download_supautils.sh && \
echo ' ARCH="arm64"' >> /tmp/download_supautils.sh && \
echo 'else' >> /tmp/download_supautils.sh && \
echo ' echo "Unsupported architecture: $TARGETARCH" >&2' >> /tmp/download_supautils.sh && \
echo ' exit 1' >> /tmp/download_supautils.sh && \
echo 'fi' >> /tmp/download_supautils.sh && \
echo 'CHECKSUM=$(echo $CHECKSUM | sed "s/^sha256://")' >> /tmp/download_supautils.sh && \
echo 'curl -fsSL -o /tmp/supautils.deb \\' >> /tmp/download_supautils.sh && \
echo ' "https://github.com/supabase/supautils/releases/download/v${supautils_release}/supautils-v${supautils_release}-pg${postgresql_major}-$ARCH-linux-gnu.deb"' >> /tmp/download_supautils.sh && \
echo 'echo "$CHECKSUM /tmp/supautils.deb" | sha256sum -c -' >> /tmp/download_supautils.sh && \
chmod +x /tmp/download_supautils.sh
# Add the external download script
ADD scripts/download_supautils.sh /tmp/download_supautils.sh

# Run the script to download and verify the package
ARG supautils_release_arm64_deb_checksum
ARG supautils_release_amd64_deb_checksum
ENV supautils_release=${supautils_release} \
postgresql_major=${postgresql_major} \
supautils_release_arm64_deb_checksum=${supautils_release_arm64_deb_checksum} \
supautils_release_amd64_deb_checksum=${supautils_release_amd64_deb_checksum}
RUN /tmp/download_supautils.sh && rm /tmp/download_supautils.sh

####################
Expand Down
26 changes: 26 additions & 0 deletions scripts/download_supautils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -e
# Ensure mandatory environment variables are set
: "${supautils_release:?Environment variable supautils_release is required}"
: "${postgresql_major:?Environment variable postgresql_major is required}"
: "${supautils_release_arm64_deb_checksum:?Environment variable supautils_release_arm64_deb_checksum is required}"
: "${supautils_release_amd64_deb_checksum:?Environment variable supautils_release_amd64_deb_checksum is required}"

# Fallback to uname -m if TARGETARCH is not set
TARGETARCH=${TARGETARCH:-$(uname -m)}

if [ "$TARGETARCH" = "amd64" ]; then
CHECKSUM="${supautils_release_amd64_deb_checksum}"
ARCH="amd64"
elif [ "$TARGETARCH" = "arm64" ]; then
CHECKSUM="${supautils_release_arm64_deb_checksum}"
ARCH="arm64"
else
echo "Unsupported architecture: $TARGETARCH" >&2
exit 1
fi
CHECKSUM=$(echo $CHECKSUM | sed "s/^sha256://")
curl -fsSL -o /tmp/supautils.deb \
"https://github.com/supabase/supautils/releases/download/v${supautils_release}/supautils-v${supautils_release}-pg${postgresql_major}-$ARCH-linux-gnu.deb"
CHECKSUM_LINE=$(echo "$CHECKSUM /tmp/supautils.deb")
echo "$CHECKSUM_LINE" | sha256sum -c -

0 comments on commit 566ceea

Please sign in to comment.