CLI Setup Instructions for Docker CI/CD¶
This guide shows how to use the automated setup script to configure all secrets using gcloud, gh, and kubectl CLI tools.
Quick Start¶
Run the automated setup script:
The script will guide you through the entire setup process interactively.
Prerequisites¶
Before running the script, ensure you have these CLI tools installed:
1. Google Cloud SDK (gcloud)¶
# macOS
brew install --cask google-cloud-sdk
# Linux
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
# Verify installation
gcloud --version
2. GitHub CLI (gh)¶
# macOS
brew install gh
# Linux/Windows
# Download from: https://cli.github.com/
# Verify installation
gh --version
3. kubectl¶
# macOS
brew install kubectl
# Linux
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# Verify installation
kubectl version --client
What the Script Does¶
The setup-docker-ci-secrets.sh script will:
- Check CLI tools - Verifies all required tools are installed
- Authenticate with Google Cloud - Sets up gcloud authentication
- Create service account - Creates
github-actions-docker@kame-457417.iam.gserviceaccount.com - Grant permissions - Adds Artifact Registry writer role
- Create service account key - Generates JSON key file
- Setup Artifact Registry - Creates
kame-house-imagesrepository if needed - Authenticate with GitHub - Sets up gh CLI authentication
- Set GitHub secrets - Creates
GCP_SERVICE_ACCOUNT_KEYsecret - Optional: Set DATABASE_URL - Prompts for database connection string
- Optional: Create Kubernetes secrets - Sets up Docker registry secret for deployments
- Cleanup - Securely removes local key files
- Verify setup - Tests all connections
Interactive Prompts¶
The script will ask you:
- Do you need to authenticate with gcloud? (if not already authenticated)
- Do you want to set a DATABASE_URL secret? (optional for build-time database access)
- Do you want to create Kubernetes secrets for deployment? (optional, for pull secret)
- Which kubectl context to use? (if setting up K8s secrets)
- What namespace to use? (default: portfolio)
- Delete local key file? (recommended for security)
Manual Commands (Alternative)¶
If you prefer to run commands manually instead of using the script:
Click to expand manual commands
### 1. Create Service Accountgcloud iam service-accounts create github-actions-docker \
--display-name="GitHub Actions Docker CI" \
--description="Service account for GitHub Actions to push Docker images"
gcloud projects add-iam-policy-binding kame-457417 \
--member="serviceAccount:github-actions-docker@kame-457417.iam.gserviceaccount.com" \
--role="roles/artifactregistry.writer"
Verification¶
After running the script, verify the setup:
GitHub Secrets¶
Google Cloud¶
gcloud iam service-accounts list --filter="github-actions-docker"
gcloud artifacts repositories list --location=us-central1
Test Docker Push (Local)¶
gcloud auth configure-docker us-central1-docker.pkg.dev
docker tag your-image:latest us-central1-docker.pkg.dev/kame-457417/kame-house-images/portfolio:test
docker push us-central1-docker.pkg.dev/kame-457417/kame-house-images/portfolio:test
Troubleshooting¶
Common Issues¶
gcloud not authenticated
GitHub CLI not authenticated
Permission denied
# Ensure you have the necessary IAM permissions in the GCP project
# You need at least:
# - Service Account Admin
# - IAM Admin
# - Artifact Registry Admin
Script permission error
Security Notes¶
- The script creates minimal-privilege service accounts
- Service account keys are automatically cleaned up
- All secrets are stored securely in GitHub
- The script follows Google Cloud security best practices
Next Steps¶
After running the setup script:
- Push code to
main,develop, orstagingbranch - Monitor the GitHub Actions workflow at: https://github.com/ianlintner/portfolio/actions
- Images will be available at:
us-central1-docker.pkg.dev/kame-457417/kame-house-images/portfolio:tagname
The CI/CD pipeline is now fully configured and ready to build and push Docker images automatically!