Skip to content

Commit

Permalink
Merge pull request #837 from linuxserver/code-server-rust-multi
Browse files Browse the repository at this point in the history
rust: switch to multi-arch
  • Loading branch information
aptalca authored Feb 18, 2024
2 parents 05a486b + 1a02d2f commit 120cd4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/BuildImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
ENDPOINT: "linuxserver/mods" #don't modify
BASEIMAGE: "code-server"
MODNAME: "rust"
MULTI_ARCH: "true" #set to true if needed

jobs:
set-vars:
Expand All @@ -19,6 +20,7 @@ jobs:
echo "ENDPOINT=${{ env.ENDPOINT }}" >> $GITHUB_OUTPUT
echo "BASEIMAGE=${{ env.BASEIMAGE }}" >> $GITHUB_OUTPUT
echo "MODNAME=${{ env.MODNAME }}" >> $GITHUB_OUTPUT
echo "MULTI_ARCH=${{ env.MULTI_ARCH }}" >> $GITHUB_OUTPUT
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
MOD_VERSION=$(curl -s https://api.github.com/repos/rust-lang/rust/releases/latest | jq -r .tag_name)
echo "MOD_VERSION=${MOD_VERSION}" >> $GITHUB_OUTPUT
Expand All @@ -27,6 +29,7 @@ jobs:
ENDPOINT: ${{ steps.outputs.outputs.ENDPOINT }}
BASEIMAGE: ${{ steps.outputs.outputs.BASEIMAGE }}
MODNAME: ${{ steps.outputs.outputs.MODNAME }}
MULTI_ARCH: ${{ steps.outputs.outputs.MULTI_ARCH }}
MOD_VERSION: ${{ steps.outputs.outputs.MOD_VERSION }}

build:
Expand All @@ -42,4 +45,5 @@ jobs:
ENDPOINT: ${{ needs.set-vars.outputs.ENDPOINT }}
BASEIMAGE: ${{ needs.set-vars.outputs.BASEIMAGE }}
MODNAME: ${{ needs.set-vars.outputs.MODNAME }}
MULTI_ARCH: ${{ needs.set-vars.outputs.MULTI_ARCH }}
MOD_VERSION: ${{ needs.set-vars.outputs.MOD_VERSION }}
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ FROM ghcr.io/linuxserver/baseimage-alpine:3.19 as buildstage

ARG MOD_VERSION

RUN if [ -z "$MOD_VERSION" ]; then \
RUN \
echo "**** Retrieving rust version ****" && \
if [ -z "$MOD_VERSION" ]; then \
MOD_VERSION=$(curl -s https://api.github.com/repos/rust-lang/rust/releases/latest | jq -r .tag_name); \
fi && \
mkdir -p /root-layer/rust-bins && \
SUPPORTED_PLATFORMS="x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu" && \
for PLATFORM in $SUPPORTED_PLATFORMS; do \
ARCH=${PLATFORM%%-*}; \
RUST_BINS=/root-layer/rust-bins/rust-${ARCH}-gnu.tar.gz; \
RUST_BINS_URL=https://static.rust-lang.org/dist/rust-${MOD_VERSION}-${PLATFORM}.tar.gz; \
echo "Downloading rust for $PLATFORM"; \
curl -o $RUST_BINS -sSf $RUST_BINS_URL; \
done;
if [ $(uname -m) = "x86_64" ]; then \
echo "**** Downloading x86_64 tarball ****" && \
curl -fo \
/root-layer/rust-bins/rust.tar.gz -L \
"https://static.rust-lang.org/dist/rust-${MOD_VERSION}-x86_64-unknown-linux-gnu.tar.gz"; \
elif [ $(uname -m) = "aarch64" ]; then \
echo "**** Downloading aarch64 tarball ****" && \
curl -fo \
/root-layer/rust-bins/rust.tar.gz -L \
"https://static.rust-lang.org/dist/rust-${MOD_VERSION}-aarch64-unknown-linux-gnu.tar.gz"; \
fi

COPY root/ /root-layer/

Expand Down
24 changes: 8 additions & 16 deletions root/etc/s6-overlay/s6-rc.d/init-mod-code-server-rust-install/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@

set -e

RUST_BINS_PATH="/rust-bins"
PACKAGES_TO_INSTALL_LIST="/mod-repo-packages-to-install.list"

ARCH=$(uname -m)
SUPPORTED_ARCHS=("x86_64" "aarch64")

if [[ ! " ${SUPPORTED_ARCHS[@]} " =~ " ${ARCH} " ]]; then
echo "**** unsupported architecture: $ARCH ****"
exit 1
if [[ "${ARCH}" = "armv7l" ]]; then
echo "**** The docker mods no longer support arm32v7/armhf per https://info.linuxserver.io/issues/2023-07-01-armhf/ ****"
exit 0
fi

if ! dpkg -l | grep build-essential >/dev/null; then
echo "**** adding build-essential to install list ****"
echo "build-essential" >>"$PACKAGES_TO_INSTALL_LIST"
echo "build-essential" >> /mod-repo-packages-to-install.list
else
echo "**** build-essential already installed ****"
fi

RUST_BINARY_ARCHIVE_PATH="$RUST_BINS_PATH/rust-$ARCH-gnu.tar.gz"

if [[ -f "$RUST_BINARY_ARCHIVE_PATH" ]]; then
if [[ -f /rust-bins/rust.tar.gz ]]; then
echo "**** unpacking rust tar ****"
tar -xzf "$RUST_BINARY_ARCHIVE_PATH" -C "$RUST_BINS_PATH" --strip-components=1

tar -xzf /rust-bins/rust.tar.gz -C /rust-bins --strip-components=1
echo "**** installing rust ****"
"$RUST_BINS_PATH/install.sh"
rm -rf "$RUST_BINS_PATH"
/rust-bins/install.sh
rm -rf /rust-bins/rust.tar.gz
else
echo "**** latest rust is already installed ****"
fi

0 comments on commit 120cd4b

Please sign in to comment.