Skip to content

Commit b2c991c

Browse files
EhabYm-adawi
andauthored
feat: add test infrastructure for the web UI (#81)
* Fix sonar lint issues and formatting * Add test infrastructure + test StatusCard and StatusCardList components * Add test to docker file * Review comments * Use Dockerfile as source of truth instead of a GitHub action * revert docker-ci to main --------- Co-authored-by: Malek Adawi <[email protected]>
1 parent f9813e1 commit b2c991c

File tree

15 files changed

+910
-37
lines changed

15 files changed

+910
-37
lines changed

Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
FROM node:22-alpine3.19 AS ui
1+
# Stage 1: Build the frontend
2+
FROM node:22-alpine3.19 AS frontend-build
23
WORKDIR /ui
3-
COPY ui/package.json ui/package-lock.json .
4+
COPY ui/package.json ui/package-lock.json ./
45
RUN npm install
5-
COPY ui/ .
6+
COPY ui/ ./
67
RUN npm run build
8+
# Fail this stage if tests fail
9+
RUN npm run test
710

8-
FROM golang:1.22.5 AS backend
11+
# Stage 2: Build the backend
12+
FROM golang:1.22.5 AS backend-build
13+
WORKDIR /backend
914
COPY go.mod go.sum ./
1015
RUN go mod download
1116
COPY cmd/ cmd/
1217
COPY util/ util/
13-
COPY web/ web/
18+
COPY web/ web/
1419
COPY swarmcd/ swarmcd/
1520
RUN CGO_ENABLED=0 GOOS=linux go build -o /swarm-cd ./cmd/
1621

22+
# Stage 3: Final production image (depends on previous stages)
1723
FROM alpine:3.2
1824
WORKDIR /app
1925
RUN apk add --no-cache ca-certificates && update-ca-certificates
20-
COPY --from=ui /ui/dist/ .
21-
COPY --from=backend /swarm-cd .
26+
# Copy the built backend binary from the backend build stage
27+
COPY --from=backend-build /swarm-cd /app/
28+
# Copy the built frontend from the frontend build stage
29+
COPY --from=frontend-build /ui/dist/ /app/ui/
30+
# Set the entry point for the application
2231
CMD ["/app/swarm-cd"]

ui/.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = {
55
"eslint:recommended",
66
"plugin:@typescript-eslint/recommended",
77
"plugin:react/recommended",
8-
"plugin:react-hooks/recommended"
8+
"plugin:react-hooks/recommended",
9+
"plugin:react/jsx-runtime"
910
],
1011
ignorePatterns: ["dist", ".eslintrc.cjs"],
1112
parser: "@typescript-eslint/parser",

ui/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ swarm-cd-ui/
2121
│ ├── hooks/ # React hooks
2222
│ ├── App.tsx # Main App component
2323
│ ├── index.tsx # Entry point
24+
├── tests/ # Test files
2425
├── package.json # Project metadata and scripts
2526
└── vite.config.ts # Vite configuration
27+
└── vitest.config.ts # Vitest configuration
2628
```
2729

2830
Recommended `.vscode/settings.json`:

0 commit comments

Comments
 (0)