-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up, fix warnings and use a Makefile (#508)
* Tidy up, fix warnings and use a Makefile * Update README.md * Remove make dependency in docker image * Remove unused USE_VENV variable * Can't run specific tests with docker-compose * Fix pagination with no items
- Loading branch information
Showing
14 changed files
with
134 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,63 +2,42 @@ FROM alpine:3.7 | |
|
||
MAINTAINER Andy Driver <[email protected]> | ||
|
||
# install build dependencies (they'll be uninstalled after pip install) | ||
RUN apk add --no-cache \ | ||
--virtual build-deps \ | ||
gcc \ | ||
musl-dev | ||
ENV HELM_VERSION 2.9.1 | ||
ENV HELM_HOME /tmp/helm | ||
ENV DJANGO_SETTINGS_MODULE "control_panel_api.settings" | ||
|
||
# install python3 and 'ca-certificates' so that HTTPS works consistently | ||
WORKDIR /home/control-panel | ||
|
||
# install build dependencies (they'll be uninstalled after pip install) | ||
RUN apk add --no-cache \ | ||
build-base \ | ||
openssl \ | ||
ca-certificates \ | ||
libffi-dev \ | ||
python3-dev | ||
|
||
# Temporary bugfix for libressl | ||
# Postgres needs libressl-dev, but cryptography only works with openssl-dev | ||
RUN apk add --no-cache --virtual temp-ssl-fix \ | ||
openssl-dev \ | ||
&& pip3 install cryptography==2.2.2 \ | ||
&& apk del temp-ssl-fix \ | ||
&& apk add --no-cache \ | ||
python3-dev \ | ||
libressl-dev \ | ||
postgresql-dev | ||
|
||
# Install helm | ||
ENV HELM_VERSION 2.9.1 | ||
RUN wget https://storage.googleapis.com/kubernetes-helm/helm-v$HELM_VERSION-linux-amd64.tar.gz \ | ||
&& tar xzf helm-v$HELM_VERSION-linux-amd64.tar.gz \ | ||
&& mv linux-amd64/helm /usr/local/bin \ | ||
&& rm -rf helm-v$HELM_VERSION-linux-amd64.tar.gz linux-amd64 | ||
|
||
# Configure helm | ||
ENV HELM_HOME /tmp/helm | ||
RUN helm init --client-only | ||
# Install and configure helm | ||
COPY helm-repositories.yaml /tmp/helm/repository/repositories.yaml | ||
RUN helm repo update | ||
|
||
WORKDIR /home/control-panel | ||
|
||
# install python dependencies | ||
ADD requirements.txt requirements.txt | ||
RUN pip3 install -r requirements.txt | ||
|
||
# uninstall build dependencies | ||
RUN apk del build-deps | ||
|
||
ENV DJANGO_SETTINGS_MODULE "control_panel_api.settings" | ||
|
||
ADD manage.py manage.py | ||
ADD run_api run_api | ||
ADD run_tests run_tests | ||
ADD wait_for_db wait_for_db | ||
ADD control_panel_api control_panel_api | ||
ADD moj_analytics moj_analytics | ||
RUN wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-linux-amd64.tar.gz -O helm.tgz \ | ||
&& tar fxz helm.tgz \ | ||
&& mv linux-amd64/helm /usr/local/bin \ | ||
&& rm -rf helm.tgz linux-amd64 \ | ||
&& helm init --client-only \ | ||
&& helm repo update | ||
|
||
# install python dependencies (and then remove build dependencies) | ||
COPY requirements.txt ./ | ||
RUN pip3 install -r requirements.txt \ | ||
&& apk del build-base | ||
|
||
COPY control_panel_api control_panel_api | ||
COPY moj_analytics moj_analytics | ||
COPY manage.py wait_for_db ./ | ||
|
||
# collect static files for deployment | ||
RUN python3 manage.py collectstatic | ||
|
||
EXPOSE 8000 | ||
|
||
CMD ["./run_api"] | ||
CMD ["gunicorn", "-b", "0.0.0.0:8000", "control_panel_api.wsgi:application"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
HOST=0.0.0.0 | ||
PORT=8000 | ||
PROJECT=control-panel | ||
MODULE=control_panel_api | ||
VENV=venv | ||
BIN=${VENV}/bin | ||
|
||
-include .env | ||
export | ||
|
||
.PHONY: collectstatic dependencies help run test wait_for_db | ||
|
||
venv/bin: | ||
@if ${USE_VENV} && [ ! -d "${VENV}" ] ; then python3 -m venv ${VENV} ; fi | ||
|
||
## dependencies: Install dependencies | ||
dependencies: ${BIN} requirements.txt | ||
@echo | ||
@echo "> Fetching dependencies..." | ||
@${BIN}/pip3 install -r requirements.txt | ||
|
||
## collectstatic: Collect assets into static folder | ||
collectstatic: dependencies | ||
@echo | ||
@echo "> Collecting static assets..." | ||
@${BIN}/python3 manage.py collectstatic --noinput | ||
|
||
## run: Run webapp | ||
run: collectstatic | ||
@echo | ||
@echo "> Running webapp..." | ||
@${BIN}/gunicorn -b ${HOST}:${PORT} ${MODULE}.wsgi:application | ||
|
||
wait_for_db: | ||
@echo | ||
@echo "> Waiting for database..." | ||
@${BIN}/python3 wait_for_db | ||
|
||
## test: Run tests | ||
test: export DJANGO_SETTINGS_MODULE=${MODULE}.settings.test | ||
test: wait_for_db | ||
@echo | ||
@echo "> Running tests..." | ||
@NAMED_TESTS="$(shell if [ -n "${TEST_NAME}" ]; then echo "-k ${TEST_NAME}" ; fi)" && \ | ||
${BIN}/pytest --color=yes ${MODULE} $$NAMED_TESTS | ||
|
||
## docker-image: Build docker image | ||
docker-image: | ||
@echo | ||
@echo "> Building docker image..." | ||
@docker build -t ${PROJECT} . | ||
|
||
## docker-test: Run tests in Docker container | ||
docker-test: | ||
@echo | ||
@echo "> Running tests in Docker..." | ||
@docker-compose -f docker-compose.test.yml up --abort-on-container-exit | ||
|
||
help: Makefile | ||
@echo | ||
@echo " Commands in "$(PROJECT)":" | ||
@echo | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters