Skip to content

Commit

Permalink
Clean up docker build for api-engine
Browse files Browse the repository at this point in the history
The current building process involves several useless steps.

And it will trigger security alerts with the old version of django packages.

This PR cleans unused code and remove unused scripts and packages.

Signed-off-by: Baohua Yang [email protected]
  • Loading branch information
yeasy authored Mar 22, 2020
2 parents f66362c + 4de6f5a commit 79d74a4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 154 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ build/docker/%/.push: build/docker/%/$(DUMMY)
--password=$(DOCKER_HUB_PASSWORD)
@docker push $(BASENAME)-$(patsubst build/docker/%/.push,%,$@):$(IMG_TAG)

common-docker: $(patsubst %,build/docker/common/%/$(DUMMY),$(COMMON_DOCKER_IMAGES)) ##@Generate docker images locally
docker-common: $(patsubst %,build/docker/common/%/$(DUMMY),$(COMMON_DOCKER_IMAGES)) ##@Generate docker images locally

agent-docker: $(patsubst %,build/docker/agent/%/$(DUMMY),$(AGENT_DOCKER_IMAGES)) ##@Generate docker images locally

docker: common-docker agent-docker
docker: docker-common agent-docker

common-docker-%:
docker-common-%:
@$(MAKE) build/docker/common/$*/$(DUMMY)

agent-docker-%:
Expand Down Expand Up @@ -272,6 +272,9 @@ HELP_FUN = \
}; \
print "\n"; }

api-engine: # for debug only now
docker build -t hyperledger/cello-api-engine:latest -f build_image/docker/common/api-engine/Dockerfile.in ./

.PHONY: \
all \
check \
Expand Down
27 changes: 16 additions & 11 deletions build_image/docker/common/api-engine/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
FROM python:3.6

RUN apt-get update && apt-get install -y gettext-base graphviz libgraphviz-dev && \
apt-get autoclean && apt-get clean && apt-get autoremove && rm -rf /var/cache/apt/
COPY src/api-engine/requirements.txt /
RUN cd / && \
pip install -r requirements.txt
# Install software
RUN apt-get update \
&& apt-get install -y gettext-base graphviz libgraphviz-dev \
&& apt-get autoclean \
&& apt-get clean \
&& apt-get autoremove && rm -rf /var/cache/apt/

COPY src/api-engine /var/www/server
COPY src/api-engine/docker/uwsgi/server.ini /etc/uwsgi/apps-enabled/
COPY src/api-engine/docker/scripts /scripts
COPY build_image/docker/common/api-engine/entrypoint.sh /
# Set the working dir
WORKDIR /var/www/server

RUN cd /var/www/server/api_engine && cp settings.py.initial settings.py && cd .. && python manage.py collectstatic --noinput
# Copy source code to the working dir
COPY src/api-engine ./

WORKDIR /var/www/server
# Install python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Add uwsgi configuration file
COPY build_image/docker/common/api-engine/server.ini /etc/uwsgi/apps-enabled/

ENV RUN_MODE server

COPY build_image/docker/common/api-engine/entrypoint.sh /
CMD bash /entrypoint.sh
20 changes: 16 additions & 4 deletions build_image/docker/common/api-engine/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#!/usr/bin/env bash

bash /scripts/initial.sh;
#bash /scripts/initial.sh;

echo "Generating the settings.py for api_engine"
LOCAL_SETTINGS="/var/www/server/api_engine/settings.py"
RAW_LOCAL_SETTINGS="/var/www/server/api_engine/settings.py.example"

envsubst < ${RAW_LOCAL_SETTINGS} > ${LOCAL_SETTINGS}

holdup -t 120 tcp://${DB_HOST}:${DB_PORT};
if [[ "$RUN_MODE" == "server" ]]; then
python manage.py makemigrations && python manage.py migrate;
python manage.py create_user --username ${ADMIN_USERNAME} --password ${ADMIN_PASSWORD} --is_superuser --email ${ADMIN_EMAIL} --role operator
if [[ "$DEBUG" == "True" ]]; then
python manage.py create_user \
--username ${ADMIN_USERNAME:-admin} \
--password ${ADMIN_PASSWORD:-pass} \
--email ${ADMIN_EMAIL:-admin@cello} \
--is_superuser \
--role operator
if [[ "$DEBUG" == "True" ]]; then # For dev, use pure Django directly
python manage.py runserver 0.0.0.0:8080;
else
else # For production, use uwsgi in front
uwsgi --ini /etc/uwsgi/apps-enabled/server.ini;
fi
else
Expand Down
File renamed without changes.
123 changes: 0 additions & 123 deletions src/api-engine/api_engine/settings.py.initial

This file was deleted.

5 changes: 0 additions & 5 deletions src/api-engine/docker/scripts/change_local_settings.sh

This file was deleted.

6 changes: 0 additions & 6 deletions src/api-engine/docker/scripts/initial.sh

This file was deleted.

4 changes: 2 additions & 2 deletions src/api-engine/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django<=2.1.4
Django>=2.2.10,<=3.0.4
uwsgi<=2.0.17.1
djangorestframework<=3.9.0
django-filter<=1.1.0
Expand All @@ -11,7 +11,7 @@ django-extensions<=2.1.6
pygraphviz<=1.5
celery<=4.2.1
redis<=3.2.0
docker-compose>=1.18.0,<=1.23.2
# docker-compose>=1.18.0,<=1.25.4
watchdog<=0.9.0
django-allauth<=0.39.1
django-rest-auth<=0.9.3
Expand Down

0 comments on commit 79d74a4

Please sign in to comment.