|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Famedly Rust Container entrypoint. |
| 4 | +# |
| 5 | +# Configures the runtime to be used for various CI jobs. |
| 6 | + |
| 7 | +echo "Preparing Rust build environment" |
| 8 | + |
| 9 | + |
| 10 | +if [ -n "${FCR_SSH_KEY}" ]; then |
| 11 | + echo "Setting up SSH" |
| 12 | + |
| 13 | + # Get an ssh agent running |
| 14 | + USER="$(whoami)" |
| 15 | + SSH_HOME="$(getent passwd "$USER" | cut -d: -f6)" # Is different from $HOME in docker containers, because github CI.. |
| 16 | + eval "$(ssh-agent)" # This exports the socket to `SSH_AUTH_SOCK` |
| 17 | + |
| 18 | + # Import the SSH key from the secret |
| 19 | + ssh-add -vvv - <<< "${FCR_SSH_KEY}"$'\n' # ensure newline at the end of key |
| 20 | + |
| 21 | + # Import host keys for GitHub and Gitlab |
| 22 | + mkdir -p "$SSH_HOME/.ssh" |
| 23 | + ( |
| 24 | + ssh-keyscan -H gitlab.com |
| 25 | + ssh-keyscan -H github.com |
| 26 | + ) >> "$SSH_HOME/.ssh/known_hosts" |
| 27 | +fi |
| 28 | + |
| 29 | + |
| 30 | +if [ -n "${FCR_ADDITIONAL_RUST_PACKAGES}" ]; then |
| 31 | + echo "Installing additional packages: ${FCR_ADDITIONAL_RUST_PACKAGES}" |
| 32 | + # shellcheck disable=SC2086 |
| 33 | + apt-get install -yqq --no-install-recommends ${FCR_ADDITIONAL_RUST_PACKAGES} |
| 34 | +fi |
| 35 | + |
| 36 | + |
| 37 | +echo "Configuring cargo" |
| 38 | + |
| 39 | +CARGO_HOME="${HOME}/${CARGO_HOME}" |
| 40 | +mkdir -p "${CARGO_HOME}" |
| 41 | +cat << EOF >> "${CARGO_HOME}/config.toml" |
| 42 | +[net] |
| 43 | +git-fetch-with-cli = true |
| 44 | +EOF |
| 45 | + |
| 46 | +# Don't write anything for crates-io, since it is baked-in and cargo |
| 47 | +# special cases on it so configuring it works differently anyway. |
| 48 | +if [ -n "${FCR_CRATES_REGISTRY}" ] && [ "${FCR_CRATES_REGISTRY}" != "crates-io" ]; then |
| 49 | + case "${FCR_CRATES_REGISTRY}" in |
| 50 | + "famedly") |
| 51 | + FCR_CRATES_REGISTRY_INDEX="${FCR_CRATES_REGISTRY_INDEX:-ssh://git@ssh.shipyard.rs/famedly/crate-index.git}" |
| 52 | + ;; |
| 53 | + "") |
| 54 | + if [ -z "${FCR_CRATES_REGISTRY_INDEX}" ]; then |
| 55 | + echo "Error: Crate registry index URL not known for ${FCR_CRATES_REGISTRY}. Configure it using \$FCR_CRATES_REGISTRY_INDEX." > /dev/stderr |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + ;; |
| 59 | + esac |
| 60 | + |
| 61 | + cat << EOF >> "${CARGO_HOME}/config.toml" |
| 62 | +[registries.${FCR_CRATES_REGISTRY}] |
| 63 | +index = "${FCR_CRATES_REGISTRY_INDEX}" |
| 64 | +EOF |
| 65 | +fi |
| 66 | + |
| 67 | + |
| 68 | +if [ -n "${GITHUB_ENV}" ]; then |
| 69 | + # TODO(tlater): Check if this is even necessary; AIUI we should |
| 70 | + # remain in the container env and therefore these variables should |
| 71 | + # already be set. |
| 72 | + echo "Exporting created environment variables" |
| 73 | + |
| 74 | + ( |
| 75 | + echo "CARGO_HOME=${CARGO_HOME}" |
| 76 | + echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" |
| 77 | + ) >> "$GITHUB_ENV" |
| 78 | +fi |
| 79 | + |
| 80 | + |
| 81 | +echo "Preparations finished" |
| 82 | +"$@" |
0 commit comments