Skip to content

Commit 7fefbcd

Browse files
authored
Feature: Add Pynecone Container Image Build (#387)
1 parent 3f5ff53 commit 7fefbcd

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

docker-example/Dockerfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM python:3.11-slim as base
2+
3+
RUN adduser --disabled-password pynecone
4+
5+
6+
FROM base as build
7+
8+
WORKDIR /app
9+
ENV VIRTUAL_ENV=/app/venv
10+
RUN python3 -m venv $VIRTUAL_ENV
11+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
12+
13+
COPY . .
14+
15+
RUN pip install wheel \
16+
&& pip install -r requirements.txt
17+
18+
19+
FROM base as runtime
20+
21+
RUN apt-get update && apt-get install -y \
22+
curl \
23+
&& curl -fsSL https://deb.nodesource.com/setup_19.x | bash - \
24+
&& apt-get update && apt-get install -y \
25+
nodejs \
26+
unzip \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
ENV PATH="/app/venv/bin:$PATH"
30+
31+
32+
FROM runtime as init
33+
34+
WORKDIR /app
35+
ENV BUN_INSTALL="/app/.bun"
36+
COPY --from=build /app/ /app/
37+
RUN pc init
38+
39+
40+
FROM runtime
41+
42+
COPY --chown=pynecone --from=init /app/ /app/
43+
USER pynecone
44+
WORKDIR /app
45+
46+
CMD ["pc","run" , "--env", "prod"]
47+
48+
EXPOSE 3000
49+
EXPOSE 8000

docker-example/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Pynecone Container Image Build
2+
This example describes how to create and use a container image for Pynecone with your own code.
3+
4+
## Update Requirements
5+
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.
6+
7+
## Customize Pynecone Config
8+
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.
9+
10+
```python
11+
import pynecone as pc
12+
13+
config = pc.Config(
14+
app_name="app",
15+
api_url="0.0.0.0:8000",
16+
bun_path="/app/.bun/bin/bun",
17+
db_url="sqlite:///pynecone.db",
18+
)
19+
```
20+
21+
## Build Pyonecone Container Image
22+
To build your container image run the following command:
23+
24+
```bash
25+
docker build -t pynecone-project:latest .
26+
```
27+
28+
## Start Container Service
29+
Finally, you can start your Pynecone container service as follows:
30+
31+
```bash
32+
docker run -d -p 3000:3000 -p 8000:8000 --name pynecone pynecone:latest
33+
```

docker-example/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pynecone-io

0 commit comments

Comments
 (0)