diff --git a/executor.go b/executor.go index 762234f7..e7cb1407 100644 --- a/executor.go +++ b/executor.go @@ -888,25 +888,29 @@ func cloudExecute(pipeline *zjson.Pipeline, executionId int64, executionUuid str } } -func getBuildContextStatus(ctx context.Context, pipeline *zjson.Pipeline, organization string, cfg Config) []zjson.BuildContextStatus { - var buildContextStatus []zjson.BuildContextStatus +func getBuildContextStatus(ctx context.Context, pipeline *zjson.Pipeline, rebuild bool, organization string, cfg Config) []zjson.BuildContextStatusResponse { + var buildContextStatus []zjson.BuildContextStatusResponse for id, block := range pipeline.Pipeline { if len(block.Action.Container.Image) > 0 && !cfg.IsLocal { - status, _, err := checkImage(ctx, getImage(&block, organization), cfg) - s3Key := getKanikoBuildContextS3Key(&block) - - if err != nil { - log.Printf("failed to get build context status; err=%v", err) - return buildContextStatus + var status = false + if !rebuild { + imageStatus, _, err := checkImage(ctx, getImage(&block, organization), cfg) + if err != nil { + log.Printf("failed to get build context status; err=%v", err) + return buildContextStatus + } + status = imageStatus } - buildContextStatus = append(buildContextStatus, zjson.BuildContextStatus{ + s3Key := getKanikoBuildContextS3Key(&block) + + buildContextStatus = append(buildContextStatus, zjson.BuildContextStatusResponse{ BlockKey: id, IsUploaded: status, S3Key: s3Key, }) } else { - buildContextStatus = append(buildContextStatus, zjson.BuildContextStatus{ + buildContextStatus = append(buildContextStatus, zjson.BuildContextStatusResponse{ BlockKey: id, IsUploaded: true, S3Key: "", diff --git a/frontend/server/anvil.js b/frontend/server/anvil.js index 0bc5287d..8e1a477b 100644 --- a/frontend/server/anvil.js +++ b/frontend/server/anvil.js @@ -4,7 +4,11 @@ import { HttpMethod } from "../utils/HttpMethod"; import { buildUrl } from "../utils/urlBuilder"; import { LOCAL_DOMAINS } from "../utils/constants"; -export async function getBuildContextStatus(configuration, pipelineSpecs) { +export async function getBuildContextStatus( + configuration, + pipelineSpecs, + rebuild, +) { const response = await handleRequest( buildUrl( getScheme(configuration.anvil.host), @@ -15,7 +19,10 @@ export async function getBuildContextStatus(configuration, pipelineSpecs) { HttpMethod.POST, configuration.anvil.token, {}, - pipelineSpecs, + { + rebuild: rebuild, + pipeline: pipelineSpecs, + }, ); const body = await response.json(); diff --git a/frontend/server/pipelineSerialization.js b/frontend/server/pipelineSerialization.js index d7c16d40..58113bfa 100644 --- a/frontend/server/pipelineSerialization.js +++ b/frontend/server/pipelineSerialization.js @@ -281,10 +281,11 @@ async function uploadBuildContexts( const buildContextStatuses = await getBuildContextStatus( configuration, pipelineSpecs, + rebuild, ); await Promise.all( buildContextStatuses - .filter((status) => !status.isUploaded || rebuild) + .filter((status) => !status.isUploaded) .map((status) => [path.join(buffer, status.blockKey), status.s3Key]) .map(([blockPath, s3Key]) => uploadDirectory(s3Key, blockPath, configuration), diff --git a/main.go b/main.go index 745eda8e..e95f42e1 100644 --- a/main.go +++ b/main.go @@ -492,14 +492,14 @@ func main() { }) router.POST("/build-context-status", func(ctx *gin.Context) { prefix := getPrefix(ctx) - pipeline, err := validateJson[zjson.Pipeline](ctx.Request.Body) + request, err := validateJson[zjson.BuildContextStatusRequest](ctx.Request.Body) if err != nil { log.Printf("invalid json request; err=%v", err) ctx.String(err.Status(), err.Error()) return } - buildContextStatus := getBuildContextStatus(ctx.Request.Context(), &pipeline, prefix, config) + buildContextStatus := getBuildContextStatus(ctx.Request.Context(), &request.Pipeline, request.Rebuild, prefix, config) ctx.JSON(http.StatusOK, buildContextStatus) }) diff --git a/zjson/schema.go b/zjson/schema.go index a8e8f8b0..6df59cd6 100644 --- a/zjson/schema.go +++ b/zjson/schema.go @@ -101,7 +101,12 @@ type Execution struct { Build bool `json:"build"` } -type BuildContextStatus struct { +type BuildContextStatusRequest struct { + Rebuild bool `json:"rebuild"` + Pipeline Pipeline `json:"pipeline"` +} + +type BuildContextStatusResponse struct { BlockKey string `json:"blockKey"` IsUploaded bool `json:"isUploaded"` S3Key string `json:"s3Key"`