diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..8e363e97 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# This file is moved to the root directory before building the image + +**/node_modules +*.log +.DS_Store +heat-stack/.env +heat-stack/.cache +**/*build diff --git a/.gitignore b/.gitignore index ee899313..1f58a1f5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ node_modules #local temporary folders heat-app -venv +venv* heat-tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ea0340d9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,105 @@ +# Our 116 (from Main branch) +# base node image +FROM node:20-bookworm-slim AS base + +# set for base and all layer that inherit from it +ENV NODE_ENV production + +# Install openssl for Prisma +RUN apt-get update && apt-get install -y fuse3 openssl sqlite3 ca-certificates + +# Install all node_modules, including dev dependencies +FROM base AS deps + +WORKDIR /myapp/heat-stack + +ADD heat-stack/package.json heat-stack/package-lock.json heat-stack/.npmrc ./ +RUN npm install --include=dev + +# Setup production node_modules +FROM base AS production-deps + +WORKDIR /myapp/heat-stack + +COPY --from=deps /myapp/heat-stack/node_modules /myapp/heat-stack/node_modules +ADD heat-stack/package.json heat-stack/package-lock.json heat-stack/.npmrc ./ +RUN npm prune --omit=dev + +# Build the app +FROM base AS heat-build + +ARG COMMIT_SHA +ENV COMMIT_SHA=$COMMIT_SHA + +# Use the following environment variables to configure Sentry +# ENV SENTRY_ORG= +# ENV SENTRY_PROJECT= + + +WORKDIR /myapp/heat-stack + +COPY --from=deps /myapp/heat-stack/node_modules /myapp/heat-stack/node_modules + +ADD heat-stack/. . +# Mount the secret and set it as an environment variable and run the build +# RUN npx prisma generate +RUN npm run build + + +# RUN mount=type=secret,id=SENTRY_AUTH_TOKEN \ +# export SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) && \ +# npm run build + +FROM python:3.12.3-slim-bookworm as rules-build +WORKDIR /myapp +ADD python/. . +RUN bash -c "source setup-wheel.sh" + +# Finally, build the production image with minimal heat-stack footprint +FROM base + +ENV FLY="true" +ENV LITEFS_DIR="/litefs/data" +ENV DATABASE_FILENAME="sqlite.db" +ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME" +ENV DATABASE_URL="file:$DATABASE_PATH" +ENV CACHE_DATABASE_FILENAME="cache.db" +ENV CACHE_DATABASE_PATH="$LITEFS_DIR/$CACHE_DATABASE_FILENAME" +ENV INTERNAL_PORT="8080" +ENV PORT="8081" +ENV NODE_ENV="production" +# For WAL support: https://github.com/prisma/prisma-engines/issues/4675#issuecomment-1914383246 +ENV PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK = "1" + +# add shortcut for connecting to database CLI +RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli + +WORKDIR /myapp/heat-stack + +# Generate random value and save it to .env file which will be loaded by dotenv +RUN INTERNAL_COMMAND_TOKEN=$(openssl rand -hex 32) && \ + echo "INTERNAL_COMMAND_TOKEN=$INTERNAL_COMMAND_TOKEN" > .env + +COPY --from=production-deps /myapp/heat-stack/node_modules /myapp/heat-stack/node_modules +COPY --from=heat-build /myapp/heat-stack/node_modules/.prisma /myapp/heat-stack/node_modules/.prisma + +COPY --from=heat-build /myapp/heat-stack/server-build /myapp/heat-stack/server-build +COPY --from=heat-build /myapp/heat-stack/build /myapp/heat-stack/build + +# HEAT Stack custom line for Pyodide +COPY --from=heat-build /myapp/heat-stack/public /myapp/heat-stack/public +COPY --from=heat-build /myapp/heat-stack/package.json /myapp/heat-stack/package.json +COPY --from=heat-build /myapp/heat-stack/prisma /myapp/heat-stack/prisma +COPY --from=heat-build /myapp/heat-stack/app/components/ui/icons /myapp/heat-stack/app/components/ui/icons +COPY --from=rules-build /myapp/dist/*.whl /myapp/heat-stack/public/pyodide-env/ + + + +# prepare for litefs +COPY --from=flyio/litefs:0.5.11 /usr/local/bin/litefs /usr/local/bin/litefs +ADD heat-stack/other/litefs.yml /etc/litefs.yml +RUN mkdir -p /data ${LITEFS_DIR} + +ADD heat-stack/. . + +CMD ["litefs", "mount"] diff --git a/heat-stack/fly.toml b/heat-stack/fly.toml index 39a31b0c..fe437461 100644 --- a/heat-stack/fly.toml +++ b/heat-stack/fly.toml @@ -15,8 +15,8 @@ destination = "/data" [build] # github actions moves these for now, but upstream they no longer need to be moved: -dockerfile = "Dockerfile" -ignorefile = "Dockerfile.dockerignore" +dockerfile = "../Dockerfile" +ignorefile = "../Dockerfile.dockerignore" # dockerfile = "/other/Dockerfile" # ignorefile = "/other/Dockerfile.dockerignore" diff --git a/heat-stack/other/Dockerfile b/heat-stack/other/Dockerfile deleted file mode 100644 index 3cd618a6..00000000 --- a/heat-stack/other/Dockerfile +++ /dev/null @@ -1,98 +0,0 @@ -# This file is moved to the root directory before building the image - -# base node image -FROM node:20-bookworm-slim as base - -# set for base and all layer that inherit from it -ENV NODE_ENV production - -# Install openssl for Prisma -RUN apt-get update && apt-get install -y fuse3 openssl sqlite3 ca-certificates - -# Install all node_modules, including dev dependencies -FROM base as deps - -WORKDIR /myapp - -ADD package.json package-lock.json .npmrc ./ -RUN npm install --include=dev - -# Setup production node_modules -FROM base as production-deps - -WORKDIR /myapp - -COPY --from=deps /myapp/node_modules /myapp/node_modules -ADD package.json package-lock.json .npmrc ./ -RUN npm prune --omit=dev - -# Build the app -FROM base as build - -ARG COMMIT_SHA -ENV COMMIT_SHA=$COMMIT_SHA - -# Use the following environment variables to configure Sentry -# ENV SENTRY_ORG= -# ENV SENTRY_PROJECT= - - -WORKDIR /myapp - -COPY --from=deps /myapp/node_modules /myapp/node_modules - -ADD prisma . -RUN npx prisma generate - -ADD . . - -# Mount the secret and set it as an environment variable and run the build -RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \ - export SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) && \ - npm run build - -# Finally, build the production image with minimal footprint -FROM base - -ENV FLY="true" -ENV LITEFS_DIR="/litefs/data" -ENV DATABASE_FILENAME="sqlite.db" -ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME" -ENV DATABASE_URL="file:$DATABASE_PATH" -ENV CACHE_DATABASE_FILENAME="cache.db" -ENV CACHE_DATABASE_PATH="$LITEFS_DIR/$CACHE_DATABASE_FILENAME" -ENV INTERNAL_PORT="8080" -ENV PORT="8081" -ENV NODE_ENV="production" -# For WAL support: https://github.com/prisma/prisma-engines/issues/4675#issuecomment-1914383246 -ENV PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK = "1" - -# add shortcut for connecting to database CLI -RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli - -WORKDIR /myapp - -# Generate random value and save it to .env file which will be loaded by dotenv -RUN INTERNAL_COMMAND_TOKEN=$(openssl rand -hex 32) && \ - echo "INTERNAL_COMMAND_TOKEN=$INTERNAL_COMMAND_TOKEN" > .env - -COPY --from=production-deps /myapp/node_modules /myapp/node_modules -COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma - -COPY --from=build /myapp/server-build /myapp/server-build -COPY --from=build /myapp/build /myapp/build - -# HEAT Stack custom line for Pyodide -COPY --from=build /myapp/public /myapp/public -COPY --from=build /myapp/package.json /myapp/package.json -COPY --from=build /myapp/prisma /myapp/prisma -COPY --from=build /myapp/app/components/ui/icons /myapp/app/components/ui/icons - -# prepare for litefs -COPY --from=flyio/litefs:0.5.11 /usr/local/bin/litefs /usr/local/bin/litefs -ADD other/litefs.yml /etc/litefs.yml -RUN mkdir -p /data ${LITEFS_DIR} - -ADD . . - -CMD ["litefs", "mount"] diff --git a/heat-stack/package.json b/heat-stack/package.json index 1f4ede24..846acd11 100644 --- a/heat-stack/package.json +++ b/heat-stack/package.json @@ -15,6 +15,7 @@ "build:server": "tsx ./other/build-server.ts", "predev": "npm run build:icons --silent", "dev": "node ./server/dev-server.js", + "prisma:generate": "prisma generate", "prisma:studio": "prisma studio", "format": "prettier --write .", "lint": "eslint .", diff --git a/python/setup-wheel.sh b/python/setup-wheel.sh new file mode 100644 index 00000000..5acfb6e8 --- /dev/null +++ b/python/setup-wheel.sh @@ -0,0 +1,5 @@ +python3 -m venv venv +pip install -r requirements.txt +source venv/bin/activate +pip install -q build +python3 -m build \ No newline at end of file