Skip to content

Commit

Permalink
updating dockerfile to include api server (#14)
Browse files Browse the repository at this point in the history
The existing dockerfile only ran the frontend React app. It needed to
have the Python API included.

- Switched from alpine to ubuntu because alpine was giving me grief
about installing python requirements, but this required following the
node people's cumbersome instructions for how to get an even remotely
up-to-date version of node because ubuntu defaults to v12 😱
- Created a shell script per docker recommendations to start the
frontend and backend servers (took some time to track down that I now
need to provide the aught host param to vite to expose the web interface
outside the container)
  • Loading branch information
krachwal authored Jan 2, 2024
2 parents c4f7668 + 4f80391 commit 89b57b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
44 changes: 26 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
# syntax=docker/dockerfile:1
# This docker container runs the web portal
# Slim Linux image
FROM alpine:latest
FROM ubuntu:latest
LABEL description="Ramanujan Machine Web Portal"

# set working directory
WORKDIR /srv/ramanujan-machine-portal

# install node
RUN apk update && apk add nodejs npm
RUN apt-get update && apt-get -y install python3 python3-pip ca-certificates curl gnupg

COPY ./react-frontend/package.json ./
COPY ./react-frontend/package-lock.json ./
COPY ./react-frontend/tsconfig.json ./
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
ENV NODE_MAJOR=20
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

# install node package dependencies
RUN npm ci
RUN apt-get update && apt-get -y install nodejs

COPY ./react-frontend ./

# Copy project files
COPY ./react-frontend/src ./src
COPY ./react-frontend/public ./public
# install node package dependencies
RUN npm install

# Build project
# Build frontend project
RUN npm run build

# remove dev dependencies
RUN npm prune --production
# RUN npm install -g serve
# copy API files
COPY ./python-backend/Pipfile* ./
COPY ./python-backend/*.py ./
COPY ./python-backend/requirements.txt ./

# install Python dependencies
RUN pip3 install -r requirements.txt
RUN pip3 install uvicorn

EXPOSE 5173
EXPOSE 8000

EXPOSE 3000
#ENTRYPOINT ["serve", "-s", "build"]
ENTRYPOINT ["npm", "run", "start"]
COPY docker_start.sh docker_start.sh
RUN chmod +x docker_start.sh
CMD ./docker_start.sh
13 changes: 13 additions & 0 deletions docker_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Start the first process
npx vite --host "0.0.0.0" --port 5173 &

# Start the second process
uvicorn main:app --host "0.0.0.0" --port 8000 &

# Wait for any process to exit
wait -n

# Exit with status of process that exited first
exit $?

0 comments on commit 89b57b3

Please sign in to comment.