Преглед на файлове

Feature: Add Pynecone Container Image Build (#387)

Robert Neumann преди 2 години
родител
ревизия
7fefbcd444
променени са 3 файла, в които са добавени 83 реда и са изтрити 0 реда
  1. 49 0
      docker-example/Dockerfile
  2. 33 0
      docker-example/README.md
  3. 1 0
      docker-example/requirements.txt

+ 49 - 0
docker-example/Dockerfile

@@ -0,0 +1,49 @@
+FROM python:3.11-slim as base
+
+RUN adduser --disabled-password pynecone
+
+
+FROM base as build
+
+WORKDIR /app
+ENV VIRTUAL_ENV=/app/venv
+RUN python3 -m venv $VIRTUAL_ENV
+ENV PATH="$VIRTUAL_ENV/bin:$PATH"
+
+COPY . .
+
+RUN pip install wheel \
+    && pip install -r requirements.txt
+
+
+FROM base as runtime
+
+RUN apt-get update && apt-get install -y \
+    curl \
+    && curl -fsSL https://deb.nodesource.com/setup_19.x | bash - \
+    && apt-get update && apt-get install -y \
+    nodejs \
+    unzip \
+    && rm -rf /var/lib/apt/lists/*
+
+ENV PATH="/app/venv/bin:$PATH"
+
+
+FROM runtime as init
+
+WORKDIR /app
+ENV BUN_INSTALL="/app/.bun"
+COPY --from=build /app/ /app/
+RUN pc init
+
+
+FROM runtime
+
+COPY --chown=pynecone --from=init /app/ /app/
+USER pynecone
+WORKDIR /app
+
+CMD ["pc","run" , "--env", "prod"]
+
+EXPOSE 3000
+EXPOSE 8000

+ 33 - 0
docker-example/README.md

@@ -0,0 +1,33 @@
+# Pynecone Container Image Build
+This example describes how to create and use a container image for Pynecone with your own code.
+
+## Update Requirements
+The `requirements.txt` includes the pynecone-io package which is need to install Pynecone framework. If you use additional packages in your project you have add this in the `requirements.txt` first. Copy the `Dockerfile` and the `requirements.txt` file in your project folder.
+
+## Customize Pynecone Config
+The `pcconfig.py` includes the configuration of your Pynecone service. Edit the file like the following configuration. If you want to use a custom database you can set the endpoint in this file.
+
+```python
+import pynecone as pc
+
+config = pc.Config(
+    app_name="app",
+    api_url="0.0.0.0:8000",
+    bun_path="/app/.bun/bin/bun",
+    db_url="sqlite:///pynecone.db",
+)
+```
+
+## Build Pyonecone Container Image
+To build your container image run the following command:
+
+```bash
+docker build -t pynecone-project:latest .
+```
+
+## Start Container Service
+Finally, you can start your Pynecone container service as follows:
+
+```bash
+docker run -d -p 3000:3000 -p 8000:8000 --name pynecone pynecone:latest
+```

+ 1 - 0
docker-example/requirements.txt

@@ -0,0 +1 @@
+pynecone-io