Skip to content

Commit 59df5c8

Browse files
committed
add app tests
1 parent ee0a27a commit 59df5c8

8 files changed

+118
-6
lines changed

app-tests/entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -m
4+
5+
npm start &
6+
./cache-offloader
7+
8+
fg %1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM node:16-bullseye-slim AS builder
2+
3+
RUN apt update && apt install -y git wget \
4+
&& git clone https://github.com/vercel/commerce.git \
5+
&& cd commerce \
6+
&& npm install --save-prod \
7+
&& NODE_ENV="production" npm run build \
8+
&& wget https://github.com/neurocode-io/cache-offloader/releases/download/v0.1.4/cache-offloader_0.1.4_linux_amd64.tar.gz \
9+
&& tar -xvf cache-offloader_0.1.4_linux_amd64.tar.gz
10+
11+
12+
FROM node:16-bullseye-slim
13+
14+
WORKDIR /app
15+
16+
ENV NODE_ENV="production"
17+
ENV NEXT_TELEMETRY_DISABLED="1"
18+
19+
COPY --from=builder /commerce/site/public ./public
20+
COPY --from=builder /commerce/site/.next ./.next
21+
COPY --from=builder /commerce/node_modules ./node_modules
22+
COPY --from=builder /commerce/site/package.json ./package.json
23+
COPY --from=builder /commerce/cache-offloader ./cache-offloader
24+
COPY entrypoint.sh .
25+
26+
ENV DOWNSTREAM_HOST=http://localhost:3000
27+
ENV CACHE_SHOULD_HASH_QUERY="true"
28+
ENV CACHE_STRATEGY=LFU
29+
ENV CACHE_SIZE_MB=10
30+
ENV CACHE_STALE_WHILE_REVALIDATE_SEC=60
31+
ENV SERVER_PORT=8000
32+
ENV SERVER_STORAGE=memory
33+
ENV CACHE_IGNORE_ENDPOINTS="/probes/liveness"
34+
ENV CACHE_IGNORE_ENDPOINTS="/probes/readiness"
35+
36+
RUN chown -R node:node /app
37+
38+
USER node
39+
EXPOSE 8000
40+
41+
ENTRYPOINT [ "./entrypoint.sh ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM node:16-bullseye-slim AS builder
2+
3+
RUN apt update && apt install -y git \
4+
&& git clone https://github.com/vercel/commerce.git \
5+
&& cd commerce \
6+
&& npm install --save-prod \
7+
&& npm install @next-boost/next-boost @next-boost/hybrid-disk-cache \
8+
&& NODE_ENV="production" npm run build \
9+
&& sed -i 's/next start/next-boost/g' site/package.json
10+
11+
12+
13+
FROM node:16-bullseye-slim
14+
15+
WORKDIR /app
16+
17+
ENV NODE_ENV="production"
18+
ENV NEXT_TELEMETRY_DISABLED="1"
19+
20+
COPY --from=builder /commerce/site/public ./public
21+
COPY --from=builder /commerce/site/.next ./.next
22+
COPY --from=builder /commerce/node_modules ./node_modules
23+
COPY --from=builder /commerce/site/package.json ./package.json
24+
25+
RUN chown -R node:node /app
26+
27+
USER node
28+
29+
EXPOSE 3000
30+
31+
32+
ENTRYPOINT [ "npm", "start" ]

app-tests/vercel-commerce.Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM node:16-bullseye-slim AS builder
2+
3+
RUN apt update && apt install -y git \
4+
&& git clone https://github.com/vercel/commerce.git \
5+
&& cd commerce \
6+
&& npm install --save-prod \
7+
&& NODE_ENV="production" npm run build
8+
9+
10+
FROM node:16-bullseye-slim
11+
12+
WORKDIR /app
13+
14+
ENV NODE_ENV="production"
15+
ENV NEXT_TELEMETRY_DISABLED="1"
16+
17+
COPY --from=builder /commerce/site/public ./public
18+
COPY --from=builder /commerce/site/.next ./.next
19+
COPY --from=builder /commerce/node_modules ./node_modules
20+
COPY --from=builder /commerce/site/package.json ./package.json
21+
22+
RUN chown -R node:node /app
23+
24+
USER node
25+
26+
EXPOSE 3000
27+
28+
29+
ENTRYPOINT [ "npm", "start" ]

config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func New() Config {
5858
Size: getEnvAsFloat("CACHE_SIZE_MB", "10"),
5959
IgnorePaths: getEnvAsSlice("CACHE_IGNORE_ENDPOINTS"),
6060
StaleInSeconds: getEnvAsInt("CACHE_STALE_WHILE_REVALIDATE_SEC", "5"),
61-
ShouldHashQuery: getEnvAsBool("CACHE_SHOULD_HASH_QUERY", ""),
61+
ShouldHashQuery: getEnvAsBool("CACHE_SHOULD_HASH_QUERY", "true"),
6262
HashQueryIgnore: hashQueryIgnoreMap(getEnvAsSlice("CACHE_HASH_QUERY_IGNORE")),
6363
}
6464

config/helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func getEnvAsLogLevel(key string) zerolog.Level {
5353
func getEnvAsSlice(key string) []string {
5454
strSlice, _ := os.LookupEnv(key)
5555
if strSlice == "" {
56-
log.Panic().Msgf("%s is not set", key)
56+
return []string{}
5757
}
5858

5959
return strings.Split(strSlice, ",")

dev.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ SHUTDOWN_GRACE_PERIOD=30
77

88
# CacheConfig
99
CACHE_SHOULD_HASH_QUERY="true"
10-
CACHE_HASH_QUERY_IGNORE=utm,live
10+
# CACHE_HASH_QUERY_IGNORE=utm,live
1111
CACHE_STRATEGY=LFU
1212
CACHE_SIZE_MB=10
1313
CACHE_STALE_WHILE_REVALIDATE_SEC=60
14-
CACHE_IGNORE_ENDPOINTS=/status,/health
14+
# CACHE_IGNORE_ENDPOINTS=/status,/health
1515

1616
# if SERVER_STORAGE=redis
1717
REDIS_CONNECTION_STRING=redis://:development@localhost:6379/0

pkg/http/server.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ func RunServer(opts ServerOpts) {
2626
mux.Handle("/", newCacheHandler(opts.Cacher, opts.MetricsCollector, opts.Worker, opts.Config.CacheConfig))
2727
mux.Handle("/metrics/prometheus", metricsHandler())
2828
mux.HandleFunc("/probes/liveness", livenessHandler)
29+
mux.HandleFunc("/probes/readiness", readinessHandler(opts.ReadinessChecker))
2930

3031
for _, path := range opts.Config.CacheConfig.IgnorePaths {
32+
if path == "/metrics/prometheus" || path == "/probes/liveness" || path == "/probes/readiness" {
33+
continue
34+
}
3135
mux.HandleFunc(path, forwardHandler(opts.Config.CacheConfig.DownstreamHost))
3236
}
3337

34-
mux.HandleFunc("/probes/readiness", readinessHandler(opts.ReadinessChecker))
35-
3638
server := &h.Server{
3739
Addr: fmt.Sprintf("0.0.0.0:%s", opts.Config.ServerConfig.Port),
3840
Handler: mux,

0 commit comments

Comments
 (0)