Skip to content

Commit 162f046

Browse files
committed
feat: UI dockerization tweaks
1 parent dd22fde commit 162f046

9 files changed

Lines changed: 95 additions & 50 deletions

File tree

compose.yaml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@ services:
1111
env_file:
1212
- .env
1313

14-
cadvisor:
15-
image: gcr.io/cadvisor/cadvisor:latest
16-
container_name: cadvisor
17-
networks:
18-
- monitoring
19-
ports:
20-
- "8081:8080"
21-
volumes:
22-
- /:/rootfs:ro
23-
- /var/run:/var/run:ro
24-
- /sys:/sys:ro
25-
- /var/lib/docker/:/var/lib/docker:ro
26-
- /var/run/docker.sock:/var/run/docker.sock:ro
27-
profiles:
28-
- dev
29-
- prod
30-
31-
# TODO Change to latest
3214
fhir-module:
3315
image: ghcr.io/bbmri-cz/fhir-module:latest
3416
container_name: fhir-module
@@ -39,7 +21,7 @@ services:
3921
- fhir-integration
4022
- monitoring
4123
ports:
42-
- "5001:5000"
24+
- "5000:5000"
4325
environment:
4426
BLAZE_URL: "http://test-blaze:8080/fhir"
4527
MIABIS_BLAZE_URL: "http://miabis-blaze:8080/fhir"
@@ -53,7 +35,7 @@ services:
5335
- fhir-logs:/var/log/fhir-module
5436

5537
fhir-ui:
56-
image: ghcr.io/bbmri-cz/fhir-ui:local
38+
image: ghcr.io/bbmri-cz/fhir-ui:latest
5739
container_name: fhir-ui
5840
profiles:
5941
- dev
@@ -69,6 +51,7 @@ services:
6951
- ui-data:/app/data
7052
depends_on:
7153
- fhir-module
54+
restart: unless-stopped
7255

7356
prometheus:
7457
image: prom/prometheus:latest

ui/fhir-place/Dockerfile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ COPY . .
1717

1818
# Generate database schema and build the application
1919
RUN npm run db:generate
20+
RUN mkdir -p /app/data
21+
22+
# Create and initialize the database during build
23+
RUN npm run db:migrate
24+
RUN npm run db:init
25+
2026
RUN npm run build
2127

2228
# Production stage
2329
FROM node:18-alpine AS runner
2430

2531
WORKDIR /app
2632

33+
# Install tsx for TypeScript execution
34+
RUN npm install -g tsx
35+
2736
# Create a non-root user
2837
RUN addgroup -g 1001 -S nodejs
2938
RUN adduser -S nextjs -u 1001
@@ -36,12 +45,20 @@ COPY --from=builder /app/.next/static ./.next/static
3645
# Copy package.json for runtime dependencies
3746
COPY --from=builder /app/package.json ./package.json
3847

39-
# Copy database migration files if they exist
48+
# Copy database migration files and scripts
4049
COPY --from=builder /app/drizzle ./drizzle
4150
COPY --from=builder /app/src/scripts ./src/scripts
51+
COPY --from=builder /app/src/lib ./src/lib
52+
53+
# Copy startup script
54+
COPY start.sh /app/start.sh
55+
56+
# Create data directory for SQLite database
57+
RUN mkdir -p /app/data
4258

4359
# Set correct permissions
4460
RUN chown -R nextjs:nodejs /app
61+
RUN chmod +x /app/start.sh
4562
USER nextjs
4663

4764
# Expose port
@@ -50,5 +67,5 @@ EXPOSE 3000
5067
ENV PORT=3000
5168
ENV HOSTNAME="0.0.0.0"
5269

53-
# Start the application
54-
CMD ["node", "server.js"]
70+
# Start the application with database initialization
71+
CMD ["/app/start.sh"]

ui/fhir-place/README.md

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,75 @@
1-
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
1+
# FHIR Place UI
22

3-
## Getting Started
3+
A Next.js application for managing FHIR data with authentication and SQLite database.
44

5-
First, run the development server:
5+
## Features
66

7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
15-
```
7+
- User authentication with NextAuth.js
8+
- SQLite database for data persistence
9+
- Modern UI with Tailwind CSS
10+
- Docker support for containerized deployment
1611

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
12+
## Development
1813

19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
14+
### Prerequisites
2015

21-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
16+
- Node.js 18+
17+
- npm or yarn
2218

23-
## Learn More
19+
### Local Development
2420

25-
To learn more about Next.js, take a look at the following resources:
21+
1. Install dependencies:
2622

27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
23+
```bash
24+
npm install
25+
```
2926

30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
27+
2. Initialize the database:
3128

32-
## Deploy on Vercel
29+
```bash
30+
npm run db:init
31+
```
3332

34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
3. Start the development server:
3534

36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
35+
```bash
36+
npm run dev
37+
```
38+
39+
4. Open [http://localhost:3000](http://localhost:3000) in your browser.
40+
41+
## Docker Deployment
42+
43+
The application is configured to run in Docker containers with the main `compose.yaml` file.
44+
45+
### Environment Variables
46+
47+
The following environment variables are required:
48+
49+
- `NEXTAUTH_SECRET`: Secret key for NextAuth.js (change in production)
50+
- `AUTH_TRUST_HOST`: Set to `true` for Docker deployment
51+
- `NODE_ENV`: Set to `production` for Docker
52+
- `PORT`: Application port (default: 3000)
53+
54+
### Running with Docker Compose
55+
56+
1. From the project root, run:
57+
58+
```bash
59+
docker-compose --profile dev up fhir-ui
60+
```
61+
62+
2. The UI will be available at [http://localhost:3000](http://localhost:3000)
63+
64+
### Database
65+
66+
The SQLite database is stored in the `/app/data` directory and persisted using Docker volumes. The database will be automatically initialized on first run.
67+
68+
## Available Scripts
69+
70+
- `npm run dev`: Start development server
71+
- `npm run build`: Build for production
72+
- `npm run start`: Start production server
73+
- `npm run db:init`: Initialize database with seed data
74+
- `npm run db:generate`: Generate database schema
75+
- `npm run db:migrate`: Run database migrations

ui/fhir-place/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const config = {
9191
session: {
9292
strategy: "jwt" as const,
9393
},
94-
secret: process.env.AUTH_SECRET,
94+
secret: process.env.NEXTAUTH_SECRET,
9595
};
9696

9797
export const { handlers, signIn, signOut, auth } = NextAuth(config);

ui/fhir-place/drizzle.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default defineConfig({
55
out: "./drizzle",
66
dialect: "sqlite",
77
dbCredentials: {
8-
url: "./database.sqlite",
8+
url: "./data/database.sqlite",
99
},
1010
});

ui/fhir-place/src/actions/backend/backend-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface BackendActionResult {
66
data?: unknown;
77
}
88

9-
const BACKEND_BASE_URL = process.env.BACKEND_API_URL || "http://localhost:5001";
9+
const BACKEND_BASE_URL = process.env.BACKEND_API_URL || "http://localhost:5000";
1010

1111
async function callBackendAPI(
1212
endpoint: string,

ui/fhir-place/src/lib/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DatabaseError,
1111
} from "./errors";
1212
import { validatePassword } from "./password-validation";
13+
import crypto from "crypto";
1314

1415
export interface CreateUserData {
1516
username: string;

ui/fhir-place/src/lib/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { drizzle } from "drizzle-orm/better-sqlite3";
33
import * as schema from "./schema";
44
import path from "path";
55

6-
const dbPath = path.join(process.cwd(), "database.sqlite");
6+
const dbPath = path.join(process.cwd(), "data", "database.sqlite");
77
const sqlite = new Database(dbPath);
88
const db = drizzle(sqlite, { schema });
99

ui/fhir-place/start.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
# Start the application
4+
echo "Starting Next.js application..."
5+
node server.js

0 commit comments

Comments
 (0)