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

192 Rebuild for cloud version #194

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
10 changes: 8 additions & 2 deletions frontend/server/pipelineSerialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,20 @@ async function uploadBlocks(
return pipelineSpecs;
}

async function uploadBuildContexts(configuration, pipelineSpecs, buffer, rebuild) {
async function uploadBuildContexts(
configuration,
pipelineSpecs,
buffer,
rebuild,
) {
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
Loading