Skip to content

Commit

Permalink
feat: Add an entrypoint to perform env setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tlater-famedly committed Feb 5, 2025
1 parent 1746d80 commit 57eb505
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
publish_release:
if: github.event.pull_request.merged == true
needs: set_date
uses: famedly/github-workflows/.github/workflows/docker.yml@49401388492ed7fe3eeb13fbefacf68168e9bc64
uses: famedly/github-workflows/.github/workflows/docker.yml@597134d3c9ce40aa5b2ca12f8236483dab96a20c
with:
push: true
image_name: rust-container
Expand All @@ -43,7 +43,7 @@ jobs:
publish_dev:
if: github.event.pull_request.merged != true
needs: set_date
uses: famedly/github-workflows/.github/workflows/docker.yml@49401388492ed7fe3eeb13fbefacf68168e9bc64
uses: famedly/github-workflows/.github/workflows/docker.yml@597134d3c9ce40aa5b2ca12f8236483dab96a20c
with:
push: true
image_name: rust-container
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ RUN apt update -yqq \
&& cargo install cargo-license \
&& cargo cache -a
COPY cobertura_transform.xslt /opt/

COPY entrypoint.bash /entrypoint.bash
ENTRYPOINT ["/entrypoint.bash"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Famedly Rust Container

Container used for Rust CI jobs. Set up with all necessary packages
and configuration to build, test and publish our crates.

For full environment setup, some secrets need to be defined:

## Settings

| Variable | Example Value | Explanation |
|------------------------------|---------------------------------------------------|-------------|
| FRC_ADDITIONAL_PACKAGES | libxml2 dbus | Additional ubuntu packages to install before running the given command. |
| FRC_CRATES_REGISTRY | famedly | Additional registry to pull crates from. |
| FRC_CRATES_REGISTRY_INDEX | ssh://[email protected]/famedly/crate-index.git | The index URL of the registry; Can be omitted for `famedly`. |
| FRC_SSH_KEY | | The SSH key to use |
86 changes: 86 additions & 0 deletions entrypoint.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# Famedly Rust Container entrypoint.
#
# Configures the runtime to be used for various CI jobs.

echo "Preparing Rust build environment"


if [ -n "${FRC_SSH_KEY}" ]; then
echo "Setting up SSH"

# Get an ssh agent running
USER="$(whoami)"
SSH_HOME="$(getent passwd "$USER" | cut -d: -f6)" # Is different from $HOME in docker containers, because github CI..
eval "$(ssh-agent)" # This exports the socket to `SSH_AUTH_SOCK`

# Import the SSH key from the secret
ssh-add -vvv - <<< "${FRC_SSH_KEY}"$'\n' # ensure newline at the end of key

# Import host keys for GitHub and Gitlab
mkdir -p "$SSH_HOME/.ssh"
(
ssh-keyscan -H gitlab.com
ssh-keyscan -H github.com
) >> "$SSH_HOME/.ssh/known_hosts"
else
echo "SSH key not specified; SSH not available in this run"
fi


if [ -n "${FRC_ADDITIONAL_PACKAGES}" ]; then
echo "Installing additional packages: ${FRC_ADDITIONAL_PACKAGES}"
# shellcheck disable=SC2086
apt-get install -yqq --no-install-recommends ${FRC_ADDITIONAL_PACKAGES}
fi


echo "Configuring cargo"

CARGO_HOME="${HOME}/${CARGO_HOME}"
mkdir -p "${CARGO_HOME}"
cat << EOF >> "${CARGO_HOME}/config.toml"
[term]
color = 'always'
[net]
git-fetch-with-cli = true
EOF

# Don't write anything for crates-io, since it is baked-in and cargo
# special cases on it so configuring it works differently anyway.
if [ -n "${FRC_CRATES_REGISTRY}" ] && [ "${FRC_CRATES_REGISTRY}" != "crates-io" ]; then
case "${FRC_CRATES_REGISTRY}" in
"famedly")
FRC_CRATES_REGISTRY_INDEX="${FRC_CRATES_REGISTRY_INDEX:-ssh://git@ssh.shipyard.rs/famedly/crate-index.git}"
;;
"")
if [ -z "${FRC_CRATES_REGISTRY_INDEX}" ]; then
echo "Error: Crate registry index URL not known for ${FRC_CRATES_REGISTRY}. Configure it using \$FRC_CRATES_REGISTRY_INDEX." > /dev/stderr
exit 1
fi
;;
esac

cat << EOF >> "${CARGO_HOME}/config.toml"
[registries.${FRC_CRATES_REGISTRY}]
index = "${FRC_CRATES_REGISTRY_INDEX}"
EOF
fi


if [ -n "${GITHUB_ENV}" ]; then
# TODO(tlater): Check if this is even necessary; AIUI we should
# remain in the container env and therefore these variables should
# already be set.
echo "Exporting created environment variables"

(
echo "CARGO_HOME=${CARGO_HOME}"
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}"
) >> "$GITHUB_ENV"
fi


echo "Preparations finished"
"$@"

0 comments on commit 57eb505

Please sign in to comment.