MCPcopy Create free account
hub / github.com/serverless/serverless / #buildUsingBuildPack

Method #buildUsingBuildPack

packages/util/src/docker/index.js:383–474  ·  view source on GitHub ↗

* Build Docker image using Buildpacks * @param {Object} params - Build parameters * @param {string} params.containerName - Name of the container * @param {string} params.containerPath - Path to container source * @param {string} params.imageUri - Full image URI with tag * @param {stri

({
    containerName,
    containerPath,
    imageUri,
    platform = 'linux/amd64',
    builder = null,
  })

Source from the content-addressed store, hash-verified

381 * @returns {Promise<string>}
382 */
383 async #buildUsingBuildPack({
384 containerName,
385 containerPath,
386 imageUri,
387 platform = 'linux/amd64',
388 builder = null,
389 }) {
390 const buildOutput = []
391
392 // Default to Google Cloud buildpacks builder for backward compatibility
393 // Use heroku/builder:24 for ARM64 support
394 const builderImage =
395 builder ||
396 'gcr.io/buildpacks/builder@sha256:5977b4bd47d3e9ff729eefe9eb99d321d4bba7aa3b14986323133f40b622aef1'
397
398 this.logger.debug(
399 `${containerName}: Building Docker image using Buildpacks for platform ${platform} with builder ${builderImage}. Container path: ${containerPath}, Image URI: ${imageUri}`,
400 )
401
402 // Read frameworkId from .serverlessrc for buildpack volume caching
403 let volumeKey = null
404 try {
405 const rcConfig = await getRcConfig('serverless')
406 volumeKey = rcConfig?.frameworkId || null
407 } catch {
408 // .serverlessrc not available, skip
409 }
410
411 // Build pack command arguments
412 const packArgs = [
413 'run',
414 '--rm',
415 ...(volumeKey ? ['-e', `PACK_VOLUME_KEY=${volumeKey}`] : []),
416 '-v',
417 '/var/run/docker.sock:/var/run/docker.sock',
418 '-v',
419 `${containerPath}:/workspace`,
420 '-w',
421 '/workspace',
422 'buildpacksio/pack',
423 'build',
424 imageUri,
425 '--builder',
426 builderImage,
427 '--trust-builder',
428 '--cache',
429 `type=build;format=volume;name=sls-${containerName}-build-cache`,
430 '--cache',
431 `type=launch;format=volume;name=sls-${containerName}-launch-cache`,
432 ]
433
434 // Add platform flag only if using a builder that supports it (like heroku/builder:24)
435 if (builder && platform) {
436 packArgs.push('--platform', platform)
437 }
438
439 return await new Promise((resolve, reject) => {
440 const packProcess = spawn('docker', packArgs)

Callers 1

buildImageMethod · 0.95

Calls 4

#handleBuildOutputMethod · 0.95
#handleBuildFailureMethod · 0.95
getRcConfigFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected