Add builder
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
This commit is contained in:
parent
7f534c8483
commit
9af420b61d
31
Dockerfile-full
Normal file
31
Dockerfile-full
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
FROM docker.io/library/rust:${RUST_VERSION}-slim
|
||||||
|
LABEL maintainer 'Jacob Kiers <code@kie.rs>'
|
||||||
|
|
||||||
|
# Install docker
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y ca-certificates curl gnupg && \
|
||||||
|
mkdir -p /etc/apt/keyrings && \
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" >> /etc/apt/sources.list.d/docker.list && \
|
||||||
|
apt-get update && apt-get install -y docker-ce-cli && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
|
|
||||||
|
# Install cross
|
||||||
|
RUN mkdir -p /usr/local/cargo/bin && curl -L \
|
||||||
|
https://github.com/cross-rs/cross/releases/download/v${CROSS_VERSION}/cross-x86_64-unknown-linux-gnu.tar.gz \
|
||||||
|
| tar -xz -C /usr/local/cargo/bin
|
||||||
|
|
||||||
|
|
||||||
|
# Install rust targets
|
||||||
|
RUN rustup target add \
|
||||||
|
aarch64-unknown-linux-gnu \
|
||||||
|
aarch64-unknown-linux-musl \
|
||||||
|
x86_64-pc-windows-gnu \
|
||||||
|
x86_64-unknown-linux-gnu \
|
||||||
|
x86_64-unknown-linux-musl && \
|
||||||
|
rustup component add --target aarch64-unknown-linux-gnu rust-src && \
|
||||||
|
rustup component add --target aarch64-unknown-linux-musl rust-src && \
|
||||||
|
rustup component add --target x86_64-pc-windows-gnu rust-src && \
|
||||||
|
rustup component add --target x86_64-unknown-linux-gnu rust-src && \
|
||||||
|
rustup component add --target x86_64-unknown-linux-musl rust-src
|
18
Dockerfile-slim
Normal file
18
Dockerfile-slim
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM docker.io/library/rust:${RUST_VERSION}-slim
|
||||||
|
LABEL maintainer 'Jacob Kiers <code@kie.rs>'
|
||||||
|
|
||||||
|
# Install docker
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y ca-certificates curl gnupg && \
|
||||||
|
mkdir -p /etc/apt/keyrings && \
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" >> /etc/apt/sources.list.d/docker.list && \
|
||||||
|
apt-get update && apt-get install -y docker-ce-cli && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
|
|
||||||
|
# Install cross
|
||||||
|
RUN mkdir -p /usr/local/cargo/bin && curl -L \
|
||||||
|
https://github.com/cross-rs/cross/releases/download/v${CROSS_VERSION}/cross-x86_64-unknown-linux-gnu.tar.gz \
|
||||||
|
| tar -xz -C /usr/local/cargo/bin
|
||||||
|
|
24
README.md
24
README.md
@ -1,3 +1,25 @@
|
|||||||
# toolchain-builder
|
# toolchain-builder
|
||||||
|
|
||||||
Toolchain builder for Rust cross compilation
|
Toolchain builder for Rust cross compilation.
|
||||||
|
|
||||||
|
This project build the toolchain used for [newsletter2web][1].
|
||||||
|
|
||||||
|
By default, it uses the latest [Rust][2] and [`cross`][3] versions.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
USAGE: ./build.sh <slim|full> [rust version] [cross version]
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
<slim|full> Slim build (without targets) or Full build (with targets)
|
||||||
|
[rust version] Version of rust (https://github.com/rust-lang/rust)
|
||||||
|
[cross version] Version of cross (https://github.com/cross-rs/cross)
|
||||||
|
|
||||||
|
Both versions default to the latest version.
|
||||||
|
```
|
||||||
|
|
||||||
|
[1]: https://code.kiers.eu/newsletter-to-web/newsletter-to-web
|
||||||
|
[2]: https://www.rustlang.org/
|
||||||
|
[3]: https://github.com/cross-rs/cross
|
||||||
|
|
||||||
|
85
build.sh
Executable file
85
build.sh
Executable file
@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
print_usage()
|
||||||
|
{
|
||||||
|
echo "USAGE: $0 <slim|full> [rust version] [cross version]"
|
||||||
|
echo
|
||||||
|
echo "Arguments:"
|
||||||
|
echo -e "\t<slim|full>\tSlim build (without targets) or Full build (with targets)"
|
||||||
|
echo -e "\t[rust version]\tVersion of rust (https://github.com/rust-lang/rust)"
|
||||||
|
echo -e "\t[cross version]\tVersion of cross (https://github.com/cross-rs/cross)"
|
||||||
|
echo
|
||||||
|
echo "Both versions default to the latest version."
|
||||||
|
}
|
||||||
|
|
||||||
|
get_latest_release() {
|
||||||
|
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
|
||||||
|
grep '"tag_name":' | # Get tag line
|
||||||
|
sed -E 's/.*"v?([^"]+)".*/\1/' # Pluck JSON value
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if command -v podman &> /dev/null
|
||||||
|
then
|
||||||
|
BUILDER=podman
|
||||||
|
elif command -v docker &> /dev/null
|
||||||
|
then
|
||||||
|
BUILDER=docker
|
||||||
|
else
|
||||||
|
echo "Prerequisite failed: either podman or docker must be installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v envsubst &> /dev/null
|
||||||
|
then
|
||||||
|
echo "Prerequisite failed: envsubst must be installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case ${1} in
|
||||||
|
full | slim)
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "ERROR: The first argument mus either be 'full' or 'slim'."
|
||||||
|
echo
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
RUST_VERSION=$(get_latest_release 'rust-lang/rust')
|
||||||
|
else
|
||||||
|
RUST_VERSION=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$3" ]; then
|
||||||
|
CROSS_VERSION=$(get_latest_release 'cross-rs/cross')
|
||||||
|
else
|
||||||
|
CROSS_VERSION=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating a ${1} build with Rust ${RUST_VERSION} and cross ${CROSS_VERSION}"
|
||||||
|
|
||||||
|
export RUST_VERSION
|
||||||
|
export CROSS_VERSION
|
||||||
|
|
||||||
|
IMAGE="img.kie.rs/jjkiers/rust-dind-cross:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
|
||||||
|
|
||||||
|
envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
|
||||||
|
-t ${IMAGE} \
|
||||||
|
.
|
||||||
|
|
||||||
|
echo "Built image ${IMAGE}"
|
||||||
|
|
||||||
|
${BUILDER} push ${IMAGE}
|
||||||
|
|
||||||
|
echo "Pushed image ${IMAGE}"
|
Loading…
Reference in New Issue
Block a user