Skip to content

Commit

Permalink
Merge pull request #194 from FGRCL/192-rebuild
Browse files Browse the repository at this point in the history
192 Rebuild for cloud version
  • Loading branch information
FGRCL authored Aug 15, 2024
2 parents 9df49e8 + 81b5761 commit aa67b80
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
24 changes: 14 additions & 10 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
11 changes: 9 additions & 2 deletions frontend/server/anvil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion frontend/server/pipelineSerialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
7 changes: 6 additions & 1 deletion zjson/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit aa67b80

Please sign in to comment.