Run curv inside of /tmp

When exporting an stl it writes temporary files which is not allowed
when deployed to aws unless it's in temp.
This commit is contained in:
Kurt Hutten
2021-11-22 20:05:10 +11:00
parent 0face9b9c1
commit fe059384d3
11 changed files with 41 additions and 39 deletions

View File

@@ -9,12 +9,13 @@ const stl = async (req, _context, callback) => {
console.log('eventBody', eventBody)
const { file, settings } = JSON.parse(eventBody)
const { error, consoleMessage, fullPath } = await runCQ({ file, settings })
const { error, consoleMessage, fullPath, tempFile } = await runCQ({ file, settings })
await storeAssetAndReturnUrl({
error,
callback,
fullPath,
consoleMessage,
tempFile
})
}

View File

@@ -53,7 +53,7 @@ export const runCQ = async ({
15000,
true
)
return { consoleMessage, fullPath }
return { consoleMessage, fullPath, tempFile }
} catch (error) {
return { error: consoleMessage || error, fullPath }
}

View File

@@ -104,11 +104,13 @@ export async function storeAssetAndReturnUrl({
callback,
fullPath,
consoleMessage,
tempFile
}: {
error: string
callback: Function
fullPath: string
consoleMessage: string
tempFile: string
}) {
if (error) {
const response = {

View File

@@ -9,7 +9,7 @@ const preview = async (req, _context, callback) => {
console.log('eventBody', eventBody)
const { file, settings } = JSON.parse(eventBody)
const { error, consoleMessage, fullPath } = await runCurv({
const { error, consoleMessage, fullPath, tempFile } = await runCurv({
file,
settings,
})
@@ -18,6 +18,7 @@ const preview = async (req, _context, callback) => {
callback,
fullPath,
consoleMessage,
tempFile,
})
}
@@ -28,7 +29,7 @@ const stl = async (req, _context, callback) => {
console.log(eventBody, 'eventBody')
const { file, settings } = JSON.parse(eventBody)
const { error, consoleMessage, fullPath } = await stlExport({
const { error, consoleMessage, fullPath, tempFile } = await stlExport({
file,
settings,
})
@@ -37,6 +38,7 @@ const stl = async (req, _context, callback) => {
callback,
fullPath,
consoleMessage,
tempFile,
})
}

View File

@@ -18,6 +18,7 @@ export const runCurv = async ({
consoleMessage?: string
fullPath?: string
customizerPath?: string
tempFile?: string
}> => {
const tempFile = await writeFiles(
[
@@ -67,7 +68,7 @@ export const runCurv = async ({
`cat ${imPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
15000
)
return { consoleMessage, fullPath, customizerPath }
return { consoleMessage, fullPath, customizerPath, tempFile }
} catch (dirtyError) {
return { error: dirtyError }
}
@@ -90,11 +91,12 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
const fullPath = `/tmp/${tempFile}/output.gz`
const stlPath = `/tmp/${tempFile}/output.stl`
const command = [
'curv',
'(cd /tmp && curv',
'-o', stlPath,
'-O jit',
'-O vsize=0.4',
'-O vsize=0.6',
`/tmp/${tempFile}/main.curv`,
')',
].join(' ')
try {
@@ -113,10 +115,10 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
tempFile
)
await runCommand(
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath} && rm ${stlPath}`,
15000
)
return { consoleMessage, fullPath }
return { consoleMessage, fullPath, tempFile }
} catch (error) {
return { error, fullPath }
}

View File

@@ -9,7 +9,7 @@ const preview = async (req, _context, callback) => {
console.log('eventBody', eventBody)
const { file, settings } = JSON.parse(eventBody)
const { error, consoleMessage, fullPath } = await runScad({
const { error, consoleMessage, fullPath, tempFile } = await runScad({
file,
settings,
})
@@ -18,6 +18,7 @@ const preview = async (req, _context, callback) => {
callback,
fullPath,
consoleMessage,
tempFile,
})
}
@@ -28,7 +29,7 @@ const stl = async (req, _context, callback) => {
console.log(eventBody, 'eventBody')
const { file, settings } = JSON.parse(eventBody)
const { error, consoleMessage, fullPath } = await stlExport({
const { error, consoleMessage, fullPath, tempFile } = await stlExport({
file,
settings,
})
@@ -37,6 +38,7 @@ const stl = async (req, _context, callback) => {
callback,
fullPath,
consoleMessage,
tempFile,
})
}

View File

@@ -25,6 +25,7 @@ export const runScad = async ({
consoleMessage?: string
fullPath?: string
customizerPath?: string
tempFile?: string
}> => {
const tempFile = await writeFiles(
[
@@ -88,7 +89,7 @@ export const runScad = async ({
`cat ${imPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
15000
)
return { consoleMessage, fullPath, customizerPath }
return { consoleMessage, fullPath, customizerPath, tempFile }
} catch (dirtyError) {
return { error: cleanOpenScadError(dirtyError) }
}
@@ -143,7 +144,7 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
15000
)
return { consoleMessage, fullPath, customizerPath }
return { consoleMessage, fullPath, customizerPath, tempFile }
} catch (error) {
return { error, fullPath }
}

View File

@@ -87,6 +87,7 @@ functions:
timeout: 30
environment:
BUCKET: cad-preview-bucket-prod-001
cadquerystl:
image:
name: cadqueryimage
@@ -102,6 +103,7 @@ functions:
timeout: 30
environment:
BUCKET: cad-preview-bucket-prod-001
curvpreview:
image:
name: curvimage
@@ -115,8 +117,19 @@ functions:
method: post
cors: true
timeout: 25
environment:
BUCKET: cad-preview-bucket-prod-001
curvstl:
image:
name: curvimage
command:
- js/curv.stl
entryPoint:
- '/entrypoint.sh'
events:
- http:
path: curv/stl
method: post
cors: true
timeout: 30
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details