Skip to content

Commit 4c7dac7

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

4 files changed

Lines changed: 124 additions & 2 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
publish_release:
2828
if: github.event.pull_request.merged == true
2929
needs: set_date
30-
uses: famedly/github-workflows/.github/workflows/docker.yml@49401388492ed7fe3eeb13fbefacf68168e9bc64
30+
uses: famedly/github-workflows/.github/workflows/docker.yml@597134d3c9ce40aa5b2ca12f8236483dab96a20c
3131
with:
3232
push: true
3333
image_name: rust-container
@@ -43,7 +43,7 @@ jobs:
4343
publish_dev:
4444
if: github.event.pull_request.merged != true
4545
needs: set_date
46-
uses: famedly/github-workflows/.github/workflows/docker.yml@49401388492ed7fe3eeb13fbefacf68168e9bc64
46+
uses: famedly/github-workflows/.github/workflows/docker.yml@597134d3c9ce40aa5b2ca12f8236483dab96a20c
4747
with:
4848
push: true
4949
image_name: rust-container

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@ FROM docker.io/rust:bookworm
33
ARG NIGHTLY_VERSION_DATE
44
ENV NIGHTLY_VERSION=nightly-$NIGHTLY_VERSION_DATE
55

6+
# Add the docker apt repo.
7+
#
8+
# See instructions in the docker docs:
9+
# https://docs.docker.com/engine/install/ubuntu/#installation-methods
10+
RUN apt install ca-certificates curl \
11+
&& install -m 0755 -d /etc/apt/keyrings \
12+
&& curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \
13+
&& chmod a+r /etc/apt/keyrings/docker.asc \
14+
&& echo \
15+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
16+
tee /etc/apt/sources.list.d/docker.list
17+
18+
# Note that we do not need docker engine as we mount a docker socket
19+
# into the container
620
RUN apt update -yqq \
721
&& apt install -yqq --no-install-recommends \
822
build-essential cmake libssl-dev pkg-config git musl-tools jq xmlstarlet lcov protobuf-compiler libprotobuf-dev libprotoc-dev \
23+
docker-ce-cli docker-compose-plugin \
924
&& rustup toolchain add $NIGHTLY_VERSION --component rustfmt --component clippy --component llvm-tools-preview \
1025
&& rustup toolchain add beta --component rustfmt --component clippy --component llvm-tools-preview \
1126
&& rustup toolchain add stable --component rustfmt --component clippy --component llvm-tools-preview \
@@ -24,4 +39,8 @@ RUN apt update -yqq \
2439
&& cargo install cargo-auditable \
2540
&& cargo install cargo-license \
2641
&& cargo cache -a
42+
2743
COPY cobertura_transform.xslt /opt/
44+
45+
COPY entrypoint.sh /entrypoint.sh
46+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 15 additions & 0 deletions
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+
| FRC_ADDITIONAL_PACKAGES | libxml2 dbus | Additional ubuntu packages to install before running the given command. |
13+
| FRC_CRATES_REGISTRY | famedly | Additional registry to pull crates from. |
14+
| FRC_CRATES_REGISTRY_INDEX | ssh://git@ssh.shipyard.rs/famedly/crate-index.git | The index URL of the registry; Can be omitted for `famedly`. |
15+
| FRC_SSH_KEY | | The SSH key to use |

entrypoint.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/sh
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 "${FRC_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+
#
20+
# `echo` ensures there will be a newline at the end of the key.
21+
echo "${FRC_SSH_KEY}" | ssh-add -vvv -
22+
23+
# Import host keys for GitHub and Gitlab
24+
mkdir -p "$SSH_HOME/.ssh"
25+
(
26+
ssh-keyscan -H gitlab.com
27+
ssh-keyscan -H github.com
28+
) >> "$SSH_HOME/.ssh/known_hosts"
29+
else
30+
echo "SSH key not specified; SSH not available in this run"
31+
fi
32+
33+
34+
if [ -n "${FRC_ADDITIONAL_PACKAGES}" ]; then
35+
echo "Installing additional packages: ${FRC_ADDITIONAL_PACKAGES}"
36+
# shellcheck disable=SC2086
37+
apt-get install -yqq --no-install-recommends ${FRC_ADDITIONAL_PACKAGES}
38+
fi
39+
40+
41+
echo "Configuring cargo"
42+
43+
CARGO_HOME="${HOME}/${CARGO_HOME}"
44+
mkdir -p "${CARGO_HOME}"
45+
cat << EOF >> "${CARGO_HOME}/config.toml"
46+
[term]
47+
color = 'always'
48+
[net]
49+
git-fetch-with-cli = true
50+
EOF
51+
52+
# Don't write anything for crates-io, since it is baked-in and cargo
53+
# special cases on it so configuring it works differently anyway.
54+
if [ -n "${FRC_CRATES_REGISTRY}" ] && [ "${FRC_CRATES_REGISTRY}" != "crates-io" ]; then
55+
case "${FRC_CRATES_REGISTRY}" in
56+
"famedly")
57+
FRC_CRATES_REGISTRY_INDEX="${FRC_CRATES_REGISTRY_INDEX:-ssh://git@ssh.shipyard.rs/famedly/crate-index.git}"
58+
;;
59+
"")
60+
if [ -z "${FRC_CRATES_REGISTRY_INDEX}" ]; then
61+
echo "Error: Crate registry index URL not known for ${FRC_CRATES_REGISTRY}. Configure it using \$FRC_CRATES_REGISTRY_INDEX." > /dev/stderr
62+
exit 1
63+
fi
64+
;;
65+
esac
66+
67+
cat << EOF >> "${CARGO_HOME}/config.toml"
68+
[registries.${FRC_CRATES_REGISTRY}]
69+
index = "${FRC_CRATES_REGISTRY_INDEX}"
70+
EOF
71+
fi
72+
73+
74+
if [ -n "${GITHUB_ENV}" ]; then
75+
# TODO(tlater): Check if this is even necessary; AIUI we should
76+
# remain in the container env and therefore these variables should
77+
# already be set.
78+
echo "Exporting created environment variables"
79+
80+
(
81+
echo "CARGO_HOME=${CARGO_HOME}"
82+
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}"
83+
) >> "$GITHUB_ENV"
84+
fi
85+
86+
87+
echo "Preparations finished"
88+
"$@"

0 commit comments

Comments
 (0)