MCPcopy Create free account
hub / github.com/vercel/vercel / assertBuildContainerStorage

Function assertBuildContainerStorage

packages/container/src/storage-driver.ts:173–258  ·  view source on GitHub ↗
(
  log: (message: string) => void = () => {}
)

Source from the content-addressed store, hash-verified

171 * No-op outside the build container.
172 */
173export async function assertBuildContainerStorage(
174 log: (message: string) => void = () => {}
175): Promise<void> {
176 if (!isBuildContainer()) {
177 return;
178 }
179 if (readString(process.env.VERCEL_VCR_DOCKER_STORAGE_DRIVER)) {
180 // Operator explicitly chose a driver; don't second-guess it.
181 return;
182 }
183
184 const strict = Boolean(readString(process.env.VERCEL_VCR_STRICT_STORAGE));
185
186 let storeInfo: BuildahStoreInfo | undefined;
187 try {
188 storeInfo = await readBuildahStoreInfo();
189 } catch (err) {
190 // `buildah info` itself failing (e.g. overlay can't init on this fs) is the
191 // very condition we're reporting on; surface it but don't block by default.
192 const message = `Could not verify buildah storage via \`buildah info\`: ${
193 (err as Error).message
194 }`;
195 if (strict) {
196 throw new Error(message);
197 }
198 log(message);
199 return;
200 }
201 if (!storeInfo) {
202 const message =
203 'Could not verify buildah storage: `buildah info` returned no store data.';
204 if (strict) {
205 throw new Error(message);
206 }
207 log(message);
208 return;
209 }
210
211 const problems: string[] = [];
212 if (storeInfo.driver !== REQUIRED_BUILD_CONTAINER_DRIVER) {
213 problems.push(
214 `storage driver is "${storeInfo.driver}", expected ` +
215 `"${REQUIRED_BUILD_CONTAINER_DRIVER}"`
216 );
217 }
218 if (storeInfo.graphRoot !== BUILDAH_GRAPH_ROOT) {
219 problems.push(
220 `graphRoot is "${storeInfo.graphRoot}", expected the mounted ` +
221 `volume "${BUILDAH_GRAPH_ROOT}"`
222 );
223 }
224 // The volume is XFS; an overlay backing fs would mean we're on the cell
225 // rootfs, not the mounted volume (overlay-on-overlay).
226 if (storeInfo.backingFs && storeInfo.backingFs === 'overlayfs') {
227 problems.push(
228 `backing filesystem is "${storeInfo.backingFs}" (the overlay rootfs), ` +
229 'not the mounted volume'
230 );

Callers 1

verifyStorageFunction · 0.90

Calls 5

isBuildContainerFunction · 0.90
readStringFunction · 0.90
readBuildahStoreInfoFunction · 0.85
pushMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected