From 9cf02980cc248f693829076582a3213564b47128 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Fri, 23 Apr 2021 07:41:55 +1000 Subject: [PATCH] Use release package instead to avoid conda permission issues conda permission issue would arise only when deployed. Side stepped this issue by using the release package instead. Also cleaned up the docker file. Still need to remove duplication between openscad and cadquery apis --- api/src/docker/cadquery/Dockerfile | 60 +++++------------------- api/src/docker/cadquery/runCQ.js | 19 ++------ api/src/docker/cadquery/shaft_coupler.py | 13 ----- api/src/docker/openscad/runScad.js | 2 +- 4 files changed, 16 insertions(+), 78 deletions(-) delete mode 100644 api/src/docker/cadquery/shaft_coupler.py diff --git a/api/src/docker/cadquery/Dockerfile b/api/src/docker/cadquery/Dockerfile index f9772ac..d2735a4 100644 --- a/api/src/docker/cadquery/Dockerfile +++ b/api/src/docker/cadquery/Dockerfile @@ -2,15 +2,10 @@ 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 -# 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 -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 -qq openscad -# 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 ADD node14source_setup.sh /nodesource_setup.sh @@ -20,13 +15,13 @@ RUN apt-get install -y nodejs # Install aws-lambda-cpp build dependencies, this is for the post install script in aws-lambda-ric (in package.json) RUN apt-get update && \ - apt-get install -y \ - g++ \ - make \ - cmake \ - unzip \ - automake autoconf libtool \ - libcurl4-openssl-dev + apt-get install -y \ + g++ \ + make \ + cmake \ + unzip \ + automake autoconf libtool \ + libcurl4-openssl-dev # 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), @@ -39,46 +34,15 @@ WORKDIR /var/task/ COPY package*.json /var/task/ 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 /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 +# Get the distribution copy of cq-cli +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 -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 chmod +x cq-cli/cq-cli 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" ] diff --git a/api/src/docker/cadquery/runCQ.js b/api/src/docker/cadquery/runCQ.js index ffd5ab2..d0a2941 100644 --- a/api/src/docker/cadquery/runCQ.js +++ b/api/src/docker/cadquery/runCQ.js @@ -3,26 +3,13 @@ const { promises } = require('fs') const { writeFile } = promises const { nanoid } = require('nanoid') -module.exports.runCQ = async ({ - file, - settings: { - size: { x = 500, y = 500 } = {}, - camera: { - position = { x: 40, y: 40, z: 40 }, - rotation = { x: 55, y: 0, z: 25 }, - dist = 200, - } = {}, - } = {}, // TODO add view settings -} = {}) => { +module.exports.runCQ = async ({ file, settings = {} } = {}) => { const tempFile = await makeFile(file) - // 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` + const command = `cq-cli/cq-cli --codec stl --infile /tmp/${tempFile}/main.py --outfile /tmp/${tempFile}/output.stl` console.log('command', command) try { - const result = await runCommand(command, 10000) + const result = await runCommand(command, 30000) return { result, tempFile } } catch (error) { return { error, tempFile } diff --git a/api/src/docker/cadquery/shaft_coupler.py b/api/src/docker/cadquery/shaft_coupler.py deleted file mode 100644 index 467fbf7..0000000 --- a/api/src/docker/cadquery/shaft_coupler.py +++ /dev/null @@ -1,13 +0,0 @@ -import cadquery as cq -from cadquery import exporters - -diam = 5.0 - -result = (cq.Workplane().circle(diam).extrude(20.0) - .faces(">Z").workplane(invert=True).circle(1.05).cutBlind(8.0) - .faces("