mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f024b0166f | ||
|
|
d6889a27b5 | ||
|
|
edbc72a7c9 | ||
|
|
7e82b42b29 | ||
|
|
f5c835b5d9 |
19
Dockerfile
19
Dockerfile
@@ -6,9 +6,13 @@ WORKDIR /app
|
|||||||
COPY package.json package-lock.json* ./
|
COPY package.json package-lock.json* ./
|
||||||
COPY ./prisma ./prisma
|
COPY ./prisma ./prisma
|
||||||
|
|
||||||
|
# Install all dependencies (including devDependencies)
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
|
# Generate Prisma client
|
||||||
RUN npx prisma generate
|
RUN npx prisma generate
|
||||||
|
|
||||||
|
# Build the application
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
@@ -19,13 +23,16 @@ WORKDIR /app
|
|||||||
|
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
|
|
||||||
# Install production dependencies INCLUDING prisma
|
# Copy package files
|
||||||
COPY package.json package-lock.json* ./
|
COPY package.json package-lock.json* ./
|
||||||
RUN npm install --production --ignore-scripts
|
|
||||||
|
|
||||||
# Copy needed Prisma files
|
# Copy node_modules from builder
|
||||||
COPY --from=builder /app/node_modules/.prisma /app/node_modules/.prisma
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
COPY --from=builder /app/node_modules/@prisma /app/node_modules/@prisma
|
|
||||||
|
# Remove dev dependencies
|
||||||
|
RUN npm prune --production
|
||||||
|
|
||||||
|
# Copy Prisma files
|
||||||
COPY --from=builder /app/prisma ./prisma
|
COPY --from=builder /app/prisma ./prisma
|
||||||
|
|
||||||
# Copy built application
|
# Copy built application
|
||||||
@@ -36,5 +43,5 @@ COPY --from=builder /app/next.config.js* ./
|
|||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Run migrations first, then start app
|
# Run migrations and start
|
||||||
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]
|
CMD ["sh", "-c", "npx prisma migrate deploy && npm start"]
|
||||||
@@ -102,38 +102,70 @@ func getApplications(db *sql.DB) []Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
func checkAndUpdateStatus(db *sql.DB, client *http.Client, apps []Application) {
|
||||||
for _, app := range apps {
|
fmt.Printf("Start checking %d applications at %v\n", len(apps), time.Now())
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "HEAD", app.PublicURL, nil)
|
for i, app := range apps {
|
||||||
|
logPrefix := fmt.Sprintf("[App %d/%d URL: %s]", i+1, len(apps), app.PublicURL)
|
||||||
|
fmt.Printf("%s Starting check\n", logPrefix)
|
||||||
|
|
||||||
|
// HTTP Check
|
||||||
|
startHTTP := time.Now()
|
||||||
|
httpCtx, httpCancel := context.WithTimeout(context.Background(), 4*time.Second)
|
||||||
|
defer httpCancel()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(httpCtx, "HEAD", app.PublicURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating request: %v\n", err)
|
fmt.Printf("%s Request creation failed: %v\n", logPrefix, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
isOnline := false
|
httpDuration := time.Since(startHTTP)
|
||||||
if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
|
||||||
isOnline = true
|
// Log HTTP details
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s HTTP error after %v: %v\n", logPrefix, httpDuration, err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s HTTP %d after %v (ContentLength: %d)\n",
|
||||||
|
logPrefix, resp.StatusCode, httpDuration, resp.ContentLength)
|
||||||
|
resp.Body.Close() // Important to prevent leaks
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(ctx,
|
isOnline := err == nil && resp != nil && resp.StatusCode >= 200 && resp.StatusCode < 300 || resp.StatusCode == 405
|
||||||
|
|
||||||
|
// Database Update
|
||||||
|
dbCtx, dbCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer dbCancel()
|
||||||
|
|
||||||
|
startUpdate := time.Now()
|
||||||
|
updateRes, err := db.ExecContext(dbCtx,
|
||||||
`UPDATE application SET online = $1 WHERE id = $2`,
|
`UPDATE application SET online = $1 WHERE id = $2`,
|
||||||
isOnline,
|
isOnline,
|
||||||
app.ID,
|
app.ID,
|
||||||
)
|
)
|
||||||
|
updateDuration := time.Since(startUpdate)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Update failed for app %d: %v\n", app.ID, err)
|
fmt.Printf("%s UPDATE failed after %v: %v\n", logPrefix, updateDuration, err)
|
||||||
|
} else {
|
||||||
|
affected, _ := updateRes.RowsAffected()
|
||||||
|
fmt.Printf("%s UPDATE OK (%d rows) after %v\n", logPrefix, affected, updateDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(ctx,
|
// History Insert
|
||||||
|
startInsert := time.Now()
|
||||||
|
insertRes, err := db.ExecContext(dbCtx,
|
||||||
`INSERT INTO uptime_history ("applicationId", online, "createdAt") VALUES ($1, $2, now())`,
|
`INSERT INTO uptime_history ("applicationId", online, "createdAt") VALUES ($1, $2, now())`,
|
||||||
app.ID,
|
app.ID,
|
||||||
isOnline,
|
isOnline,
|
||||||
)
|
)
|
||||||
|
insertDuration := time.Since(startInsert)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Insert into uptime_history failed for app %d: %v\n", app.ID, err)
|
fmt.Printf("%s INSERT failed after %v: %v\n", logPrefix, insertDuration, err)
|
||||||
|
} else {
|
||||||
|
inserted, _ := insertRes.RowsAffected()
|
||||||
|
fmt.Printf("%s INSERT OK (%d rows) after %v\n", logPrefix, inserted, insertDuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -4545,21 +4545,6 @@
|
|||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"node_modules/@next/swc-win32-x64-msvc": {
|
|
||||||
"version": "15.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.3.0.tgz",
|
|
||||||
"integrity": "sha512-vHUQS4YVGJPmpjn7r5lEZuMhK5UQBNBRSB+iGDvJjaNk649pTIcRluDWNb9siunyLLiu/LDPHfvxBtNamyuLTw==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"win32"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 10"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user