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 4 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
15 changes: 8 additions & 7 deletions django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# deps
FROM python:3.8-slim-buster 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 ./requirements.txt ./requirements.txt

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

# Install postgres dependencies (pgsql client and development files)
COPY ./etc/pgdg.sh /tmp/pgdg.sh
Expand All @@ -20,12 +21,12 @@ 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 ./entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["/usr/src/django/entrypoint.sh"]

# prod
Expand All @@ -36,4 +37,4 @@ COPY university/ ./university
COPY manage.py tasks.py ./

COPY ./entrypoint_prod.sh ./entrypoint_prod.sh
ENTRYPOINT ["/usr/src/django/entrypoint_prod.sh"]
ENTRYPOINT ["/usr/src/django/entrypoint_prod.sh"]
7 changes: 6 additions & 1 deletion django/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ 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"
>&2 echo "PostgreSQL is up - executing commands"

# Compile protobuf files
echo "Compiling protobuf files..."
protoc --python_out=generated ./protos/*.proto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's best to have ./protos/**/*.proto instead of just ./protos/*.proto.

With the ** we are able to better support a folder structure of proto files (for example, if we wanted to separate different .proto files in different folders.

echo "Protobuf files compiled successfully."

# Migrate the Django.
python manage.py inspectdb > university/models.py
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

echo "Protobuf files compiled successfully."

# Migrate the Django.
python manage.py inspectdb >university/models.py
python manage.py makemigrations
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ services:
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