(ctx context.Context)
| 882 | } |
| 883 | |
| 884 | func (r *Runner) runWorkspaceBuild(ctx context.Context) (*proto.CompletedJob, *proto.FailedJob) { |
| 885 | ctx, span := r.startTrace(ctx, tracing.FuncName()) |
| 886 | defer span.End() |
| 887 | |
| 888 | var ( |
| 889 | applyStage string |
| 890 | commitQuota bool |
| 891 | ) |
| 892 | switch r.job.GetWorkspaceBuild().Metadata.WorkspaceTransition { |
| 893 | case sdkproto.WorkspaceTransition_START: |
| 894 | applyStage = "Starting workspace" |
| 895 | commitQuota = true |
| 896 | case sdkproto.WorkspaceTransition_STOP: |
| 897 | applyStage = "Stopping workspace" |
| 898 | commitQuota = true |
| 899 | case sdkproto.WorkspaceTransition_DESTROY: |
| 900 | applyStage = "Destroying workspace" |
| 901 | } |
| 902 | |
| 903 | failedJob := r.configure(&sdkproto.Config{ |
| 904 | ProvisionerLogLevel: r.job.GetWorkspaceBuild().LogLevel, |
| 905 | TemplateId: strings2.EmptyToNil(r.job.GetWorkspaceBuild().Metadata.TemplateId), |
| 906 | TemplateVersionId: strings2.EmptyToNil(r.job.GetWorkspaceBuild().Metadata.TemplateVersionId), |
| 907 | }) |
| 908 | if failedJob != nil { |
| 909 | return nil, failedJob |
| 910 | } |
| 911 | |
| 912 | // timings collects all timings from each phase of the build |
| 913 | timings := make([]*sdkproto.Timing, 0) |
| 914 | |
| 915 | var cachedModulesTar []byte |
| 916 | // Download modules if cached in coderd |
| 917 | if r.job.GetWorkspaceBuild().Metadata.TemplateVersionModulesFile != "" { |
| 918 | fileID, err := uuid.Parse(r.job.GetWorkspaceBuild().Metadata.TemplateVersionModulesFile) |
| 919 | if err != nil { |
| 920 | return nil, r.failedWorkspaceBuildf("invalid template version modules file ID: %s", err) |
| 921 | } |
| 922 | // Download the module tar file |
| 923 | cachedModulesTar, err = r.fileDownloader.DownloadFile(ctx, &proto.FileRequest{ |
| 924 | FileId: fileID.String(), |
| 925 | UploadType: sdkproto.DataUploadType_UPLOAD_TYPE_MODULE_FILES, |
| 926 | }) |
| 927 | if err != nil { |
| 928 | return nil, r.failedWorkspaceBuildf("failed to download template version modules file: %s", err) |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | // Initialize the Terraform working directory |
| 933 | initComplete, failedJob := r.init(ctx, true, r.job.GetTemplateSourceArchive(), cachedModulesTar) |
| 934 | if failedJob != nil { |
| 935 | return nil, failedJob |
| 936 | } |
| 937 | if initComplete == nil { |
| 938 | return nil, r.failedWorkspaceBuildf("invalid message type received from provisioner during init") |
| 939 | } |
| 940 | // Collect init timings |
| 941 | timings = append(timings, initComplete.Timings...) |
no test coverage detected