File size: 3,385 Bytes
eda0bfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251af83
eda0bfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e404eb5
eda0bfa
 
e404eb5
59da6a4
251af83
 
 
eda0bfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f273c1d
1bf2147
4532503
 
 
 
eda0bfa
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# /!\ NOTICE /!\

# Many of the developers DO NOT USE the Dockerfile or image.
# While we do test new changes to Docker configuration, it's
# possible that future changes to the repo might break it.
# When changing this file, please try to make it as resiliant
# to such changes as possible; developers shouldn't need to
# worry about Docker unless the build/run process changes.

# Build stage
FROM node:24-alpine AS build

# Install build dependencies
RUN apk add --no-cache git python3 make g++ \
    && ln -sf /usr/bin/python3 /usr/bin/python

# Set up working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Fail early if lockfile or manifest is missing
RUN test -f package.json && test -f package-lock.json

# Copy the source files
COPY . .

# Install mocha
RUN npm i -g npm@latest
RUN npm install -g mocha

# Install node modules
RUN npm cache clean --force && \
    for i in 1 2 3; do \
        npm ci && break || \
        if [ $i -lt 3 ]; then \
            sleep 15; \
        else \
            LOG_DIR="$(npm config get cache | tr -d '\"')/_logs"; \
            echo "npm install failed; dumping logs from $LOG_DIR"; \
            if [ -d "$LOG_DIR" ]; then \
                ls -al "$LOG_DIR" || true; \
                cat "$LOG_DIR"/* || true; \
            else \
                echo "Log directory not found (npm cache: $(npm config get cache))"; \
            fi; \
            exit 1; \
        fi; \
    done

# Run the build command if necessary
RUN cd src/gui && npm run build && cd - && cd src/puter-js && npm install && npm run build

# Production stage
FROM node:24-alpine

# Set labels
LABEL repo="https://github.com/HeyPuter/puter"
LABEL license="AGPL-3.0,https://github.com/HeyPuter/puter/blob/master/LICENSE.txt"
LABEL version="1.2.46-beta-1"

# Install git (required by Puter to check version)
RUN apk add --no-cache git

# Set up working directory
RUN mkdir -p /opt/puter/app
WORKDIR /opt/puter/app

# Copy built artifacts and necessary files from the build stage
# Original dist copy removed
COPY --from=build /app/node_modules ./node_modules
COPY . .
# Copy GUI assets to the correct location AFTER source copy to prevent overwrite
COPY --from=build /app/src/gui/dist ./src/gui/dist
# Infrastructure for local SDK
RUN mkdir -p ./src/backend/puter.js
COPY --from=build /app/src/puter-js/dist/puter.js ./src/backend/puter.js/v2.js

# Set permissions
RUN chown -R node:node /opt/puter/app
USER node

EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=3s \
    CMD wget --no-verbose --tries=1 --spider http://localhost:7860/test || exit 1

ENV NO_VAR_RUNTUME=1

# Attempt to fix `lru-cache@11.0.2` missing after build stage
# by doing a redundant `npm install` at this stage
RUN npm install

ENV PORT=7860

RUN mkdir -p volatile/config && echo '{"config_name": "hf-space", "allow_all_host_values": true, "http_port": 7860, "services": {"database": {"engine": "sqlite", "path": "puter-database.sqlite"}, "thumbnails": {"engine": "purejs"}, "file-cache": {"disk_limit": 16384, "disk_max_size": 16384, "precache_size": 16384, "path": "./file-cache"}}}' > volatile/config/config.json
ENV PORT=7860

RUN mkdir -p volatile/config
COPY hf_config.json volatile/config/config.json
CMD ["npm", "start"]