| 179 | } |
| 180 | |
| 181 | func (f *Funclet) prepareUserCode(ctx *funcletCtx.Context, code *api.CodeStorage, codeSha256, hexCodeSha256 string) (string, error) { |
| 182 | destination := f.GetUserCodePath(hexCodeSha256) |
| 183 | codeFolder := f.Options.CachePath |
| 184 | defer ctx.Logger.TimeTrack(time.Now(), "Prepare user code", |
| 185 | zap.String("codesha256", codeSha256), |
| 186 | zap.String("hexcode", hexCodeSha256), |
| 187 | zap.String("repositoryType", "bos"), |
| 188 | ) |
| 189 | |
| 190 | // serial fetch code |
| 191 | prepareCodeChain, isMaster := f.HandlingChanMap.GetChan(hexCodeSha256) |
| 192 | if !isMaster { |
| 193 | <-prepareCodeChain |
| 194 | } else { |
| 195 | defer f.HandlingChanMap.CloseChan(hexCodeSha256) |
| 196 | } |
| 197 | |
| 198 | // check code |
| 199 | foundCode := f.CodeManager.FindCode(codeFolder, hexCodeSha256) |
| 200 | foundCodeCompleteTag := f.CodeManager.FindCodeCompeleteTag(codeFolder, hexCodeSha256) |
| 201 | if foundCode && foundCodeCompleteTag { |
| 202 | ctx.Logger.V(6).Infof("Code cache %s found", destination) |
| 203 | return destination, nil |
| 204 | } |
| 205 | |
| 206 | zipFilePath, err := f.CodeManager.FetchCode(ctx, code) |
| 207 | if err != nil { |
| 208 | return "", err |
| 209 | } |
| 210 | defer os.Remove(zipFilePath) |
| 211 | |
| 212 | // check CodeSha256 |
| 213 | if !f.CodeManager.CheckCode(ctx, zipFilePath, codeSha256) { |
| 214 | ctx.Logger.Warnf("Code %s checksum failed", zipFilePath) |
| 215 | return "", errors.New("CodeSha256 checksum failed") |
| 216 | } |
| 217 | |
| 218 | // unzip code |
| 219 | if err := f.CodeManager.UnzipCode(ctx, zipFilePath, destination); err != nil { |
| 220 | return "", err |
| 221 | } |
| 222 | |
| 223 | // mark as finished |
| 224 | if err := f.CodeManager.CreateCodeCompeleteTag(codeFolder, hexCodeSha256); err != nil { |
| 225 | return "", err |
| 226 | } |
| 227 | return destination, nil |
| 228 | } |
| 229 | |
| 230 | func (f *Funclet) prepareRuntimeConf(ctx *funcletCtx.Context, warmUpContainerArgs *api.WarmUpContainerArgs) (string, error) { |
| 231 | confPath := f.GetContainerConfPath(ctx.Container.Hostname) |