Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance Cloud Run deploy command with advanced configuration options #40

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Add default URL configuration for Cloud Run deployments
- Introduce new flags to control default URL settings for Cloud Run services
- Add support for enabling/disabling the default service URL
- Implement configuration options for default URL through CLI flags
- Update service definition to handle default URL annotations
- Enhance deployment flexibility with default URL management
  • Loading branch information
dijarvrella committed Feb 27, 2025
commit 909fec4d675fc631a6370e1b75b16c402d0a0635
3 changes: 3 additions & 0 deletions cmd/cloud-run/deploy.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,8 @@ Access and Traffic Configuration:
- --allow-unauthenticated Allow unauthenticated access to the service
- --no-allow-unauthenticated Require authentication for access to the service
- --ingress TYPE Set the ingress traffic settings (all, internal, internal-and-cloud-load-balancing)
- --default-url Use the default URL for the service (default)
- --no-default-url Disable the default URL for the service

Examples:
# Deploy from container image
@@ -95,6 +97,7 @@ Examples:
// Add access and traffic configuration flags
deployCmd.Flags().BoolVar(&opts.AllowUnauthenticated, "allow-unauthenticated", true, "Allow unauthenticated access to the service")
deployCmd.Flags().StringVar(&opts.Ingress, "ingress", "all", "Set the ingress traffic settings (all, internal, internal-and-cloud-load-balancing)")
deployCmd.Flags().BoolVar(&opts.DefaultURL, "default-url", true, "Use the default URL for the service")

// Flag validations
// Only one of these env var flags can be used at a time, but all are optional
1 change: 1 addition & 0 deletions cmd/cloud-run/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -35,4 +35,5 @@ type DeployOptions struct {
// Access and traffic configuration
AllowUnauthenticated bool // Whether to allow unauthenticated access (if false, --no-allow-unauthenticated)
Ingress string // Ingress setting: all, internal, or internal-and-cloud-load-balancing
DefaultURL bool // Whether to use the default URL (if false, --no-default-url)
}
24 changes: 24 additions & 0 deletions cmd/cloud-run/pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -506,6 +506,21 @@ func updateWithOptions(service *run.Service, opts config.DeployOptions) {
service.Metadata.Annotations["run.googleapis.com/ingress-status"] = "internal-and-cloud-load-balancing"
log.Println("Requiring authentication for access")
}

// Set the default URL setting
if service.Metadata.Annotations == nil {
service.Metadata.Annotations = make(map[string]string)
}

if !opts.DefaultURL {
service.Metadata.Annotations["run.googleapis.com/launch-stage"] = "BETA"
service.Metadata.Annotations["run.googleapis.com/default-url"] = "disabled"
log.Println("Disabling the default URL")
} else {
// Remove the annotation if it exists to enable default URL (which is the default behavior)
delete(service.Metadata.Annotations, "run.googleapis.com/default-url")
log.Println("Enabling the default URL")
}
}

// buildServiceDefinition creates a new Cloud Run Service object based on the
@@ -637,5 +652,14 @@ func buildServiceDefinition(projectID string, opts config.DeployOptions) run.Ser
log.Println("Requiring authentication for access")
}

// Set the default URL setting
if !opts.DefaultURL {
rService.Metadata.Annotations["run.googleapis.com/launch-stage"] = "BETA"
rService.Metadata.Annotations["run.googleapis.com/default-url"] = "disabled"
log.Println("Disabling the default URL")
} else {
log.Println("Enabling the default URL (default behavior)")
}

return rService
}