Skip to content

Commit b8d84fb

Browse files
fix docker builds
1 parent b164113 commit b8d84fb

File tree

2 files changed

+69
-57
lines changed

2 files changed

+69
-57
lines changed

.dockerignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dependency directories
2+
# We want the container to run its own 'npm install'
3+
node_modules/
4+
npm-debug.log
5+
yarn-error.log
6+
7+
# Git metadata
8+
.git
9+
.gitignore
10+
11+
# Local build artifacts and caches
12+
dist/
13+
build/
14+
.cache/
15+
.npm/
16+
17+
# OS-specific files
18+
.DS_Store
19+
Thumbs.db
20+
21+
# Docker-related files
22+
Dockerfile
23+
.dockerignore
24+
docker-compose.yml
25+
26+
# Large data or temp files
27+
*.tar
28+
*.zip
29+
*.log
30+
tmp/

Dockerfile

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,57 @@
1-
FROM node:18-bookworm
1+
# --- STAGE 1: The Builder ---
2+
FROM node:18-bookworm AS builder
23

34
ARG NODE_SNAP=false
5+
WORKDIR /usr/src/app/FUXA
46

5-
RUN apt-get update && apt-get install -y dos2unix
7+
# Install ONLY what is needed to compile
8+
RUN apt-get update && apt-get install -y \
9+
dos2unix build-essential unixodbc-dev sqlite3 libsqlite3-dev \
10+
&& rm -rf /var/lib/apt/lists/*
611

7-
# Change working directory
8-
WORKDIR /usr/src/app
9-
10-
# Clone FUXA repository
11-
RUN git clone https://github.com/frangoteam/FUXA.git
12-
13-
# Install build dependencies for node-odbc
14-
RUN apt-get update && apt-get install -y build-essential unixodbc unixodbc-dev
15-
16-
# Convert the script to Unix format and make it executable
17-
RUN dos2unix FUXA/odbc/install_odbc_drivers.sh && chmod +x FUXA/odbc/install_odbc_drivers.sh
18-
19-
WORKDIR /usr/src/app/FUXA/odbc
20-
RUN ./install_odbc_drivers.sh
12+
# Copy only dependency files first to leverage caching
13+
COPY server/package*.json ./server/
14+
WORKDIR /usr/src/app/FUXA/server
2115

22-
# Change working directory
23-
WORKDIR /usr/src/app
16+
# Optimized NPM for speed
17+
RUN npm config set audit false && npm config set fund false
18+
RUN npm install --no-audit --no-fund --network-timeout=600000
2419

25-
# Copy odbcinst.ini to /etc
26-
RUN cp FUXA/odbc/odbcinst.ini /etc/odbcinst.ini
20+
# Install snap7 if requested
21+
RUN if [ "$NODE_SNAP" = "true" ]; then npm install node-snap7; fi
2722

28-
# Install Fuxa server
29-
WORKDIR /usr/src/app/FUXA/server
23+
# Rebuild sqlite3 for the container architecture
24+
RUN npm install --build-from-source --sqlite=/usr/bin sqlite3
3025

31-
# More tolerant npm config
32-
ENV NODE_OPTIONS=--dns-result-order=ipv4first
33-
RUN npm config set registry https://registry.npmjs.org/ \
34-
&& npm config set fetch-retries 8 \
35-
&& npm config set fetch-retry-factor 2 \
36-
&& npm config set fetch-retry-mintimeout 30000 \
37-
&& npm config set fetch-retry-maxtimeout 300000 \
38-
&& npm config set audit false \
39-
&& npm config set fund false
26+
# Now copy the rest of the source code
27+
WORKDIR /usr/src/app/FUXA
28+
COPY . .
4029

41-
# Retry loop con backoff + timeout alto
42-
RUN bash -lc '\
43-
for i in 1 2 3 4 5 6 7 8; do \
44-
echo "npm install - attempt $i/8"; \
45-
npm install --no-audit --no-fund --prefer-offline --network-timeout=600000 && exit 0; \
46-
echo "Failed, wait $((10*i))s and try again..."; \
47-
sleep $((10*i)); \
48-
done; \
49-
echo "npm install failed after 8 attempts"; \
50-
exit 1'
30+
# Run the driver scripts (only needed for the setup files they generate)
31+
RUN dos2unix odbc/install_odbc_drivers.sh && \
32+
chmod +x odbc/install_odbc_drivers.sh
5133

34+
# --- STAGE 2: The Runner (Final Image) ---
35+
FROM node:18-bookworm-slim
5236

53-
# Install options snap7
54-
RUN if [ "$NODE_SNAP" = "true" ]; then \
55-
npm install node-snap7; \
56-
fi
37+
WORKDIR /usr/src/app/FUXA
5738

58-
# Workaround for sqlite3 https://stackoverflow.com/questions/71894884/sqlite3-err-dlopen-failed-version-glibc-2-29-not-found
59-
RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev && \
60-
apt-get autoremove -yqq --purge && \
61-
apt-get clean && \
62-
rm -rf /var/lib/apt/lists/* && \
63-
npm install --build-from-source --sqlite=/usr/bin sqlite3
39+
# Install ONLY the runtime libraries (no compilers/build-essential)
40+
RUN apt-get update && apt-get install -y \
41+
unixodbc sqlite3 libsqlite3-dev \
42+
&& rm -rf /var/lib/apt/lists/*
6443

65-
# Add project files
66-
ADD . /usr/src/app/FUXA
44+
# Copy ONLY the necessary artifacts from the builder
45+
COPY --from=builder /usr/src/app/FUXA/server ./server
46+
COPY --from=builder /usr/src/app/FUXA/app ./app
47+
COPY --from=builder /usr/src/app/FUXA/client ./client
48+
COPY --from=builder /usr/src/app/FUXA/node-red ./node-red
49+
COPY --from=builder /usr/src/app/FUXA/odbc ./odbc
50+
COPY --from=builder /usr/src/app/FUXA/odbc/odbcinst.ini /etc/odbcinst.ini
6751

68-
# Set working directory
52+
# Set environment and expose
6953
WORKDIR /usr/src/app/FUXA/server
70-
71-
# Expose port
54+
ENV NODE_ENV=production
7255
EXPOSE 1881
7356

74-
# Start the server
7557
CMD [ "npm", "start" ]

0 commit comments

Comments
 (0)