Skip to content

Commit

Permalink
Include date & version in build
Browse files Browse the repository at this point in the history
  • Loading branch information
thgh committed Jan 13, 2024
1 parent a896ce3 commit ae6c6fd
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!bundle
!dist
!package.json
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ RUN apk add --no-cache docker
WORKDIR /app
COPY dist ./dist
COPY bundle .
COPY package.json ./package.json

# Replace "0.0.1-dev" & "0001-01-01T01:01:01Z" with version & date
RUN sed -i "s/0.0.1-dev/$(node -p -e "require('./package.json').version")/" index-*.*js && sed -i "s/0001-01-01T01:01:01Z/$(date -u +"%Y-%m-%dT%H:%M:%SZ")/" index-*.*js

EXPOSE 80
CMD ["node", "server.mjs"]
2 changes: 0 additions & 2 deletions bundle/server.d.cts

This file was deleted.

2 changes: 0 additions & 2 deletions bundle/server.d.mts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@hookform/resolvers": "^3.3.1",
"react-hook-form": "^7.46.2",
"sonner": "^1.3.1",
"ws": "^8.16.0",
"zod": "^3.22.2"
},
"devDependencies": {
Expand Down Expand Up @@ -88,6 +87,7 @@
"class-variance-authority": "^0.7.0",
"classnames": "^2.3.2",
"clsx": "^2.0.0",
"ws": "^8.16.0",
"cmdk": "^0.2.0",
"cookie-parser": "^1.4.6",
"eslint": "^8.49.0",
Expand Down
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { resolve } from 'node:path'
import express from 'express'

import { serverRouter } from './api'
import { buildDate, version } from './lib/env'
import { checkAuth, state } from './lib/state'

export function createServer(port: number) {
Expand All @@ -27,13 +28,11 @@ export function createServer(port: number) {
const credentials = await checkAuth().catch((err) => {
console.log(err)
})
if (credentials) {
console.log(
`📦 Hivepanel is running on http://localhost:${port}/#password=${credentials.password}`
)
} else {
console.log(`📦 Hivepanel is running on http://localhost:${port}`)
}
console.log(
`📦 Hivepanel ${version} ${buildDate}\nServer is listening on ${
state.origin
}${credentials ? `/#password=${credentials.password}` : ''}`
)
resolve(server)
})
})
Expand Down
5 changes: 5 additions & 0 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const port = parseInt(process.env.PORT || '80')
export const devPort = parseInt(process.env.PORT || '23088')

export const version = '0.0.1-dev'
export const buildDate = '0001-01-01T01:01:01Z'
10 changes: 5 additions & 5 deletions src/server.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { createServer } from 'vite'
import { serverRouter } from './api'
import { enableDNS } from './api/dns'
import { setupWebsocket } from './lib/docker'
import { devPort } from './lib/env'
import { checkAuth, state } from './lib/state'

enableDNS()
const app = express()
const port = process.env.PORT || 23088 // Default in production is 80

app.use(express.static('public'))
app.use(express.urlencoded({ extended: false }))
Expand All @@ -28,15 +28,15 @@ if (global.closeSignal) {
// First start
global.viteInstance ||= await createServer({ server: { middlewareMode: true } })
app.use(global.viteInstance.middlewares)
const server = app.listen(port, async () => {
state.origin = `http://localhost:${port}`
const server = app.listen(devPort, async () => {
state.origin = `http://localhost:${devPort}`
const credentials = await checkAuth()
if (credentials) {
console.log(
`📦 Hivepanel is running on http://localhost:${port}/#password=${credentials.password}`
`📦 Hivepanel is running on http://localhost:${devPort}/#password=${credentials.password}`
)
} else {
console.log(`📦 Hivepanel is running on http://localhost:${port}`)
console.log(`📦 Hivepanel is running on http://localhost:${devPort}`)
}
})
global.closeSignal = new Promise((resolve) =>
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createServer } from './index'
import { port } from './lib/env'

// Default port in dev is 23088
const port = parseInt(process.env.PORT || '80')
createServer(port)

// Listen for termination signals allows Ctrl+C in docker run
Expand Down

0 comments on commit ae6c6fd

Please sign in to comment.