Add experimental support for OpenSCAD libraries

I've been able to get a proof of concept of downloading a openscad
library when the docker image builds
https://twitter.com/IrevDev/status/1400785325509660678
Since its experimental atm I'll leave it with just the one for now.

I've also got a local dev working again for the cad lambdas.

Resolves #338
This commit is contained in:
Kurt Hutten
2021-06-05 11:11:14 +10:00
parent a2327b6169
commit b868ab292b
7 changed files with 1827 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
# The following are the env vars you need run the cad lamdas locally
# The still connect to s3 so some secrets are needed, ask Kurt and he'll set things up for you
DEV_AWS_SECRET_ACCESS_KEY=""
DEV_AWS_ACCESS_KEY_ID=""
DEV_BUCKET="cad-preview-bucket-dev-001"

View File

@@ -3,7 +3,7 @@
We're using the serverless from work for deployment We're using the serverless from work for deployment
``` ```
sls deploy sls deploy --stage stagename
``` ```
But [Kurt Hutten](https://github.com/Irev-Dev) is the only one with credentials for deployment atm, though if you wanted to set your own account you could deploy to that if you wanted to test. But [Kurt Hutten](https://github.com/Irev-Dev) is the only one with credentials for deployment atm, though if you wanted to set your own account you could deploy to that if you wanted to test.

View File

@@ -13,7 +13,7 @@ const invocationURL = (port) =>
app.post('/openscad/preview', async (req, res) => { app.post('/openscad/preview', async (req, res) => {
try { try {
const { data } = await axios.post(invocationURL(5052), { const { data } = await axios.post(invocationURL(5052), {
body: Buffer.from(JSON.stringify(req.body)).toString('base64'), body: JSON.stringify(req.body),
}) })
res.status(data.statusCode) res.status(data.statusCode)
res.send(data.body) res.send(data.body)
@@ -26,7 +26,7 @@ app.post('/cadquery/stl', async (req, res) => {
console.log('making post request to 5060') console.log('making post request to 5060')
try { try {
const { data } = await axios.post(invocationURL(5060), { const { data } = await axios.post(invocationURL(5060), {
body: Buffer.from(JSON.stringify(req.body)).toString('base64'), body: req.body
}) })
res.status(data.statusCode) res.status(data.statusCode)
res.send(data.body) res.send(data.body)

View File

@@ -23,6 +23,10 @@ services:
# - awsland # - awsland
ports: ports:
- "5052:8080" - "5052:8080"
environment:
AWS_SECRET_ACCESS_KEY: "${DEV_AWS_SECRET_ACCESS_KEY}"
AWS_ACCESS_KEY_ID: "${DEV_AWS_ACCESS_KEY_ID}"
BUCKET: "${DEV_BUCKET}"
openscad-stl: openscad-stl:
image: openscad image: openscad
@@ -30,6 +34,10 @@ services:
command: openscad.stl command: openscad.stl
ports: ports:
- "5053:8080" - "5053:8080"
environment:
AWS_SECRET_ACCESS_KEY: "${DEV_AWS_SECRET_ACCESS_KEY}"
AWS_ACCESS_KEY_ID: "${DEV_AWS_ACCESS_KEY_ID}"
BUCKET: "${DEV_BUCKET}"
cadquery-stl: cadquery-stl:
build: build:
@@ -38,6 +46,10 @@ services:
command: cadquery.stl command: cadquery.stl
ports: ports:
- 5060:8080 - 5060:8080
environment:
AWS_SECRET_ACCESS_KEY: "${DEV_AWS_SECRET_ACCESS_KEY}"
AWS_ACCESS_KEY_ID: "${DEV_AWS_ACCESS_KEY_ID}"
BUCKET: "${DEV_BUCKET}"
# networks: # networks:
# awsland: # awsland:

View File

@@ -8,7 +8,7 @@ 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 -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 update -qq
RUN apt-get install -y -qq openscad RUN apt-get install -y -qq openscad
RUN apt-get install -y curl RUN apt-get install -y curl wget
# install node14, see comment at the to of node14source_setup.sh # install node14, see comment at the to of node14source_setup.sh
ADD common/node14source_setup.sh /nodesource_setup.sh ADD common/node14source_setup.sh /nodesource_setup.sh
@@ -37,6 +37,12 @@ WORKDIR /var/task/
COPY openscad/package*.json /var/task/ COPY openscad/package*.json /var/task/
RUN npm install RUN npm install
# Install OpenSCAD libraries
# It's experimental, so only adding latest Round-Anything for now
RUN echo "OPENSCADPATH=/var/task/openscad" >>/etc/profile && \
wget -P /var/task/openscad/ https://github.com/Irev-Dev/Round-Anything/archive/refs/tags/1.0.4.zip && \
unzip /var/task/openscad/1.0.4
COPY openscad/*.js /var/task/ COPY openscad/*.js /var/task/
COPY common/*.js /var/common/ COPY common/*.js /var/common/
COPY common/entrypoint.sh /entrypoint.sh COPY common/entrypoint.sh /entrypoint.sh

1799
app/api/src/docker/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@ import { STLLoader } from 'three/examples/jsm/loaders/STLLoader'
export const lambdaBaseURL = export const lambdaBaseURL =
process.env.CAD_LAMBDA_BASE_URL || process.env.CAD_LAMBDA_BASE_URL ||
'https://oxt2p7ddgj.execute-api.us-east-1.amazonaws.com/prod' 'https://2inlbple1b.execute-api.us-east-1.amazonaws.com/prod2'
export const stlToGeometry = (url) => export const stlToGeometry = (url) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {