Skip to content

Commit

Permalink
Fix workflows and Dockerfiles
Browse files Browse the repository at this point in the history
Fix ruff lint

Cleanup db-init
  • Loading branch information
mslwang committed Sep 27, 2024
1 parent 5172831 commit 726e9a5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 65 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

26 changes: 12 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ on:
- main
paths:
- "frontend/**"
- "backend/typescript/**"
- "backend/python/**"
- "backend/**"
pull_request:
branches:
- main
paths:
- "frontend/**"
- "backend/typescript/**"
- "backend/python/**"
- "backend/**"

jobs:
run-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Filter changed files
uses: dorny/paths-filter@v2
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
Expand All @@ -35,23 +33,23 @@ jobs:
- name: Set up Node.js
if: steps.changes.outputs.frontend == 'true'
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: "20.11.1"
cache: "yarn"
cache: "npm"
cache-dependency-path: |
frontend/yarn.lock
frontend/package-lock.json
- name: Install Node.js dependencies
if: steps.changes.outputs.frontend == 'true'
run: yarn --cwd ./frontend --prefer-offline
run: npm ci --prefix ./frontend

- name: Lint frontend
if: steps.changes.outputs.frontend == 'true'
working-directory: ./frontend
run: yarn lint
run: npm run lint

- name: Lint Python backend
if: steps.changes.outputs.python-backend == 'true'
working-directory: ./backend/python
run: pip install black && python -m black --check .
if: steps.changes.outputs.backend == 'true'
working-directory: ./backend
run: pip install ruff && ruff check .
10 changes: 5 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ FROM python:3.12

WORKDIR /app

COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY . ./app
COPY pyproject.toml ./
COPY pdm.lock ./
RUN pip install pdm && pdm install
COPY . .

EXPOSE 8080
ENTRYPOINT ["python", "server.py"]
CMD ["pdm", "run", "fastapi", "run", "app/server.py", "--port", "8080"]
8 changes: 1 addition & 7 deletions backend/app/server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import uvicorn
from dotenv import load_dotenv
from typing import Union
from fastapi import FastAPI

load_dotenv()
app = FastAPI()

@app.get("/")
Expand All @@ -14,8 +13,3 @@ def read_root():
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}

if __name__ == "__main__":
load_dotenv()

uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 8080)))
22 changes: 0 additions & 22 deletions db-init/create-multiple-dbs.sh

This file was deleted.

23 changes: 7 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,35 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- ./frontend:/app
- /app/node_modules
ports:
- 3000:3000
environment:
- CHOKIDAR_USEPOLLING=true
env_file:
- ./frontend/.env
py-backend:
container_name: llsc_py_backend
backend:
container_name: llsc_backend
restart: always
build:
context: ./backend/python
context: ./backend
dockerfile: Dockerfile
ports:
- 8080:8080
dns:
- 8.8.8.8
volumes:
- ./backend/python:/app
depends_on:
db:
condition: service_healthy
env_file:
- ./.env
db:
container_name: llsc_db
image: postgres:12-alpine
image: postgres:16-alpine
ports:
- 5432:5432
volumes:
- postgres_data:/var/lib/postgresql/data/
- ./db-init:/docker-entrypoint-initdb.d
env_file:
- ./.env
environment:
- POSTGRES_MULTIPLE_DATABASES=${POSTGRES_DB_DEV},${POSTGRES_DB_TEST}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DATABASE}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
Expand Down
11 changes: 11 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20.11.1

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm install

COPY . .

EXPOSE 3000
CMD ["npm", "run", "dev"]

0 comments on commit 726e9a5

Please sign in to comment.