Rust Release Build & Publish
# Environment Variables
# | Key | Purpose |
# | --------------------- | ---------------------------------------------------------------- |
# | DEPLOY_KEY | Private SSH key (public key must be added in Github) |
# | REPO_URL | Github repository url (ssh) |
# | BINARY_NAME | Binary name in Cargo.toml |
# | RCLONE_CONFIG_CONTENT | Contents of the Rclone config. Name must be "remote_destination" |
# | RCLONE_COPY_PATH | Path of the bucket where you want to copy the file |
# Rclone Config Example
# ```
# [remote_destination]
# type = s3
# provider = Other
# access_key_id =
# secret_access_key =
# endpoint =
# acl = public-read
# ```
export DEBIAN_FRONTEND=noninteractive
apt update
apt install -y build-essential libssl-dev pkg-config curl git openssh-client unzip
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
curl https://rclone.org/install.sh | bash
export RCLONE_CONFIG="/rclone.conf"
echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
mkdir -p /root/.ssh
echo "$DEPLOY_KEY" > /root/.ssh/deploy_key
chmod 600 /root/.ssh/deploy_key
ssh-keyscan github.com >> /root/.ssh/known_hosts
chmod 600 /root/.ssh/known_hosts
mkdir -p /app
GIT_SSH_COMMAND="ssh -i /root/.ssh/deploy_key" git clone $REPO_URL /app
cd /app
FULL_NAME=$BINARY_NAME-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed -e 's/x86_64/amd64/' -e 's/armv6l/arm/' -e 's/armv7l/arm/' -e 's/aarch64/arm64/')
cargo build --release && \
cp target/release/$BINARY_NAME $FULL_NAME
rclone copy "$FULL_NAME" remote_destination:"$RCLONE_COPY_PATH"
2025-06-16T10:02:19.115421774+00:00