Skip to content

Commit

Permalink
Dockerized dev environment 😊
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony2261 committed Apr 6, 2024
1 parent b6ef383 commit b1c7864
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 17 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ text2sql-backend/coverage.xml
text2sql-backend/*.cover
text2sql-backend/*.log
text2sql-backend/.git
text2sql-backend/dataline/db.sqlite3

# Don't need tests or hooks
*/tests
Expand Down
52 changes: 36 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,15 @@ COPY text2sql-backend/pyproject.toml text2sql-backend/poetry.lock ./
RUN poetry config virtualenvs.in-project true && poetry install --only main --no-root

# -------------------------------
# PROD BUILD WITH MINIMAL DEPS
# BASE BUILD
# -------------------------------
# FROM python:3.11.8-alpine as prod
FROM python:3.11.6-slim-bookworm as prod
FROM python:3.11.6-slim-bookworm as base

# Setup supervisor and caddy
WORKDIR /home/dataline

# Install supervisor to manage be/fe processes
RUN pip install --no-cache-dir supervisor

# Install Caddy server
# RUN apk update && apk add caddy
RUN apt update && apt install caddy -y

# Install postgres connector dependencies
RUN apt update && apt install --no-install-recommends libpq5 -y

# Copy in supervisor config, frontend build, backend source
COPY supervisord.conf .
COPY --from=temp-frontend /home/dataline/frontend/dist /home/dataline/frontend/dist
COPY text2sql-frontend/Caddyfile /home/dataline/frontend/Caddyfile

# Move it to venv not .venv so supervisord does not cry
COPY --from=temp-backend /home/dataline/backend/.venv /home/dataline/backend/venv
ENV PATH="/home/dataline/backend/venv/bin:$PATH"
Expand All @@ -90,4 +76,38 @@ RUN mkdir -p /home/.dataline
# Supervisord will forward the env vars to the subprocess envs
ENV SQLITE_PATH="/home/.dataline/db.sqlite3"

# -------------------------------
# DEV BUILD WITH MINIMAL DEPS
# -------------------------------
FROM base as dev

WORKDIR /home/dataline/backend

# Running alembic and uvicorn without combining them in a bash -c command won't work
CMD ["bash", "-c", "python -m alembic upgrade head && python -m uvicorn main:app --port=7377 --host=0.0.0.0 --reload"]


# -------------------------------
# PROD BUILD WITH MINIMAL DEPS
# -------------------------------
# FROM python:3.11.8-alpine as prod
FROM base as prod

# Setup supervisor and caddy
WORKDIR /home/dataline

# Install supervisor to manage be/fe processes
RUN pip install --no-cache-dir supervisor

# Install Caddy server
# RUN apk update && apk add caddy
RUN apt update && apt install caddy -y


# Copy in supervisor config, frontend build, backend source
COPY supervisord.conf .
COPY --from=temp-frontend /home/dataline/frontend/dist /home/dataline/frontend/dist
COPY text2sql-frontend/Caddyfile /home/dataline/frontend/Caddyfile


CMD ["supervisord", "-n"]
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.8"

networks:
dataline:
driver: bridge

volumes:
dataline_dev:

services:
backend:
build:
context: .
target: dev
ports:
- "7377:7377"
volumes:
- dataline_dev:/home/.dataline # persist local sqlite db
- ./text2sql-backend/dataline:/home/dataline/backend/dataline
networks:
- dataline

frontend:
build:
context: ./text2sql-frontend
depends_on:
- backend
ports:
- "5173:5173"
volumes:
- ./text2sql-frontend:/app
networks:
- dataline
16 changes: 16 additions & 0 deletions text2sql-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# as production
FROM node:21-alpine

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

ENV NODE_ENV=local

EXPOSE 5173

CMD [ "npm", "run", "dev" ]
3 changes: 2 additions & 1 deletion text2sql-frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
// Tauri expects a fixed port, fail if that port is not available
server: {
strictPort: true,
host: true,
},
// to make use of `TAURI_PLATFORM`, `TAURI_ARCH`, `TAURI_FAMILY`,
// `TAURI_PLATFORM_VERSION`, `TAURI_PLATFORM_TYPE` and `TAURI_DEBUG`
Expand All @@ -19,7 +20,7 @@ export default defineConfig({
"@": path.resolve(__dirname, "src"),
"@components": path.resolve(__dirname, "src/components"),
"@catalyst": path.resolve(__dirname, "src/components/Catalyst"),
}
},
},
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
Expand Down

0 comments on commit b1c7864

Please sign in to comment.