Skip to content

Commit dd22fde

Browse files
xjadrnicAjcgd
authored andcommitted
feat: compose extension & GH action
1 parent 9b93e42 commit dd22fde

11 files changed

Lines changed: 169 additions & 169 deletions

File tree

.github/workflows/build-ui.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and Push UI Container
2+
3+
on:
4+
schedule:
5+
- cron: "0 10 * * *" # every day at 10am
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
workflow_dispatch:
11+
12+
jobs:
13+
build-ui:
14+
name: Build UI Container
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Login to GitHub Container Registry
25+
if: github.event_name != 'pull_request'
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.repository_owner }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ghcr.io/${{ github.repository_owner }}/fhir-ui
37+
tags: |
38+
type=schedule
39+
type=ref,event=branch
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
44+
45+
- name: Build and push UI container
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: ui/fhir-place
49+
file: ui/fhir-place/Dockerfile
50+
push: ${{ github.event_name != 'pull_request' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
55+
platforms: linux/amd64,linux/arm64

compose.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ services:
5252
target: "/opt/records"
5353
- fhir-logs:/var/log/fhir-module
5454

55+
fhir-ui:
56+
image: ghcr.io/bbmri-cz/fhir-ui:local
57+
container_name: fhir-ui
58+
profiles:
59+
- dev
60+
- prod
61+
networks:
62+
- fhir-integration
63+
- monitoring
64+
ports:
65+
- "3000:3000"
66+
env_file:
67+
- .env
68+
volumes:
69+
- ui-data:/app/data
70+
depends_on:
71+
- fhir-module
72+
5573
prometheus:
5674
image: prom/prometheus:latest
5775
depends_on:
@@ -136,3 +154,4 @@ volumes:
136154
fhir-logs:
137155
promtail-config:
138156
promtail-positions:
157+
ui-data:

ui/fhir-place/.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules
2+
.next
3+
.git
4+
.gitignore
5+
README.md
6+
Dockerfile
7+
.dockerignore
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
.env*.local
12+
.DS_Store
13+
*.tgz
14+
*.tar.gz

ui/fhir-place/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Build stage
2+
FROM node:18-alpine AS builder
3+
4+
# Install dependencies needed for native modules
5+
RUN apk add --no-cache libc6-compat python3 make g++
6+
7+
WORKDIR /app
8+
9+
# Copy package files
10+
COPY package*.json ./
11+
12+
# Install all dependencies (including devDependencies for build)
13+
RUN npm ci && npm cache clean --force
14+
15+
# Copy source code
16+
COPY . .
17+
18+
# Generate database schema and build the application
19+
RUN npm run db:generate
20+
RUN npm run build
21+
22+
# Production stage
23+
FROM node:18-alpine AS runner
24+
25+
WORKDIR /app
26+
27+
# Create a non-root user
28+
RUN addgroup -g 1001 -S nodejs
29+
RUN adduser -S nextjs -u 1001
30+
31+
# Copy necessary files from builder stage
32+
COPY --from=builder /app/public ./public
33+
COPY --from=builder /app/.next/standalone ./
34+
COPY --from=builder /app/.next/static ./.next/static
35+
36+
# Copy package.json for runtime dependencies
37+
COPY --from=builder /app/package.json ./package.json
38+
39+
# Copy database migration files if they exist
40+
COPY --from=builder /app/drizzle ./drizzle
41+
COPY --from=builder /app/src/scripts ./src/scripts
42+
43+
# Set correct permissions
44+
RUN chown -R nextjs:nodejs /app
45+
USER nextjs
46+
47+
# Expose port
48+
EXPOSE 3000
49+
50+
ENV PORT=3000
51+
ENV HOSTNAME="0.0.0.0"
52+
53+
# Start the application
54+
CMD ["node", "server.js"]

ui/fhir-place/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { InvalidCredentialsError, AuthenticationError } from "@/lib/errors";
88
import { LoginFormSchema } from "@/app/login/form/schema";
99

1010
const config = {
11+
trustHost:
12+
process.env.NODE_ENV === "development" ||
13+
process.env.AUTH_TRUST_HOST === "true",
1114
providers: [
1215
Credentials({
1316
name: "credentials",
@@ -88,10 +91,7 @@ const config = {
8891
session: {
8992
strategy: "jwt" as const,
9093
},
91-
secret:
92-
process.env.AUTH_SECRET ||
93-
process.env.SESSION_SECRET ||
94-
"your-secret-key-change-this-in-production",
94+
secret: process.env.AUTH_SECRET,
9595
};
9696

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

ui/fhir-place/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3.8"
2+
3+
services:
4+
fhir-ui:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "3000:3000"
10+
environment:
11+
- NODE_ENV=production
12+
- PORT=3000
13+
volumes:
14+
# Mount a volume for the SQLite database to persist data
15+
- ./data:/app/data
16+
restart: unless-stopped

ui/fhir-place/next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4+
output: "standalone",
45
/* config options here */
56
};
67

ui/fhir-place/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@radix-ui/react-hover-card": "^1.1.14",
1919
"@radix-ui/react-label": "^2.1.7",
2020
"@radix-ui/react-progress": "^1.1.7",
21+
"@radix-ui/react-select": "^2.1.1",
2122
"@radix-ui/react-slot": "^1.2.3",
2223
"@radix-ui/react-tabs": "^1.1.12",
2324
"bcryptjs": "^3.0.2",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ async function callBackendAPI(
1212
endpoint: string,
1313
method: string = "POST"
1414
): Promise<BackendActionResult> {
15+
console.log("BACKEND_BASE_URL", BACKEND_BASE_URL);
16+
1517
try {
1618
const response = await fetch(`${BACKEND_BASE_URL}${endpoint}`, {
1719
method,

ui/fhir-place/src/actions/prometheus/query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export async function queryPrometheusAction(
2626
};
2727
}
2828

29-
const prometheusUrl = `http://localhost:9090/api/v1/query`;
29+
const prometheusBaseUrl =
30+
process.env.PROMETHEUS_URL || "http://prometheus:9090";
31+
const prometheusUrl = `${prometheusBaseUrl}/api/v1/query`;
3032
const url = new URL(prometheusUrl);
3133
url.searchParams.append("query", query);
3234

0 commit comments

Comments
 (0)