#!/usr/bin/env bash # ============================================================================= # 01-login.sh (Linux) # Authenticates your local machine to Google Cloud and configures Docker # to push images to Artifact Registry. # # Run this once per machine (or whenever your credentials expire). # Windows users: run GCR/scripts/01-login.ps1 in PowerShell instead. # ============================================================================= set -euo pipefail if [[ "$(uname -s)" != "Linux" ]]; then echo "ERROR: This script is for Linux only." echo "Windows users: run GCR/scripts/01-login.ps1" exit 1 fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # ── Load .env ───────────────────────────────────────────────────────────────── ENV_FILE="$SCRIPT_DIR/../.env" if [[ ! -f "$ENV_FILE" ]]; then echo "ERROR: $ENV_FILE not found." echo "Copy GCR/.env.example to GCR/.env and fill in your values first." exit 1 fi # shellcheck disable=SC1090 source "$ENV_FILE" : "${GCP_PROJECT_ID:?GCP_PROJECT_ID is not set in .env}" : "${GCP_REGION:?GCP_REGION is not set in .env}" # ── Step 1: Authenticate user account ──────────────────────────────────────── echo ">>> Logging in to Google Cloud..." echo " A browser window will open. Sign in with the Google account that has" echo " access to project: $GCP_PROJECT_ID" echo "" gcloud auth login # ── Step 2: Set default project ────────────────────────────────────────────── echo "" echo ">>> Setting default project to: $GCP_PROJECT_ID" gcloud config set project "$GCP_PROJECT_ID" # ── Step 3: Set default region ─────────────────────────────────────────────── echo ">>> Setting default region to: $GCP_REGION" gcloud config set run/region "$GCP_REGION" # ── Step 4: Configure Docker to authenticate against Artifact Registry ──────── echo "" echo ">>> Configuring Docker to authenticate with Artifact Registry..." gcloud auth configure-docker "${GCP_REGION}-docker.pkg.dev" --quiet echo "" echo ">>> Login complete. You are now authenticated as:" gcloud auth list --filter=status:ACTIVE --format="value(account)" echo "" echo ">>> Next step: run GCR/scripts/02-setup-project.sh"