Skip to content

Commit 46b4f6f

Browse files
feat: Add an entrypoint to perform env setup
1 parent 1746d80 commit 46b4f6f

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

Diff for: Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ RUN apt update -yqq \
2525
&& cargo install cargo-license \
2626
&& cargo cache -a
2727
COPY cobertura_transform.xslt /opt/
28+
29+
COPY entrypoint.bash /entrypoint.bash
30+
ENTRYPOINT ["/entrypoint.bash"]

Diff for: README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Famedly Rust Container
2+
3+
Container used for Rust CI jobs. Set up with all necessary packages
4+
and configuration to build, test and publish our crates.
5+
6+
For full environment setup, some secrets need to be defined:
7+
8+
## Settings
9+
10+
| Variable | Example Value | Explanation |
11+
|------------------------------|---------------------------------------------------|-----------------------------------------------------------------------|
12+
| FCR_ADDITIONAL_RUST_PACKAGES | cargo-fuzz cargo-tarpaulin | Additional Rust packages to install before running the given command. |
13+
| FCR_CRATES_REGISTRY | famedly | Additional registry to pull crates from. |
14+
| FCR_CRATES_REGISTRY_INDEX | ssh://[email protected]/famedly/crate-index.git | The index URL of the registry; Can be omitted for `famedly`. |
15+
| FCR_SSH_KEY | | The SSH key to use |

Diff for: entrypoint.bash

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)