Skip to content

Commit 51b166d

Browse files
authored
Merge pull request #4 from axelmarciano/feat/dashboard
feat: add dashboard & prometheus metrics
2 parents 9eb4ac3 + a261aba commit 51b166d

112 files changed

Lines changed: 11315 additions & 157 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Dockerfile

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
# Start with the official Golang base image
2-
FROM golang:1.23-alpine AS builder
1+
FROM node:18-alpine AS dashboard-builder
2+
WORKDIR /app/dashboard
3+
COPY dashboard/package.json dashboard/package-lock.json ./
4+
RUN npm ci
5+
COPY dashboard ./
6+
RUN npm run build
37

4-
# Set the Current Working Directory inside the container
8+
FROM golang:1.23-alpine AS builder
59
WORKDIR /app
6-
7-
# Copy go mod and sum files
810
COPY go.mod go.sum ./
9-
10-
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
1111
RUN go mod download
12-
13-
# Copy the source from the current directory to the Working Directory inside the container
1412
COPY cmd ./cmd
1513
COPY internal ./internal
1614
COPY keys ./keys
1715
COPY config ./config
1816
COPY updates ./updates
19-
20-
# Build the Go app
21-
RUN ls
2217
RUN GOOS=linux GOARCH=amd64 go build -o main ./cmd/api
2318

24-
# Start a new stage from scratch
2519
FROM alpine:latest
26-
27-
# Copy the Pre-built binary file from the previous stage
20+
RUN apk add --no-cache bash
2821
COPY --from=builder /app/main /app/main
29-
22+
COPY --from=dashboard-builder /app/dashboard/dist /app/dashboard/dist
3023
EXPOSE 3000
31-
32-
# Command to run the executable
3324
CMD ["/app/main"]

Dockerfile-ci

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
FROM node:18-alpine AS dashboard-builder
2+
3+
WORKDIR /app/dashboard
4+
5+
COPY dashboard/package.json dashboard/package-lock.json ./
6+
RUN npm ci
7+
8+
COPY dashboard ./
9+
RUN npm run build
10+
111
FROM golang:1.23-alpine
212

313
RUN apk add --no-cache git bash curl unzip entr make tar
@@ -6,4 +16,6 @@ RUN go install github.com/cespare/reflex@latest
616

717
ENV PATH="/go/bin:${PATH}"
818

19+
COPY --from=dashboard-builder /app/dashboard/dist /app/dashboard/dist
20+
921
CMD ["bash"]

Dockerfile-dev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ COPY keys ./keys
2626
COPY config ./config
2727
COPY updates ./updates
2828
COPY test ./test
29-
COPY commands ./commands
3029
RUN if [ -f .env ]; then cp .env /app/.env; fi
3130

3231

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ endif
2525

2626
test_app:
2727
ifeq ($(DOCKER_FLAG),docker)
28-
docker-compose exec ota-server sh -c "$(MAKE_COVERAGE_CMD)"
28+
docker-compose --profile test run --rm -e "" ota-server-test go test -v -coverprofile=coverage.out ./...
2929
else
3030
$(MAKE_COVERAGE_CMD)
3131
endif
@@ -42,9 +42,9 @@ endef
4242

4343
define CLEAN_COVERAGE
4444
if [ "$(shell uname -s)" = "Darwin" ]; then \
45-
sed -i '' -e '/test/d' -e '/commands/d' -e '/cmd/d' -e '/lambda/d' coverage.out; \
45+
sed -i '' -e '/test/d' -e '/cmd/d' coverage.out; \
4646
else \
47-
sed -i '/test/d;/commands/d;/cmd/d;/lambda/d' coverage.out; \
47+
sed -i '/test/d;/cmd/d;' coverage.out; \
4848
fi
4949
endef
5050

cmd/api/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@ package main
22

33
import (
44
"expo-open-ota/config"
5+
"expo-open-ota/internal/metrics"
56
"expo-open-ota/internal/router"
7+
"github.com/gorilla/handlers"
68
"log"
79
"net/http"
810
)
911

1012
func init() {
1113
config.LoadConfig()
14+
metrics.InitMetrics()
1215
}
1316

1417
func main() {
1518
router := infrastructure.NewRouter()
1619
log.Println("Server is running on port 3000")
17-
err := http.ListenAndServe(":3000", router)
20+
corsOptions := handlers.CORS(
21+
handlers.AllowedHeaders([]string{"Authorization", "Content-Type"}),
22+
handlers.AllowedMethods([]string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}),
23+
handlers.AllowedOrigins([]string{"*"}),
24+
handlers.AllowCredentials(),
25+
)
26+
err := http.ListenAndServe(":3000", corsOptions(router))
1827
if err != nil {
1928
log.Fatalf("Server failed to start: %v", err)
2029
}

dashboard/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

dashboard/.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"bracketSameLine": true,
6+
"trailingComma": "es5",
7+
"arrowParens": "avoid",
8+
"endOfLine": "auto"
9+
}

dashboard/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## Expanding the ESLint configuration
11+
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
14+
- Configure the top-level `parserOptions` property like this:
15+
16+
```js
17+
export default tseslint.config({
18+
languageOptions: {
19+
// other options...
20+
parserOptions: {
21+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
22+
tsconfigRootDir: import.meta.dirname,
23+
},
24+
},
25+
})
26+
```
27+
28+
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29+
- Optionally add `...tseslint.configs.stylisticTypeChecked`
30+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31+
32+
```js
33+
// eslint.config.js
34+
import react from 'eslint-plugin-react'
35+
36+
export default tseslint.config({
37+
// Set the react version
38+
settings: { react: { version: '18.3' } },
39+
plugins: {
40+
// Add the react plugin
41+
react,
42+
},
43+
rules: {
44+
// other rules...
45+
// Enable its recommended rules
46+
...react.configs.recommended.rules,
47+
...react.configs['jsx-runtime'].rules,
48+
},
49+
})
50+
```

dashboard/components.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": false,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "src/index.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"lib": "@/lib",
18+
"hooks": "@/hooks"
19+
},
20+
"iconLibrary": "lucide"
21+
}

dashboard/eslint.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
export default tseslint.config(
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
},
28+
)

0 commit comments

Comments
 (0)