Skip to content

Commit

Permalink
build: refactor multistage docker builds (#87)
Browse files Browse the repository at this point in the history
Move dev builds for frontend/backend in main Dockerfiles
to reduce duplication
  • Loading branch information
alubbock authored Oct 2, 2024
1 parent 403cb87 commit 3ef9cea
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: backend
target: prod
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: quay.io/rosalindfranklininstitute/antigen-app-backend:latest
Expand All @@ -38,6 +39,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: frontend
target: prod
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: quay.io/rosalindfranklininstitute/antigen-app-frontend:latest
22 changes: 21 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COPY antigenapi /usr/src/antigenapi

RUN DJANGO_CI=true .venv/bin/python manage.py collectstatic --noinput

FROM python:3.11-slim-bullseye
FROM python:3.11-slim-bullseye AS prod

RUN apt-get update && apt-get install -y \
libxml2 \
Expand All @@ -39,3 +39,23 @@ RUN adduser --uid 10191 --gid 10191 --system --no-create-home nonroot
USER nonroot

CMD [".venv/bin/uwsgi", "--ini", "uwsgi.ini"]

FROM python:3.11-bullseye AS dev

RUN python -m pip install wheel pipenv

COPY Pipfile Pipfile.lock pyproject.toml setup.cfg /usr/src/
WORKDIR /usr/src

RUN python -m pipenv install --system --verbose
RUN python -m pipenv install --dev

COPY manage.py /usr/src/
COPY antigendjango /usr/src/antigendjango
COPY antigenapi /usr/src/antigenapi

RUN DJANGO_CI=true python manage.py collectstatic --noinput \
&& mkdir /api_data/ \
&& mv ./static/ /api_data/static/

CMD ["python", "manage.py", "runserver", "0.0.0.0:8080"]
19 changes: 0 additions & 19 deletions backend/Dockerfile-dev

This file was deleted.

4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
container_name: antigenapp_app
build:
context: frontend
dockerfile: Dockerfile-dev
target: dev
restart: always
ports:
- 3000:3000
Expand All @@ -15,7 +15,7 @@ services:
container_name: antigenapp_api
build:
context: backend
dockerfile: Dockerfile-dev
target: dev
restart: always
volumes:
- ./backend:/usr/src
Expand Down
8 changes: 6 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.hub.docker.com/library/node:18-alpine as build-stage
FROM registry.hub.docker.com/library/node:18-alpine AS dev

ENV ANTIGENAPP_DIR /antigenapp

Expand All @@ -10,9 +10,13 @@ RUN npm install

COPY . ${ANTIGENAPP_DIR}

CMD ["npm", "start"]

FROM dev AS build-stage

RUN npm run build

FROM nginx:stable-alpine as prod
FROM nginx:stable-alpine AS prod

COPY --from=build-stage /antigenapp/build/ /usr/share/nginx/html
COPY nginx-check-env.sh /docker-entrypoint.d/nginx-check-env.sh
Expand Down
13 changes: 0 additions & 13 deletions frontend/Dockerfile-dev

This file was deleted.

0 comments on commit 3ef9cea

Please sign in to comment.