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

added protobufs instructions to Dockerfile #109

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tts-protobufs"]
path = tts-protobufs
url = https://github.com/NIAEFEUP/tts-protobufs.git
32 changes: 19 additions & 13 deletions django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
# deps
FROM python:3.11-slim AS deps

WORKDIR /usr/src/django/
WORKDIR /usr/src/django/

# Get's the output from the django in realtime.
# Get's the output from the django in realtime.
ENV PYTHONUNBUFFERED=1

# Copy requirements
COPY ./requirements.txt ./requirements.txt
# Copy requirements
COPY ./django/requirements.txt ./requirements.txt

COPY ./tts-protobufs protos

# Dependencies for building the requirements
RUN apt-get update
RUN apt-get -y install build-essential
RUN apt-get -y install build-essential protobuf-compiler git

RUN git init
RUN git submodule init
RUN git submodule update

# Install postgres dependencies (pgsql client and development files)
COPY ./etc/pgdg.sh /tmp/pgdg.sh
COPY ./django/etc/pgdg.sh /tmp/pgdg.sh
RUN /tmp/pgdg.sh

RUN apt -y install libpq-dev postgresql-client-16
RUN apt -y clean && rm -rf /var/lib/apt/lists/*

# Install the requirements
RUN pip install -r requirements.txt

EXPOSE 8000

COPY ./entrypoint.sh ./entrypoint.sh
# Install the requirements
COPY ./django/entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["/usr/src/django/entrypoint.sh"]

# prod
FROM deps AS prod

COPY tts_be/ ./tts_be
COPY university/ ./university
COPY manage.py tasks.py ./
COPY django/tts_be/ ./tts_be
COPY django/university/ ./university
COPY django/manage.py django/tasks.py ./

COPY ./entrypoint_prod.sh ./entrypoint_prod.sh
ENTRYPOINT ["/usr/src/django/entrypoint_prod.sh"]
COPY ./django/entrypoint_prod.sh ./entrypoint_prod.sh
ENTRYPOINT ["/usr/src/django/entrypoint_prod.sh"]
8 changes: 6 additions & 2 deletions django/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${POSTGRES_HOST}" -U "${POSTGRE
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 4
done
>&2 echo "PostgreSQL is up - executing command"

echo "ENTRYPOINT RAN"
>&2 echo "PostgreSQL is up - executing commands"

# Compile protobuf files
echo "Compiling protobuf files..."
protoc --python_out=generated -I=./protos/ ./protos/**/*.proto
echo "Protobuf files compiled successfully."

# Migrate the Django.
python manage.py makemigrations
Expand Down
5 changes: 5 additions & 0 deletions django/entrypoint_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${POSTGRES_HOST}" -U "${POSTGRE
done
>&2 echo "PostgreSQL is up - executing command"

# Compile protobuf files
echo "Compiling protobuf files..."
protoc --python_out=generated -I=./protos/ ./protos/**/*.proto
echo "Protobuf files compiled successfully."

# Migrate the Django.
python manage.py inspectdb >university/models.py
python manage.py makemigrations
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ services:
- ./nginx/certs/:/etc/nginx/certs/

django:
build: ./django
build:
context: ./
dockerfile: django/Dockerfile
container_name: tts_django
env_file:
- django/.env.dev
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
volumes:
- ./django/:/usr/src/django/
- ./tts-protobufs/protos/:/usr/src/django/protos/
- ./protos/:/usr/src/django/generated/
ports:
- 8100:8000

Expand Down
93 changes: 93 additions & 0 deletions protos/class_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tts-protobufs
Submodule tts-protobufs added at 12aefb