-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
58 lines (41 loc) · 1.45 KB
/
Dockerfile
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
# Multistage Docker build
# Define build directory as an absolute path
ARG build_dir=/build_application
# First stage: Builds the application
FROM node:20.18.0 as builder
ARG build_dir
ENV DEPLOYMENT_URL="http://localhost:8080"
# Set up the build directory
WORKDIR $build_dir
# Copy all project files into the build directory
COPY . .
# Install dependencies and build the application
RUN npm install
RUN npm run build
# Second stage: Sets up the container to run the application
FROM node:20.18.0
# Install cron for scheduling
RUN apt-get update && apt-get -y install cron
# Expose the application's default port
EXPOSE 8080
# Create a user and set up necessary directories and permissions
RUN useradd -r -s /bin/false apollon_standalone \
&& mkdir /opt/apollon_standalone \
&& touch /var/log/cron.log \
&& chmod 622 /var/log/cron.log
# Start cron service
RUN service cron start
RUN chown -R apollon_standalone /opt/apollon_standalone
# Switch to non-root user for security
USER apollon_standalone
WORKDIR /opt/apollon_standalone
# Create a directory for storing diagrams
RUN mkdir diagrams
# Copy build results from the first stage
COPY --chown=apollon_standalone:apollon_standalone --from=builder $build_dir .
# Add cron job for deleting stale diagrams
RUN crontab delete-stale-diagrams.cronjob.txt
# Set the working directory for the server
WORKDIR /opt/apollon_standalone/build/server
# Start the application
CMD [ "node", "./src/main/server.js" ]