Skip to content

Commit

Permalink
Merge pull request #1 from jffrancob/multistage-builds
Browse files Browse the repository at this point in the history
Multistage builds
  • Loading branch information
jffrancob authored Sep 6, 2023
2 parents a299986 + e2f19ef commit cdc17b5
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 153 deletions.
76 changes: 76 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.env
config.yaml

/service/__init__.pyc
*.pyc
/service/test/__init__.pyc
/service/test/test_call.pyc
_trial_temp/
*.swp

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
*.log

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log
*.log.*

# Sphinx documentation
docs/_build/

# PyBuilder
target/


*.sqlite3
*.*~
*.passwd
.coverage

14 changes: 2 additions & 12 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
redis:
host: redis
port: 6379

logging:
version: 1
formatters:
normal:
format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s"
handlers:
file:
class: logging.handlers.RotatingFileHandler
formatter: normal
filename: publisher.log
maxBytes: 10485760
backupCount: 10
console:
class: logging.StreamHandler
formatter: normal
loggers:
publisher:
level: DEBUG
handlers: [file, console]
handlers: [console]
root:
level: DEBUG
handlers: [file, console]
handlers: [console]
100 changes: 71 additions & 29 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,85 @@
version: "3.7"

services:
speech-azure:
build: speech-azure
restart: unless-stopped
networks:
- voice-api
ports:
- 8181:8000
volumes:
- ./speech-azure/src/:/app
- /var/lib/asterisk/sounds/:/sounds
- /etc/localtime:/etc/localtime
# speech-azure:
# image: ikonoim/speech-azure:0.0.1
# build:
# context: speech-azure
# dockerfile: Dockerfile
# # runtime, or dev, or test for running tests
# target: runtime
# restart: unless-stopped
# ports:
# - 8181:8000
# environment:
# - AZURE_API_TOKEN
# - DEFAULT_LANG=es-MX-JorgeNeural
# volumes:
# - /etc/localtime:/etc/localtime
# - /var/lib/asterisk/sounds/:/sounds
# ## - ./speech-azure/src/:/app
# logging:
# driver: json-file
# options:
# max-size: 20m
# max-file: "10"
# networks:
# - voice-api

speech-google:
build: speech-google
restart: unless-stopped
networks:
- voice-api
ports:
- 8182:8000
volumes:
- ./speech-google/src/:/app
- /var/lib/asterisk/sounds/:/sounds
- /etc/localtime:/etc/localtime
# speech-google:
# image: ikonoim/speech-google:0.0.1
# build:
# context: speech-google
# dockerfile: Dockerfile
# # runtime, or dev, or test for running tests
# target: runtime
# restart: unless-stopped
# ports:
# - 8182:8000
# environment:
# - GOOGLE_APPLICATION_CREDENTIALS
# volumes:
# - /etc/localtime:/etc/localtime
# - /var/lib/asterisk/sounds/:/sounds
# ## - ./speech-google/src/:/app
# logging:
# driver: json-file
# options:
# max-size: 20m
# max-file: "10"
# networks:
# - voice-api

tts-azure:
build: tts-azure
image: ikonoim/tts-azure:0.0.1
build:
context: tts-azure
dockerfile: Dockerfile
# runtime, or dev, or test for running tests
target: runtime
restart: unless-stopped
networks:
- voice-api
ports:
- 8081:8000
environment:
- AZURE_API_TOKEN
volumes:
- ./tts-azure/src/:/app
- /var/lib/asterisk/sounds/:/sounds
- ./config.yaml:/etc/config.yaml
- /etc/localtime:/etc/localtime
#entrypoint: watchmedo auto-restart --recursive --pattern="*.py" --directory="." python main.py
- /var/lib/asterisk/sounds/:/sounds
## - ./tts-azure/src/:/app
logging:
driver: json-file
options:
max-size: 20m
max-file: "10"
networks:
- voice-api

networks:
voice-api:
external: true
name: voice-api
# driver: overlay
attachable: true
ipam:
config:
- subnet: 172.31.128.0/24
Binary file removed speech-azure/src/__pycache__/main.cpython-38.pyc
Binary file not shown.
22 changes: 0 additions & 22 deletions speech-azure/src/config.yaml

This file was deleted.

Binary file removed speech-google/src/__pycache__/main.cpython-38.pyc
Binary file not shown.
22 changes: 0 additions & 22 deletions speech-google/src/config.yaml

This file was deleted.

26 changes: 23 additions & 3 deletions tts-azure/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tiangolo/uvicorn-gunicorn:python3.8
FROM tiangolo/uvicorn-gunicorn:python3.8 as dev

LABEL name="TTS API"
LABEL authors="iKono Telecomunicaciones"
Expand All @@ -11,9 +11,10 @@ RUN apt-get update \

# copy the dependencies file to the working directory
COPY requirements.txt .

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

# Add metadata to the image to describe which port the container is listening on at runtime.
EXPOSE 8000
Expand All @@ -32,4 +33,23 @@ ENTRYPOINT ["/usr/local/bin/uvicorn"]
# app: the object created inside of main.py with the line app = FastAPI().
# --reload: make the server restart after code changes. Only do this for development.
# --host 0.0.0.0: Bind socket to this host.
CMD ["main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]



FROM python:3.8-slim as runtime

RUN apt-get update \
&& apt-get install -y \
sox \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./src /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
2 changes: 2 additions & 0 deletions tts-azure/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
watchdog
argh
5 changes: 2 additions & 3 deletions tts-azure/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fastapi
pyyaml
fastapi
aiohttp
sox
watchdog
argh
uvicorn
Binary file removed tts-azure/src/__pycache__/main.cpython-38.pyc
Binary file not shown.
22 changes: 0 additions & 22 deletions tts-azure/src/config.yaml

This file was deleted.

Loading

0 comments on commit cdc17b5

Please sign in to comment.