Skip to content

Commit

Permalink
🐋 Add Dockerfile (#21)
Browse files Browse the repository at this point in the history
* Add Dockerfile

Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>

* Pin sass

Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>

* Copy js and other static assets

* Add entrypoint

Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>

* Copy project source code, and update dependencies

* Add run.md
Update entrypoint.sh

Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>

* Add collectstatic to Dockerfile

* 🐳 Buildable Dockerfile

* Update runsever command for production

* Some linting fixes

* Fix spacing in entrypoint.sh

* Add missing WORKDIR, more spacing fixes

* Use no cache flag with pip in Dockerfile

* Pin apk versions in Dockerfile

* Condense RUN commands in Dockerfile

* Delete run.md

* 🐳 Update Dockerfile to keep libpq-dev

---------

Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>
Co-authored-by: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com>
Co-authored-by: Gary H <26419401+Gary-H9@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 29, 2023
1 parent eb482c6 commit 9891ce0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM public.ecr.aws/docker/library/node:20.9.0 AS build-node

WORKDIR /
COPY package.json package-lock.json ./
COPY controlpanel/interfaces/web/static/app.scss ./controlpanel/interfaces/web/static/app.scss

RUN npm install \
&& npm run css

FROM public.ecr.aws/docker/library/python:3.11-alpine3.18 AS final

RUN apk add --no-cache --virtual .build-deps \
libffi-dev=3.4.4-r2 \
gcc=12.2.1_git20220924-r10 \
musl-dev=1.2.4-r2 \
&& apk add --no-cache libpq-dev=15.5-r0

WORKDIR /controlpanel

RUN mkdir --parents static/assets/fonts \
&& mkdir --parents static/assets/images \
&& mkdir --parents static/assets/js

COPY --from=build-node static/app.css static/app.css
COPY --from=build-node node_modules/govuk-frontend/govuk/assets/fonts/. static/assets/fonts
COPY --from=build-node node_modules/govuk-frontend/govuk/assets/images/. static/assets/images
COPY --from=build-node node_modules/govuk-frontend/govuk/all.js static/assets/js/govuk.js
COPY scripts/container/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY requirements.txt manage.py ./
COPY controlpanel controlpanel

RUN pip install --no-cache-dir --requirement requirements.txt \
&& chmod +x /usr/local/bin/entrypoint.sh \
&& python manage.py collectstatic --noinput --ignore=*.scss \
&& apk del .build-deps

EXPOSE 8000

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["run"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"devDependencies": {
"sass": "^1.69.5"
"sass": "1.69.5"
},
"dependencies": {
"govuk-frontend": "4.7.0"
Expand Down
18 changes: 18 additions & 0 deletions scripts/container/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

MODE=${MODE:-"run"}

case "$MODE" in
"run")
echo "Running Django server"
gunicorn -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker -w 4 controlpanel.asgi:application
;;
"migrate")
echo "Running Django migrations"
python manage.py migrate
;;
*)
echo "Unknown mode: $MODE"
exit 1
;;
esac

0 comments on commit 9891ce0

Please sign in to comment.