Skip to content

Commit 3122af3

Browse files
committed
feat: Update dev/qa deployments to use variable passing from compliance-cli
- Modified dev.yaml and qa.yaml to use substitution variables - Updated compliance-cli to trigger builds with proper substitutions - Added triggerBuild functions to pass configuration dynamically - Aligned dev/qa deployment pattern with preview deployments
1 parent ac03444 commit 3122af3

4 files changed

Lines changed: 143 additions & 3 deletions

File tree

build-and-push.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ echo "Building multi-arch Docker image: ${FULL_IMAGE}"
1212
echo "Platforms: linux/amd64, linux/arm64"
1313

1414
# Ensure buildx is available and create/use builder
15-
if ! docker buildx ls | grep -q multiarch-builder; then
15+
if ! docker buildx ls | grep -q orbstack-builder; then
1616
echo "Creating buildx builder..."
17-
docker buildx create --name multiarch-builder --use
17+
docker buildx create --name orbstack-builder --driver docker-container --use
1818
else
1919
echo "Using existing buildx builder..."
20-
docker buildx use multiarch-builder
20+
docker buildx use orbstack-builder
2121
fi
2222

2323
# Build and push in one step (buildx requires --push for multi-arch)

internal/deploy/deploy.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"os/exec"
77
"strings"
8+
"time"
89
)
910

1011
// Deploy executes the deployment
@@ -165,4 +166,130 @@ func buildDeployParams(config *Config) string {
165166
params = append(params, fmt.Sprintf("CLUSTER_NAME=%s", clusterName))
166167

167168
return strings.Join(params, ",")
169+
}
170+
171+
// triggerBuild triggers a Cloud Build for the specified environment
172+
func triggerBuild(config *Config, environment string) error {
173+
fmt.Printf("Triggering %s build...\n", environment)
174+
175+
// Build substitutions
176+
substitutions := []string{
177+
fmt.Sprintf("_PROJECT_ID=%s", config.ProjectID),
178+
fmt.Sprintf("_REGION=%s", config.Region),
179+
fmt.Sprintf("_IMAGE_REPO=%s-images", config.AppConfig.App),
180+
fmt.Sprintf("_CACHE_REPO=%s-cache", config.AppConfig.App),
181+
fmt.Sprintf("_IMAGE_NAME=%s", config.AppConfig.App),
182+
fmt.Sprintf("_IMAGE_PREFIX=%s", environment),
183+
fmt.Sprintf("COMMIT_SHA=%s", config.CommitSHA),
184+
fmt.Sprintf("SHORT_SHA=%s", config.ShortSHA),
185+
}
186+
187+
// Build gcloud command
188+
triggerName := fmt.Sprintf("%s-%s-trigger", config.AppConfig.App, environment)
189+
args := []string{
190+
"builds", "triggers", "run", triggerName,
191+
"--region=" + config.Region,
192+
"--project=" + config.ProjectID,
193+
"--branch=master",
194+
}
195+
196+
// Add substitutions
197+
for _, sub := range substitutions {
198+
args = append(args, "--substitutions="+sub)
199+
}
200+
201+
cmd := exec.Command("gcloud", args...)
202+
cmd.Stdout = os.Stdout
203+
cmd.Stderr = os.Stderr
204+
205+
if err := cmd.Run(); err != nil {
206+
return fmt.Errorf("failed to trigger build: %w", err)
207+
}
208+
209+
// Wait for build to complete
210+
fmt.Println("Waiting for build to complete...")
211+
return waitForBuild(config, triggerName)
212+
}
213+
214+
// triggerBuildWithTag triggers a Cloud Build for QA with tag
215+
func triggerBuildWithTag(config *Config, environment string, tagName string) error {
216+
fmt.Printf("Triggering %s build with tag %s...\n", environment, tagName)
217+
218+
// Build substitutions
219+
substitutions := []string{
220+
fmt.Sprintf("_PROJECT_ID=%s", config.ProjectID),
221+
fmt.Sprintf("_REGION=%s", config.Region),
222+
fmt.Sprintf("_IMAGE_REPO=%s-images", config.AppConfig.App),
223+
fmt.Sprintf("_CACHE_REPO=%s-cache", config.AppConfig.App),
224+
fmt.Sprintf("_IMAGE_NAME=%s", config.AppConfig.App),
225+
fmt.Sprintf("_IMAGE_PREFIX=%s", environment),
226+
fmt.Sprintf("COMMIT_SHA=%s", config.CommitSHA),
227+
fmt.Sprintf("SHORT_SHA=%s", config.ShortSHA),
228+
fmt.Sprintf("TAG_NAME=%s", tagName),
229+
}
230+
231+
// Build gcloud command for QA (uses tag trigger)
232+
triggerName := fmt.Sprintf("%s-qa-deployment", config.AppConfig.App)
233+
args := []string{
234+
"builds", "triggers", "run", triggerName,
235+
"--region=" + config.Region,
236+
"--project=" + config.ProjectID,
237+
"--tag=" + tagName,
238+
}
239+
240+
// Add substitutions
241+
for _, sub := range substitutions {
242+
args = append(args, "--substitutions="+sub)
243+
}
244+
245+
cmd := exec.Command("gcloud", args...)
246+
cmd.Stdout = os.Stdout
247+
cmd.Stderr = os.Stderr
248+
249+
if err := cmd.Run(); err != nil {
250+
return fmt.Errorf("failed to trigger build: %w", err)
251+
}
252+
253+
// Wait for build to complete
254+
fmt.Println("Waiting for build to complete...")
255+
return waitForBuild(config, triggerName)
256+
}
257+
258+
// waitForBuild waits for a Cloud Build to complete
259+
func waitForBuild(config *Config, triggerName string) error {
260+
maxAttempts := 60 // 30 minutes with 30 second intervals
261+
262+
for i := 0; i < maxAttempts; i++ {
263+
// Get latest build status
264+
args := []string{
265+
"builds", "list",
266+
"--region=" + config.Region,
267+
"--project=" + config.ProjectID,
268+
"--limit=1",
269+
"--filter=substitutions.TRIGGER_NAME:" + triggerName,
270+
"--format=value(status)",
271+
}
272+
273+
cmd := exec.Command("gcloud", args...)
274+
output, err := cmd.Output()
275+
if err != nil {
276+
return fmt.Errorf("failed to get build status: %w", err)
277+
}
278+
279+
status := strings.TrimSpace(string(output))
280+
281+
switch status {
282+
case "SUCCESS":
283+
fmt.Println("✅ Build completed successfully")
284+
return nil
285+
case "FAILURE", "TIMEOUT", "CANCELLED":
286+
return fmt.Errorf("build failed with status: %s", status)
287+
default:
288+
// Still running
289+
fmt.Printf("Build status: %s - waiting...\n", status)
290+
time.Sleep(30 * time.Second)
291+
}
292+
}
293+
294+
return fmt.Errorf("build timed out after 30 minutes")
168295
}

internal/deploy/dev.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func NewDevCommand(appConfig *config.AppConfig) *cobra.Command {
5858
deployConfig.ReleaseName = fmt.Sprintf("dev-%s", deployConfig.ShortSHA)
5959
}
6060

61+
// Trigger Cloud Build with substitutions
62+
if err := triggerBuild(deployConfig, "dev"); err != nil {
63+
return fmt.Errorf("failed to trigger build: %w", err)
64+
}
65+
6166
return Deploy(deployConfig)
6267
},
6368
}

internal/deploy/qa.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ func NewQACommand(appConfig *config.AppConfig) *cobra.Command {
5757
deployConfig.ReleaseName = fmt.Sprintf("qa-%s", deployConfig.ShortSHA)
5858
}
5959

60+
// Get TAG_NAME from environment
61+
tagName := getStringValue(cmd, "tag", "TAG_NAME")
62+
63+
// Trigger Cloud Build with substitutions
64+
if err := triggerBuildWithTag(deployConfig, "qa", tagName); err != nil {
65+
return fmt.Errorf("failed to trigger build: %w", err)
66+
}
67+
6068
return Deploy(deployConfig)
6169
},
6270
}

0 commit comments

Comments
 (0)