File size: 2,084 Bytes
e74c73c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170a6b7
e74c73c
 
 
 
 
 
 
 
0481dd5
e74c73c
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# See https://hub.docker.com/r/nikolaik/python-nodejs
#     https://github.com/nikolaik/docker-python-nodejs
# Default user is 'pn' with uid 1000, gid 1000
FROM nikolaik/python-nodejs:python3.10-nodejs18

# Install nginx and give permissions to 'pn'
# See https://www.rockyourcode.com/run-docker-nginx-as-non-root-user/
USER root

RUN apt-get -y update && apt-get -y install nginx

RUN mkdir -p /var/cache/nginx \
             /var/log/nginx \
             /var/lib/nginx
RUN touch /var/run/nginx.pid

RUN chown -R pn:pn /var/cache/nginx \
                       /var/log/nginx \
                       /var/lib/nginx \
                       /var/run/nginx.pid

# Install dependencies and build app as non-root
USER pn
ENV HOME=/home/pn \
    PATH=/home/pn/.local/bin:$PATH

RUN mkdir $HOME/app

WORKDIR $HOME/app

# Install bun manually
RUN curl -fsSL https://bun.sh/install | bash

# Install pynecone (in case it's forgotten in requirements.txt)
RUN pip install --no-cache-dir --upgrade pynecone

# Install additional dependencies
# To install using a package manager (pipenv, poetry, pdm,...) please adapt this section
COPY --chown=pn requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Init project
RUN pc init

# Init frontend
# Optional: could be done at runtime. But saves time if already done in container build.
#           It installs all frontend dependencies
RUN python -c "from pathlib import Path; from pynecone.utils import setup_frontend; setup_frontend(Path.cwd())"

# Copy existing project
COPY --chown=pn pcconfig_docker.py pcconfig.py
COPY --chown=pn news_pynecone news_pynecone
COPY --chown=pn assets assets

# Re-init frontend (if new deps from project)
RUN python -c "from pathlib import Path; from pynecone.utils import setup_frontend; setup_frontend(Path.cwd())"

# Copy nginx configuration
COPY --chown=pn nginx.conf /etc/nginx/sites-available/default

# Copy README and entrypoint script
COPY --chown=pn README.md README.md
COPY --chown=pn run.sh .

# Run script ('service nginx start' + 'pc run')
CMD ["bash", "run.sh"]