Skip to content

Commit

Permalink
Bring forward Ethan's #201 to solve #116 local docker. TODO: arm64
Browse files Browse the repository at this point in the history
Co-authored-by: thatoldplatitude <thatoldplatitude@users.noreply.github.com>
Co-authored-by: Ethan-Strominger <32078396+ethanstrominger@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 6, 2024
1 parent 6bde273 commit 9a20eb6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 101 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ node_modules

#local temporary folders
heat-app
venv
venv*
heat-tmp
105 changes: 105 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions heat-stack/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
98 changes: 0 additions & 98 deletions heat-stack/other/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions heat-stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
5 changes: 5 additions & 0 deletions python/setup-wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
python3 -m venv venv
pip install -r requirements.txt
source venv/bin/activate
pip install -q build
python3 -m build

0 comments on commit 9a20eb6

Please sign in to comment.