-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (47 loc) · 1.68 KB
/
Dockerfile
File metadata and controls
64 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Stage 1: Build the Fastify and Express apps
FROM node:20.7 as build
WORKDIR /app
# Create the directory for the benchmark results
RUN mkdir -p /results
COPY package.json ./
RUN npm install
# Copy source code
COPY src/ ./src/
# Stage 2: Use a lighter base image and only copy essential files
FROM ubuntu:latest
# Avoid tzdata asking for geographical area
ENV DEBIAN_FRONTEND=noninteractive
# Install Apache Bench, Node.js, and PostgreSQL
RUN apt-get update \
&& apt-get install -y --no-install-recommends apache2-utils postgresql postgresql-contrib \
&& rm -rf /var/lib/apt/lists/*
# Install curl
RUN apt-get update && apt-get install -y curl
# Install curl and xz-utils
RUN apt-get update && apt-get install -y curl xz-utils
# Download Node.js binary and install
RUN curl -fsSLO --compressed "https://nodejs.org/dist/v20.7.0/node-v20.7.0-linux-x64.tar.xz" \
&& tar -xJf "node-v20.7.0-linux-x64.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v20.7.0-linux-x64.tar.xz" \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
# Initialize PostgreSQL
USER postgres
COPY init.sql /init.sql
RUN /etc/init.d/postgresql start && \
psql --command "CREATE USER myuser WITH SUPERUSER PASSWORD 'mypassword';" && \
createdb -O myuser mydatabase && \
psql mydatabase < /init.sql
# Switch back to root user
USER root
# Set working directory
WORKDIR /app
# Copy essential files from the build stage
COPY --from=build /app .
# Add benchmark.sh and make it executable
COPY benchmark.sh .
RUN chmod +x benchmark.sh
# Add startup script
COPY start.sh .
RUN chmod +x start.sh
# Run PostgreSQL, Fastify and Express and then execute the benchmark
CMD ["./start.sh"]