Skip to content

Commit

Permalink
ci: allow skipping sudo on dockerized jobs
Browse files Browse the repository at this point in the history
Our "install-dependencies.sh" script is executed by non-dockerized jobs
to install dependencies. These jobs don't run with "root" permissions,
but with a separate user. Consequently, we need to use sudo(8) there to
elevate permissions when installing packages.

We're about to merge "install-docker-dependencies.sh" into that script
though, and our Docker containers do run as "root". Using sudo(8) is
thus unnecessary there, even though it would be harmless. On some images
like Alpine Linux though there is no sudo(8) available by default, which
would consequently break the build.

Adapt the script to make "sudo" a no-op when running as "root" user.
This allows us to easily reuse the script for our dockerized jobs.
  • Loading branch information
pks-t committed Apr 4, 2024
1 parent c6fb81e commit de39855
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ci/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ UBUNTU_COMMON_PKGS="make libssl-dev libcurl4-openssl-dev libexpat-dev
tcl tk gettext zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl
libemail-valid-perl libio-socket-ssl-perl libnet-smtp-ssl-perl"

# Make sudo a no-op and execute the command directly when running as root.
# While using sudo would be fine on most platforms when we are root already,
# some platforms like e.g. Alpine Linux do not have sudo available by default
# and would thus break.
if test "$USER" = "root"
then
sudo () {
"$@"
}
fi

case "$distro" in
ubuntu-*)
sudo apt-get -q update
Expand Down

0 comments on commit de39855

Please sign in to comment.