Skip to content

Commit

Permalink
updates to port
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfowl committed Oct 26, 2023
1 parent 598ccc8 commit fe4a000
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .dockerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"containers": [
"de41975f4f64",
"074add429712"
]
}
31 changes: 19 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.10-slim

EXPOSE 8000

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
ENV PORT 8080
ENV HOST 0.0.0.0

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app
#copy local code to the container
COPY . .

EXPOSE 8080

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# For more info, please refer to https://aka.ms/vdockerscode-docker-python-configure-containers
#RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
#USER appuser

#EXPOSE 8080

# Keeps Python from generating .pyc files in the container 074add429712
# ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
# ENV PYTHONUNBUFFERED=1

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
#CMD ["gunicorn", "--bind", "0.0.0.0:8000", "-k", "uvicorn.workers.UvicornWorker", "main:app"]
#CMD ["gunicorn", "--bind", "0.0.0.0:8080", "-k", "uvicorn.workers.UvicornWorker", "main:app"]
17 changes: 17 additions & 0 deletions docker-compose.debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.4"

services:
apis:
image: apis
build:
context: .
dockerfile: ./Dockerfile
command:
[
"sh",
"-c",
"pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m uvicorn main:app --host 0.0.0.0 --port 8080",
]
ports:
- 8080:8080
- 5678:5678
12 changes: 0 additions & 12 deletions docker-compose.debug.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
build:
context: .
dockerfile: ./Dockerfile
command: sh -c "uvicorn main:app --reload --port=8000 --host=0.0.0.0"
command: sh -c "uvicorn main:app --reload --port=8080 --host=0.0.0.0"
env_file:
- .env.development
ports:
- 8000:8000
- 8080:8080
volumes:
- .:/app
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
build:
context: .
dockerfile: ./Dockerfile
command: sh -c "uvicorn main:app --port=8000 --host=0.0.0.0"
command: sh -c "uvicorn main:app --port=8080 --host=0.0.0.0"
env_file:
- .env.production
ports:
- 8000:8000
- 8080:8080
volumes:
- .:/app
4 changes: 2 additions & 2 deletions docker-compose.staging.yml → docker-compose.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
build:
context: .
dockerfile: ./Dockerfile
command: sh -c "uvicorn main:app --port=8000 --host=0.0.0.0"
command: sh -c "uvicorn main:app --port=8080 --host=0.0.0.0"
env_file:
- .env.staging
ports:
- 8000:8000
- 8080:8080
volumes:
- .:/app
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from fastapi import FastAPI
"""Module providing env"""
from os import environ as env

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def index():
"""_summary_
Returns:
_type_: _description_
"""
return {"details": f"Hello World! Secret = {env['MY_VARIABLE']}"}
9 changes: 6 additions & 3 deletions scripts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ python3 -m venv env
cd env/Scripts && activate
cd ../.. && pip install fastapi uvicorn

uvicorn main:app --reload --port=8000 --host=0.0.0.0
127.0.0.1:8000
127.0.0.1:8000/docs
uvicorn main:app --reload --port=8080 --host=0.0.0.0
127.0.0.1:8080
127.0.0.1:8080/docs
ctrl+c

pip freeze > requirements.txt
Expand All @@ -18,6 +18,9 @@ docker compose -f docker-compose.staging.yml up --build
docker compose -f docker-compose.production.yml up --build -d


docker build ./
docker run -p 8080:8080 01ecc4969ede

docker build -t andrewfowl/chatgpt-fastapi:1.0.0 .
docker login -u andrewfowl
docker push andrewfowl/chatgpt-fastapi:1.0.0
Expand Down

0 comments on commit fe4a000

Please sign in to comment.