Initial cadQuery backend POC

lost of clean up work still needed.
This commit is contained in:
Kurt Hutten
2021-04-18 13:43:44 +10:00
parent 2153e5b1bf
commit 7733694032
6 changed files with 59 additions and 13 deletions

View File

@@ -17,6 +17,14 @@ app.post('/render', async (req, res) => {
res.status(data.statusCode)
res.send(data.body)
})
app.post('/cadquery', async (req, res) => {
console.log('making post request to 5060')
const { data } = await axios.post(invocationURL(5060), {
body: Buffer.from(JSON.stringify(req.body)).toString('base64'),
})
res.status(data.statusCode)
res.send(data.body)
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)

View File

@@ -8,7 +8,8 @@ RUN apt-get update -qq
RUN apt-get -y -qq install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates xvfb imagemagick unzip inkscape
RUN apt-get update -qq
# RUN apt-get install -y -qq openscad
RUN apt-get install -y curl
# RUN apt-get install -y curl
RUN apt-get install -y wget
RUN apt-get install -y git
# install node14, see comment at the to of node14source_setup.sh
@@ -40,17 +41,44 @@ RUN npm install
# Install Miniconda and CadQuery
#RUN wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
RUN curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "miniconda.sh"
RUN bash miniconda.sh -b -p $HOME/miniconda
RUN . $HOME/miniconda/bin/activate && conda create -n cadquery && conda activate cadquery && conda install -c conda-forge -c cadquery cadquery=master python=3.8
# RUN curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "miniconda.sh"
# RUN bash miniconda.sh -b -p /var/task/miniconda
# # RUN . /var/task/miniconda/bin/activate && conda create -n cadquery && conda activate cadquery && conda install -c conda-forge -c cadquery cadquery=master python=3.8
# RUN . /var/task/miniconda/bin/activate
# # RUN export PATH="/var/task/miniconda/bin:$PATH"
# ENV PATH="/var/task/miniconda/bin:${PATH}"
# ARG PATH="/var/task/miniconda/bin:${PATH}"
# RUN conda activate cadquery && conda install -c conda-forge -c cadquery cadquery=master python=3.8
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir /root/.conda \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh \
&& echo "Running $(conda --version)" && \
conda init bash && \
. /root/.bashrc && \
conda update conda && \
conda create -n cadquery && \
conda activate cadquery && \
conda install -c conda-forge -c cadquery cadquery=master python=3.8 && \
# conda create -n python-app && \
# conda activate python-app && \
# conda install python=3.8 pip && \
git clone https://github.com/CadQuery/cq-cli.git
# Grab a copy of cq-cli to convert the provided script
RUN git clone https://github.com/CadQuery/cq-cli.git
# RUN git clone https://github.com/CadQuery/cq-cli.git
COPY *.js /var/task/
COPY entrypoint.sh /entrypoint.sh
RUN ["chmod", "+x", "/entrypoint.sh"]
ENTRYPOINT ["sh", "/entrypoint.sh"]
COPY shaft_coupler.py /shaft_coupler.py
RUN . $HOME/miniconda/bin/activate && conda activate cadquery && python cq-cli/cq-cli.py --codec svg --infile /shaft_coupler.py
# CMD [ "openscad.render" ]
# RUN . $HOME/miniconda/bin/activate && conda activate cadquery && python cq-cli/cq-cli.py --codec svg --infile /shaft_coupler.py
CMD [ "openscad.render" ]

View File

@@ -39,7 +39,7 @@ const render = async (req, _context, callback) => {
} else {
console.log(`got result in route: ${result}, file is: ${tempFile}`)
const fs = require('fs')
const image = fs.readFileSync(`/tmp/${tempFile}/output.png`, {
const image = fs.readFileSync(`/tmp/${tempFile}/output.stl`, {
encoding: 'base64',
})
console.log(image, 'encoded image')

View File

@@ -15,10 +15,10 @@ module.exports.runScad = async ({
} = {}, // TODO add view settings
} = {}) => {
const tempFile = await makeFile(file)
const { x: rx, y: ry, z: rz } = rotation
const { x: px, y: py, z: pz } = position
const cameraArg = `--camera=${px},${py},${pz},${rx},${ry},${rz},${dist}`
const command = `xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" openscad -o /tmp/${tempFile}/output.png ${cameraArg} --imgsize=${x},${y} --colorscheme DeepOcean /tmp/${tempFile}/main.scad`
// this one worked
// const command = `conda run -n cadquery python ./cq-cli/cq-cli.py --codec svg --infile /tmp/${tempFile}/main.py --outfile /tmp/${tempFile}/output.svg`
const command = `conda run -n cadquery python ./cq-cli/cq-cli.py --codec stl --infile /tmp/${tempFile}/main.py --outfile /tmp/${tempFile}/output.stl`
console.log('command', command)
try {
@@ -48,7 +48,7 @@ async function makeFile(file) {
console.log(`file to write: ${file}`)
await runCommand(`mkdir /tmp/${tempFile}`)
await writeFile(`/tmp/${tempFile}/main.scad`, file)
await writeFile(`/tmp/${tempFile}/main.py`, file)
return tempFile
}

View File

@@ -29,6 +29,12 @@ services:
ports:
- "5053:8080"
cadquery-render:
build: ./cadquery/.
command: openscad.render
ports:
- 5060:8080
# networks:
# awsland:
# name: awsland