Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Pynecone Container Image Build #387

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docker-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions docker-example/README.md
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions docker-example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pynecone-io