Skip to content
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

feat(poetry): use sudo to install curl if running as user #119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CoRfr
Copy link
Contributor

@CoRfr CoRfr commented Jun 2, 2023

Summary

If the UID is not 0 (root), uses sudo to install curl. Also checking if curl is already installed before trying to install it.

Standard Checklist

  • My comments/docstrings/type hints are clear
  • I've written new tests or this change does not need them
  • I've tested this manually
  • The architecture diagrams have been updated, if need be
  • Any external changes/dependencies are linked and described
  • I've included any special rollback strategies above
  • Any relevant metrics/monitors/SLOs have been added or modified
  • I've notified all relevant stakeholders of the change
  • I've updated .github/CODEOWNERS, if relevant

If the UID is not 0 (root), uses sudo to install curl.
Also checking if curl is already installed before trying to install it.
@CoRfr CoRfr requested review from a team and TheKevJames as code owners June 2, 2023 19:07
@CoRfr CoRfr requested review from jonathan-johnston and shaundialpad and removed request for a team June 2, 2023 19:07
Copy link
Member

@TheKevJames TheKevJames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, and thanks for finding this! Couple comments, but overall we'd be happy to accept this fix.

poetry/orb.yaml Outdated
@@ -26,16 +26,24 @@ commands:
type: string
steps:
- run:
name: install curl
name: Install curl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: leave this lowercase please, all our step names are.

apt-get update -qy
apt-get install -qy curl
if cat /etc/issue | grep "Alpine" >/dev/null 2>&1; then
if [ "$ID" = 0 ]; then export SUDO=""; else export SUDO="sudo"; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression Alpine doesn't tend to ship with the sudo binary, do you have a sample flow for how you tested this which I could play with?

I haven't ever really had opportunity to do this, but I have vague recollections about them using su-exec instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the default alpine doesn't ship with either, so in any case it needs to be installed beforehand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is running alpine with ID!=0 just not possible, then, if you need to use non-default packages? Maybe we need to make that an error case? Or avoid setting this SUDO value in that case? Just want to make sure we aren't breaking any cases which previously worked, here.

poetry/orb.yaml Outdated
exit 1
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
fi
echo "export SUDO=$SUDO" >> ${BASH_ENV}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this -- the SUDO variable isn't used in any future steps here, so we can keep it contained into only this step rather than potentially affecting future tasks.

poetry/orb.yaml Outdated
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
fi
echo "export SUDO=$SUDO" >> ${BASH_ENV}
if [ ! "$(command -v curl)" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this check to be the first line of this step: there's no need to do any work in this step if curl is already installed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants