Add CadQuery customizer (#547)
* Rough changes to make the CadQuery integration work with the customizer * Tweak runCQ * Switched to Anaconda * Cleaned up code * Update CadHub after anaconda Related to #547 * Add final tweaks to CQ customizer * Separated out customizer.json from params.json * Changes after discussing CadHub integration * linting runCQ Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit was merged in pull request #547.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
FROM public.ecr.aws/lts/ubuntu:20.04_stable
|
||||
|
||||
ENV PATH="/root/miniconda3/bin:${PATH}"
|
||||
ARG PATH="/root/miniconda3/bin:${PATH}"
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update -qq
|
||||
RUN apt-get update --fix-missing -qq
|
||||
RUN apt-get -y -qq install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates xvfb
|
||||
RUN apt-get update -qq
|
||||
RUN apt-get install -y wget
|
||||
@@ -21,7 +22,9 @@ RUN apt-get update && \
|
||||
cmake \
|
||||
unzip \
|
||||
automake autoconf libtool \
|
||||
libcurl4-openssl-dev
|
||||
libcurl4-openssl-dev \
|
||||
curl \
|
||||
git
|
||||
|
||||
# Add the lambda emulator for local dev, (see entrypoint.sh for where it's used),
|
||||
# I have the file locally (gitignored) to speed up build times (as it downloads everytime),
|
||||
@@ -35,15 +38,23 @@ COPY package*.json /var/task/
|
||||
RUN npm install
|
||||
RUN npm install aws-lambda-ric@1.0.0
|
||||
|
||||
# Install Miniconda
|
||||
RUN wget \
|
||||
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
|
||||
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
|
||||
&& rm -f Miniconda3-latest-Linux-x86_64.sh
|
||||
RUN conda --version
|
||||
|
||||
# Install CadQuery
|
||||
RUN conda install -c cadquery -c conda-forge cadquery=master ocp=7.5.2 python=3.8
|
||||
RUN conda info
|
||||
|
||||
# Get a copy of cq-cli from GitHub
|
||||
RUN git clone https://github.com/CadQuery/cq-cli.git
|
||||
|
||||
# Get the distribution copy of cq-cli
|
||||
RUN apt-get install -y libglew2.1
|
||||
RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.2-beta.2/cq-cli-Linux-x86_64.zip
|
||||
# Comment the entry above out and uncomment the one below to revert to the stable release
|
||||
# RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.1.0/cq-cli-Linux-x86_64.zip
|
||||
RUN unzip cq-cli-Linux-x86_64.zip
|
||||
|
||||
RUN chmod +x cq-cli/cq-cli
|
||||
RUN echo "cadhub-concat-split" > /var/task/cadhub-concat-split
|
||||
|
||||
# using built javascript from dist
|
||||
|
||||
@@ -1,31 +1,45 @@
|
||||
import { writeFiles, runCommand } from '../common/utils'
|
||||
import { nanoid } from 'nanoid'
|
||||
import { readFile } from 'fs/promises'
|
||||
|
||||
export const runCQ = async ({
|
||||
file,
|
||||
settings: { deflection = 0.3 } = {},
|
||||
settings: { deflection = 0.3, parameters } = {},
|
||||
} = {}) => {
|
||||
const tempFile = await writeFiles(
|
||||
[{ file, fileName: 'main.py' }],
|
||||
[
|
||||
{ file, fileName: 'main.py' },
|
||||
{
|
||||
file: JSON.stringify(parameters),
|
||||
fileName: 'params.json',
|
||||
},
|
||||
],
|
||||
'a' + nanoid() // 'a' ensure nothing funny happens if it start with a bad character like "-", maybe I should pick a safer id generator :shrug:
|
||||
)
|
||||
const fullPath = `/tmp/${tempFile}/output.gz`
|
||||
const stlPath = `/tmp/${tempFile}/output.stl`
|
||||
const customizerPath = `/tmp/${tempFile}/customizer.json`
|
||||
const command = [
|
||||
`cq-cli/cq-cli`,
|
||||
`./cq-cli/cq-cli.py`,
|
||||
`--codec stl`,
|
||||
`--infile /tmp/${tempFile}/main.py`,
|
||||
`--outfile ${stlPath}`,
|
||||
`--outputopts "deflection:${deflection};angularDeflection:${deflection};"`,
|
||||
`--params /tmp/${tempFile}/params.json`,
|
||||
`--getparams ${customizerPath}`,
|
||||
].join(' ')
|
||||
console.log('command', command)
|
||||
let consoleMessage = ''
|
||||
try {
|
||||
consoleMessage = await runCommand(command, 30000)
|
||||
const params = JSON.parse(
|
||||
await readFile(customizerPath, { encoding: 'ascii' })
|
||||
)
|
||||
await writeFiles(
|
||||
[
|
||||
{
|
||||
file: JSON.stringify({
|
||||
customizerParams: params,
|
||||
consoleMessage,
|
||||
type: 'stl',
|
||||
}),
|
||||
@@ -41,6 +55,6 @@ export const runCQ = async ({
|
||||
)
|
||||
return { consoleMessage, fullPath }
|
||||
} catch (error) {
|
||||
return { error: consoleMessage, fullPath }
|
||||
return { error: consoleMessage || error, fullPath }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM public.ecr.aws/lts/ubuntu:20.04_stable
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
## install things needed to run openscad (xvfb is an important one)
|
||||
RUN apt-get update -qq
|
||||
RUN apt-get update --fix-missing -qq
|
||||
# double check this below, I'm not sure we need inkscape etc
|
||||
RUN apt-get -y -qq install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates xvfb imagemagick unzip inkscape
|
||||
RUN apt-get install -y curl wget
|
||||
|
||||
Reference in New Issue
Block a user