Skip to content

Commit

Permalink
MAP-1943 redis8 & node22 (#747)
Browse files Browse the repository at this point in the history
* MAP-1943 redis 8 node 22

* MAP-1943 redis8 node 22 Dockerfile correction

* MAP-1943 redis8 node 22 Dockerfile correction
  • Loading branch information
marcusaleman authored Jan 7, 2025
1 parent 2202924 commit 5b39975
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ parameters:

node-version:
type: string
default: 20.15-browsers
default: 22.12-browsers

executors:
integration-tests:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.15-bookworm-slim as builder
FROM node:22.12-bookworm-slim as builder

ARG BUILD_NUMBER
ARG GIT_REF
Expand All @@ -22,7 +22,7 @@ RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit && \

RUN npm prune --production

FROM node:20.15-bookworm-slim
FROM node:22.12-bookworm-slim
LABEL maintainer="HMPPS Digital Studio <info@digital.justice.gov.uk>"

# Cache breaking
Expand Down
2 changes: 1 addition & 1 deletion job/sendReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const statementClient = new StatementsClient(db.query)
const reportLogClient = new ReportLogClient()
const incidentClient = new IncidentClient(db.query, db.inTransaction, reportLogClient)

const systemToken = systemTokenBuilder(new TokenStore(createRedisClient({ legacyMode: false })))
const systemToken = systemTokenBuilder(new TokenStore(createRedisClient()))
const emailResolver = new EmailResolver(token => new AuthClient(token), systemToken, statementClient)
const notificationService = notificationServiceFactory(eventPublisher)

Expand Down
104 changes: 54 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"security_audit": "npx audit-ci --config audit-ci.json"
},
"engines": {
"node": "^20",
"node": "^22",
"npm": "^10"
},
"jest": {
Expand Down Expand Up @@ -108,8 +108,8 @@
"bunyan-format": "^0.2.1",
"compression": "^1.7.4",
"connect-flash": "^0.1.1",
"connect-redis": "^6.1.3",
"cookie-parser": "^1.4.6",
"connect-redis": "^8.0.1",
"cookie-parser": "^1.4.7",
"cookie-session": "^2.1.0",
"csurf": "^1.11.0",
"cypress-axe": "^1.5.0",
Expand Down Expand Up @@ -146,7 +146,7 @@
"@types/hapi__joi": "^17.1.9",
"@types/http-errors": "^2.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^18.16.12",
"@types/node": "^22.10.2",
"@types/nunjucks": "^3.2.2",
"@types/pg": "^8.6.6",
"@types/superagent": "^4.1.17",
Expand Down
21 changes: 13 additions & 8 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import compression from 'compression'
import passport from 'passport'
import crypto from 'crypto'
import createError from 'http-errors'
import session from 'express-session'
import ConnectRedis from 'connect-redis'
import { createRedisClient } from './data/redisClient'
import session, { MemoryStore, Store } from 'express-session'
import { RedisStore } from 'connect-redis'
import { redisClient } from './data/redisClient'

import RequestLogger from './middleware/requestLogger'

import createRouter from './routes'
Expand Down Expand Up @@ -124,13 +125,17 @@ export default function createApp(services: Services): Express {
next()
})

const RedisStore = ConnectRedis(session)
const client = createRedisClient({ legacyMode: true })
client.connect()

let store: Store
if (config.redis.enabled) {
const client = redisClient
client.connect().catch((err: Error) => logger.error(`Error connecting to Redis`, err))
store = new RedisStore({ client })
} else {
store = new MemoryStore()
}
app.use(
session({
store: new RedisStore({ client }),
store,
cookie: { secure: config.https, sameSite: 'lax', maxAge: config.session.expiryMinutes * 60 * 1000 },
secret: config.session.secret,
resave: false, // redis implements touch so shouldn't need this
Expand Down
2 changes: 1 addition & 1 deletion server/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const dataAccess = {
telemetryClient,
draftReportClient,
reportLogClient,
systemToken: systemTokenBuilder(new TokenStore(createRedisClient({ legacyMode: false }))),
systemToken: systemTokenBuilder(new TokenStore(createRedisClient())),
authClientBuilder: ((token: string) => new AuthClient(token)) as RestClientBuilder<AuthClient>,
prisonClientBuilder: restClientBuilder<PrisonClient>('prisonApi', config.apis.prison, PrisonClient),
locationClientBuilder: restClientBuilder<LocationClient>('locationApi', config.apis.location, LocationClient),
Expand Down
1 change: 0 additions & 1 deletion server/data/prisonClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
PrisonerDetail,
CaseLoad,
Prison,
PrisonLocation,
} from './prisonClientTypes'

export default class PrisonClient {
Expand Down
5 changes: 3 additions & 2 deletions server/data/redisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ const url =
? `rediss://${config.redis.host}:${config.redis.port}`
: `redis://${config.redis.host}:${config.redis.port}`

export const createRedisClient = ({ legacyMode }: { legacyMode: boolean }): RedisClient => {
export const createRedisClient = (): RedisClient => {
const client = createClient({
url,
password: config.redis.password,
legacyMode,
socket: {
reconnectStrategy: (attempts: number) => {
// Exponential back off: 20ms, 40ms, 80ms..., capped to retry every 30 seconds
Expand All @@ -27,3 +26,5 @@ export const createRedisClient = ({ legacyMode }: { legacyMode: boolean }): Redi
client.on('error', (e: Error) => logger.error('Redis client error', e))
return client
}

export const redisClient = config.redis.enabled ? createRedisClient() : null
3 changes: 3 additions & 0 deletions server/services/reportSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ const getRestraintPositions = positions => {

const toParentChild = postions => {
const positionObjects = postions.map(p => findEnum(ControlAndRestraintPosition, p))
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parents: any[] = []
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const children: any[] = []
positionObjects.forEach(obj => {
if (obj.parent == null) {
Expand All @@ -165,6 +167,7 @@ const toParentChild = postions => {
}
})
const parentChild: string[] = []
// eslint-disable-next-line func-names
parents.forEach(function (p) {
const thesechildren = children
.filter(pos => pos.parent === p.value)
Expand Down

0 comments on commit 5b39975

Please sign in to comment.