MCPcopy Create free account
hub / github.com/serverless/serverless / buildImage

Method buildImage

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

* Builds a Docker image * @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 {string} [params.do

({
    containerName,
    containerPath,
    imageUri,
    dockerFileString = null,
    buildArgs = {},
    buildOptions = [],
    aiFramework = null,
    platform = 'linux/amd64',
    builder = null,
  })

Source from the content-addressed store, hash-verified

146 * @returns {Promise<string>} The URI of the built image
147 */
148 async buildImage({
149 containerName,
150 containerPath,
151 imageUri,
152 dockerFileString = null,
153 buildArgs = {},
154 buildOptions = [],
155 aiFramework = null,
156 platform = 'linux/amd64',
157 builder = null,
158 }) {
159 try {
160 if (aiFramework === 'mastra') {
161 dockerFileString = `
162# Builder stage: compile TypeScript and build the application
163FROM node:lts-alpine AS builder
164
165# Set working directory
166WORKDIR /app
167
168# Copy dependency manifests for layer caching
169COPY package.json package-lock.json ./
170
171# Install all dependencies (including dev dependencies for build)
172RUN npm i
173
174# Copy configuration files
175COPY tsconfig.json ./
176
177# Copy source code
178COPY src/ ./src/
179
180# Build the application using mastra as specified in package.json
181RUN npx mastra build
182
183# Production stage: lightweight image with only necessary components
184FROM node:lts-alpine AS production
185
186# Set environment variables
187ENV NODE_ENV=production
188
189# Set working directory
190WORKDIR /app
191
192# Create a non-root user for security
193RUN addgroup -S appgroup && \
194 adduser -S -G appgroup appuser
195
196# Copy the built application from the builder stage
197COPY --from=builder /app/.mastra/output /app
198
199# Set ownership to non-root user
200RUN chown -R appuser:appgroup /app
201
202# Switch to non-root user
203USER appuser
204
205# Expose port if needed (uncomment and set the appropriate port)

Callers 8

#initializeProxyMethod · 0.45
#performRebuildMethod · 0.45

Calls 3

#buildUsingBuildPackMethod · 0.95
debugMethod · 0.80

Tested by

no test coverage detected