Skip to content

Commit

Permalink
Removing SUDO mandatory dependency (#97)
Browse files Browse the repository at this point in the history
* fix: remove logic that checks for SUDO availability given that the SUDO variable handles its value as empty or not. Adding a new test to vlaidate it works in scenarios without sudo available

* fix: test-without-sudo does not erquire any previous test
  • Loading branch information
david-montano-circleci authored Oct 10, 2024
1 parent f49fe33 commit c9e7dd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ release-filters: &release-filters
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/

jobs:
test-without-sudo:
docker:
- image: google/cloud-sdk:latest
steps:
- checkout
- gcp-gcr/gcr-auth
integration-test-without-oidc:
executor: gcp-gcr/default
steps:
Expand Down Expand Up @@ -72,6 +78,13 @@ jobs:
workflows:
test-deploy:
jobs:
- test-without-sudo:
context: cpe-gcp
filters: *filters
post-steps:
- run:
command: |
gcloud version
- integration-test-without-oidc:
context: cpe-gcp
filters: *filters
Expand Down
12 changes: 5 additions & 7 deletions src/scripts/gcr-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ case "${unameOut}" in
*) platform="UNKNOWN:${unameOut}"
esac

if [ "${platform}" != "windows" ] && ! command -v sudo > /dev/null 2>&1; then
printf '%s\n' "sudo is required to configure Docker to use GCP repositories."
printf '%s\n' "Please install it and try again."
return 1
fi

# Set sudo to work whether logged in as root user or non-root user
if [[ $EUID == 0 ]] || [[ "${platform}" == "windows" ]]; then export SUDO=""; else export SUDO="sudo"; fi
if [[ $EUID == 0 ]] || [[ "${platform}" == "windows" ]]; then
export SUDO=""
else
export SUDO="sudo"
fi

# configure Docker to use gcloud as a credential helper
mkdir -p "$HOME/.docker"
Expand Down

0 comments on commit c9e7dd1

Please sign in to comment.