From c9e7dd1b25891a2bbf2a642a081f2458491863d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Alberto=20Monta=C3=B1o=20Fetecua?= Date: Thu, 10 Oct 2024 08:37:54 -0500 Subject: [PATCH] Removing SUDO mandatory dependency (#97) * 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 --- .circleci/test-deploy.yml | 13 +++++++++++++ src/scripts/gcr-auth.sh | 12 +++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 182908d..11b92a6 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -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: @@ -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 diff --git a/src/scripts/gcr-auth.sh b/src/scripts/gcr-auth.sh index 188e846..187c520 100644 --- a/src/scripts/gcr-auth.sh +++ b/src/scripts/gcr-auth.sh @@ -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"