Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend Container | Environment Variable Updates #41

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"username": "opendatarepository",
"database": "opendatarepository"
}
],
"basedpyright.analysis.extraPaths": [
"./modules/odr_api/",
"./modules/odr_core/"
]
}
14 changes: 7 additions & 7 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ tasks:
cmds:
- task --list

echo-project-root:
desc: Echo the project root directory. Helps ensure environment is set up and tasks will run.
cmds:
- echo USER WD {{.USER_WORKING_DIR}}
- echo USER_WORKING_DIRECTORY ${ROOT_DIR}
- echo ROOT ${ROOT_DIR}

setup:
desc: Setup the project
cmds:
Expand Down Expand Up @@ -109,3 +102,10 @@ tasks:
desc: Stop all running containers
cmds:
- docker compose down
dev:
desc: Start development environment with odr-api in watch mode and databases headless
cmds:
- docker compose up -d postgres pgadmin
- |
docker compose up --watch odr-api --build &
docker compose up --watch odr-frontend --build
68 changes: 67 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ services:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_PORT: 35432
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "${POSTGRES_PORT:-35432}:5432"
- 35432:5432
networks:
- omi-network

Expand All @@ -19,6 +21,15 @@ services:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_LISTEN_ADDRESS: 0.0.0.0
PGADMIN_CONFIG_SERVER_MODE: "False"
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: "False"
entrypoint: /bin/sh -c "chmod 600 /pgpass; /entrypoint.sh;"
user: root
configs:
- source: servers.json
target: /pgadmin4/servers.json
- source: pgpass
target: /pgpass
volumes:
- pgadmin_data:/var/lib/pgadmin
ports:
Expand All @@ -40,12 +51,67 @@ services:
- omi-network
depends_on:
- postgres
develop:
watch:
- action: sync
path: ./modules/odr_core
target: /app/modules/odr_core
- action: sync
path: ./modules/odr_api
target: /app/modules/odr_api
- action: sync
path: ./modules/odr_monitoring
target: /app/modules/odr_monitoring

odr-frontend:
build:
context: ./modules/odr_frontend
dockerfile: docker/Dockerfile.frontend.dev
volumes:
- ./modules/odr_frontend:/app
- odr_frontend_node_modules:/app/node_modules
- odr_frontend_pnpm_store:/app/.pnpm-store
ports:
- "5173:5173"
environment:
NODE_ENV: development
API_SERVICE_URL: http://odr-api:31100/api/v1
env_file:
- ./modules/odr_frontend/.env
networks:
- omi-network
develop:
watch:
- action: sync
path: ./modules/odr_frontend
target: /app
ignore:
- node_modules/
- .pnpm-store/

volumes:
postgres_data:
pgadmin_data:
odr_frontend_node_modules:
odr_frontend_pnpm_store:

networks:
omi-network:
external: true
driver: bridge

configs:
pgpass:
content: postgres:35432:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}
servers.json:
content: |
{"Servers": {"1": {
"Group": "Servers",
"Name": "Open Data Repository",
"Host": "postgres",
"Port": 35432,
"MaintenanceDB": "postgres",
"Username": "${POSTGRES_USER}",
"PassFile": "/pgpass",
"SSLMode": "prefer"
}}}
5 changes: 4 additions & 1 deletion modules/odr_api/docker/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY modules/odr_core /app/modules/odr_core
RUN pip install --no-cache-dir -e /app/modules/odr_core

COPY modules/odr_monitoring /app/modules/odr_monitoring
RUN pip install --no-cache-dir -e /app/modules/odr_monitoring

COPY modules/odr_api /app
RUN pip install --no-cache-dir .

Expand All @@ -31,4 +34,4 @@ EXPOSE 31100
# Set the entrypoint
# CMD ["tail", "-f", "/dev/null"]
ENTRYPOINT ["uvicorn"]
CMD ["odr_api.app:app", "--host", "0.0.0.0", "--port", "31100"]
CMD ["odr_api.app:app", "--host", "0.0.0.0", "--port", "31100", "--reload"]
6 changes: 3 additions & 3 deletions modules/odr_api/scripts/run_server.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run the FastAPI server with uvicorn

# Run the FastAPI server with multiple workers and log output to a file

./venv/Scripts/python ./modules/odr_api/odr_api/main.py
$env:PYTHONPATH = "."
./venv/Scripts/uvicorn.exe odr_api.app:app --host 0.0.0.0 --port 31100
4 changes: 3 additions & 1 deletion modules/odr_core/odr_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Config:

def get_db_url(self):
db_name = self.TEST_POSTGRES_DB if self.TEST else self.POSTGRES_DB
return f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{db_name}"

conn_str = f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{db_name}"
return conn_str


settings = Settings()
2 changes: 2 additions & 0 deletions modules/odr_core/odr_core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from odr_core.config import settings

# Create SQLAlchemy engine
url = settings.get_db_url()

engine = create_engine(settings.get_db_url())

# Create SessionLocal class
Expand Down
64 changes: 0 additions & 64 deletions modules/odr_database/docker/postgres-compose.yml

This file was deleted.

3 changes: 3 additions & 0 deletions modules/odr_datamodel/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ tasks:
desc: Migrate the database
cmds:
- alembic -c ./modules/odr_datamodel/alembic.ini upgrade head
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 35432

revision:
desc: Create a new revision, e.g. task data:revision -- "Add new column"
Expand Down
5 changes: 5 additions & 0 deletions modules/odr_frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.gitignore
npm-debug.log
./docker/Dockerfile*
.dockerignore
21 changes: 21 additions & 0 deletions modules/odr_frontend/docker/Dockerfile.frontend.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:22-alpine

WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# Copy package.json and pnpm-lock.yaml (if you have one)
COPY package.json pnpm-lock.yaml* ./

# Copy the entrypoint script
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

COPY template.env /app/.env

EXPOSE 5173

ENTRYPOINT ["/entrypoint.sh"]

CMD ["pnpm", "run", "dev", "--", "--host", "0.0.0.0"]
41 changes: 41 additions & 0 deletions modules/odr_frontend/docker/Dockerfile.frontend.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Build stage
### STUB : Not verified ####
FROM node:22-alpine AS builder

WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# Copy package.json and pnpm-lock.yaml (if you have one)
COPY package.json pnpm-lock.yaml* ./

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy the rest of the application code
COPY . .

# Build the application
RUN pnpm run build

# Production stage
FROM node:22-alpine

WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# Copy built assets from the builder stage
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json .

# Install only production dependencies
RUN pnpm install --prod

# Expose the application port
EXPOSE 3000

# Start the application
CMD ["node", "build"]
9 changes: 9 additions & 0 deletions modules/odr_frontend/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

echo "Installing dependencies..."
pnpm install


exec "$@"
7 changes: 5 additions & 2 deletions modules/odr_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"dev": "vite dev --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview",
"test": "npm run test:integration && npm run test:unit",
Expand All @@ -25,6 +25,7 @@
"@tailwindcss/typography": "0.5.14",
"@types/eslint": "^9.6.0",
"@types/node": "22.2.0",
"dotenv": "^16.0.3",
"autoprefixer": "10.4.20",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -35,12 +36,14 @@
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"sveltekit-superforms": "^2.17.0",
"tailwindcss": "3.4.10",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^5.0.3",
"vite-plugin-tailwind-purgecss": "0.3.3",
"vitest": "^2.0.0"
"vitest": "^2.0.0",
"zod": "^3.23.8"
},
"type": "module",
"dependencies": {
Expand Down
Loading
Loading