-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add an entrypoint to perform env setup #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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://git@ssh.shipyard.rs/famedly/crate-index.git | The index URL of the registry; Can be omitted for `famedly`. | | ||
| | FRC_SSH_KEY | | The SSH key to use | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "features": { | ||
| "buildkit": true | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/bin/sh | ||
|
|
||
| # 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. | ||
| # | ||
| # `echo` ensures there will be a newline at the end of the key. | ||
| echo "${FRC_SSH_KEY}" | ssh-add -vvv - | ||
|
|
||
| # 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move these to build stage? (into a |
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we just |
||
|
|
||
| # 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 | ||
| echo "Exporting created environment variables" | ||
|
|
||
| ( | ||
| echo "CARGO_HOME=${CARGO_HOME}" | ||
| echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" | ||
| ) >> "$GITHUB_ENV" | ||
| fi | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this work? this script is run insede the container but |
||
|
|
||
|
|
||
| echo "Preparations finished" | ||
| "$@" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify a bit why is this needed? Can we just mount ssh socket
-v $SSH_AUTH_SOCK:/ssh.sock -e SSH_AUTH_SOCK=/ssh.sock?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was taken on from our existing scripts. I don't think GitHub sets up an ssh socket with a configured ssh key natively. The container is started before we start any jobs, so we can't set up a socket in the workflow before this is launched; if you know some way to do that with git workflows shout though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and in docker-build action we set it up manually:
https://github.com/famedly/backend-build-workflows/blob/fa8395ee9485020df251939329dd8d79db6669f3/.github/workflows/docker-backend.yml#L52-L59