MCPcopy Index your code
hub / github.com/coder/coder / init

Method init

provisionerd/runner/init.go:15–158  ·  view source on GitHub ↗

nolint:revive

(ctx context.Context, omitModules bool, templateArchive []byte, moduleTar []byte)

Source from the content-addressed store, hash-verified

13
14//nolint:revive
15func (r *Runner) init(ctx context.Context, omitModules bool, templateArchive []byte, moduleTar []byte) (*sdkproto.InitComplete, *proto.FailedJob) {
16 ctx, span := r.startTrace(ctx, tracing.FuncName())
17 defer span.End()
18
19 // If `moduleTar` is populated, `init` will send it over in multiple parts. This
20 // It must be called before the initial request to populate the correct hash if
21 // there is data to send. This is safe to call on nil or empty slices.
22 data, chunks, err := sdkproto.BytesToDataUpload(sdkproto.DataUploadType_UPLOAD_TYPE_MODULE_FILES, moduleTar)
23 if err != nil {
24 return nil, r.failedJobf("prepare module files upload: %v", err)
25 }
26
27 hash := []byte{}
28 if len(moduleTar) > 0 {
29 hash = data.DataHash
30 }
31
32 err = r.session.Send(&sdkproto.Request{Type: &sdkproto.Request_Init{Init: &sdkproto.InitRequest{
33 TemplateSourceArchive: templateArchive,
34 OmitModuleFiles: omitModules,
35 InitialModuleTarHash: hash,
36 }}})
37 if err != nil {
38 return nil, r.failedJobf("send init request: %v", err)
39 }
40
41 // If the module tar exists, send over the data.
42 if len(moduleTar) > 0 {
43 err = r.session.Send(&sdkproto.Request{
44 Type: &sdkproto.Request_File{
45 File: &sdkproto.FileUpload{
46 Type: &sdkproto.FileUpload_DataUpload{
47 DataUpload: data,
48 },
49 },
50 },
51 })
52 if err != nil {
53 return nil, r.failedJobf("send module files data upload: %v", err)
54 }
55
56 for _, c := range chunks {
57 err = r.session.Send(&sdkproto.Request{
58 Type: &sdkproto.Request_File{
59 File: &sdkproto.FileUpload{
60 Type: &sdkproto.FileUpload_ChunkPiece{
61 ChunkPiece: c,
62 },
63 },
64 },
65 })
66 if err != nil {
67 return nil, r.failedJobf("send module files chunk: %v", err)
68 }
69 }
70 }
71
72 nevermind := make(chan struct{})

Callers 4

runTemplateImportMethod · 0.95
runTemplateDryRunMethod · 0.95
runWorkspaceBuildMethod · 0.95
InitMethod · 0.45

Calls 12

startTraceMethod · 0.95
failedJobfMethod · 0.95
logProvisionerJobLogMethod · 0.95
queueLogMethod · 0.95
AddMethod · 0.95
CompleteMethod · 0.95
FuncNameFunction · 0.92
SendMethod · 0.65
RecvMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by 1

InitMethod · 0.36