Skip to content

Commit 9062d3b

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

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

.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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@ 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/ubuntu/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/ubuntu \
16+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
17+
tee /etc/apt/sources.list.d/docker.list > /dev/null \
18+
19+
# Note that we do not need docker engine as we mount a docker socket
20+
# into the container
621
RUN apt update -yqq \
722
&& apt install -yqq --no-install-recommends \
823
build-essential cmake libssl-dev pkg-config git musl-tools jq xmlstarlet lcov protobuf-compiler libprotobuf-dev libprotoc-dev \
24+
docker-ce-cli docker-compose-plugin \
925
&& rustup toolchain add $NIGHTLY_VERSION --component rustfmt --component clippy --component llvm-tools-preview \
1026
&& rustup toolchain add beta --component rustfmt --component clippy --component llvm-tools-preview \
1127
&& rustup toolchain add stable --component rustfmt --component clippy --component llvm-tools-preview \
@@ -24,4 +40,8 @@ RUN apt update -yqq \
2440
&& cargo install cargo-auditable \
2541
&& cargo install cargo-license \
2642
&& cargo cache -a
43+
2744
COPY cobertura_transform.xslt /opt/
45+
46+
COPY entrypoint.bash /entrypoint.bash
47+
ENTRYPOINT ["/entrypoint.bash"]

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://[email protected]/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.bash

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

0 commit comments

Comments
 (0)