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

Feat: production container #123

Merged
merged 4 commits into from
Aug 23, 2022
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
28 changes: 5 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
FROM python:3.10
FROM ghcr.io/cal-itp/docker-python-web:main

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
USER=calitp \
FLASK_APP=eligibility_server/app.py

# create $USER and home directory
RUN useradd --create-home --shell /bin/bash $USER && \
chown -R $USER /home/$USER

RUN apt-get update \
&& apt-get install -qq --no-install-recommends build-essential \
&& python -m pip install --upgrade pip

# enter app directory
WORKDIR /home/$USER/app

# switch to non-root $USER
USER $USER

# update PATH for local pip installs
ENV PATH "$PATH:/home/$USER/.local/bin"
ENV FLASK_APP=eligibility_server/app.py

# install python app dependencies
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# copy source files
COPY . /home/$USER/app/
COPY bin/ .
COPY eligibility_server/ .
COPY *.py .

# start app
ENTRYPOINT ["/bin/bash"]
Expand Down
2 changes: 1 addition & 1 deletion bin/init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! usr/bin/env bash
#!/usr/bin/env bash
set -eux

# run database migrations
Expand Down
6 changes: 4 additions & 2 deletions bin/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! usr/bin/env bash
#!/usr/bin/env bash
set -eux

# initialize Flask
Expand All @@ -7,4 +7,6 @@ bin/init.sh

# start the web server

flask run -h 0.0.0.0
nginx

python -m gunicorn -c $GUNICORN_CONF eligibility_server.app:app
8 changes: 4 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
env_file: .env
image: eligibility_server:latest
ports:
- "5000"
- "8000"
volumes:
- .:/home/calitp/app/

Expand All @@ -19,15 +19,15 @@ services:
env_file: .env
image: eligibility_server:dev
ports:
- "5000"
- "8000"
volumes:
- .:/home/calitp/app/

docs:
image: eligibility_server:dev
entrypoint: mkdocs
command: serve --dev-addr "0.0.0.0:8000"
command: serve --dev-addr "0.0.0.0:8001"
ports:
- "8000"
- "8001"
volumes:
- .:/home/calitp/app
2 changes: 1 addition & 1 deletion eligibility_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def __repr__(self):


if __name__ == "__main__":
app.run(host=app.config["HOST"], debug=app.config["DEBUG_MODE"]) # nosec
app.run(host=app.config["HOST"], debug=app.config["DEBUG_MODE"], port="8000") # nosec