-
Notifications
You must be signed in to change notification settings - Fork 83
/
Dockerfile
90 lines (65 loc) · 3.33 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
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
FROM node:20.13-alpine AS base
WORKDIR /app
COPY package.json .
RUN apk add --no-cache jq yq && \
yarn global add "turbo@$(jq -r '.devDependencies.turbo' < package.json)"
COPY . .
# `turbo prune` does not include Cargo workspaces, so we create dummy projects for each workspace member
RUN turbo prune --scope='@apps/hash-ai-worker-ts' --docker && \
find $(yq '.workspace.members' -p toml -o tsv Cargo.toml | tr '*' ' ') -maxdepth 2 -name Cargo.toml -exec sh -c ' \
[ -f "/app/out/full/$1" ] || ( \
mkdir -p "/app/out/full/$(dirname "$1")/src" && \
echo > "/app/out/full/$(dirname "$1")/src/lib.rs" && \
echo -e "[package]\nname = \"$(yq ".package.name" -p toml -oy $1)\"" > "/app/out/full/$1" \
)' _ {} \; && \
cp -R .cargo Cargo.toml Cargo.lock /app/out/full/
# Turbo isn't aware of our patches by default (it would be if we use Yarn 2+ or pnpm).
# Therefore we manually add the patches to the pruned output to allow for the patches to be applied.
COPY patches /app/out/full/patches
FROM node:20.13-slim AS rust
WORKDIR /usr/local/
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=:$PATH:/usr/local/cargo/bin
COPY rust-toolchain.toml .
RUN apt-get update && \
apt-get install -y --no-install-recommends default-jre-headless wget g++ libc-dev && \
rm -rf /var/lib/apt/lists/* && \
wget -q -O- https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile minimal && \
rustup show && \
cargo install wasm-opt --debug
FROM rust AS installer
WORKDIR /usr/local/src/
COPY --from=base /app/out/json/ .
COPY --from=base /app/out/yarn.lock ./yarn.lock
COPY --from=base /app/out/full/patches patches
COPY --from=base /app/out/full/turbo.json turbo.json
RUN yarn install --frozen-lockfile --prefer-offline && \
yarn cache clean
COPY --from=base /app/out/full/ .
RUN yarn turbo build --filter '@apps/hash-ai-worker-ts' --env-mode=loose && rm -rf target/
FROM node:20.13-slim AS runner
COPY --from=installer /usr/local/src /usr/local/src
WORKDIR /usr/local/src/apps/hash-ai-worker-ts
ENTRYPOINT [ "yarn", "--cache-folder", "/tmp/yarn-cache", "--global-folder", "/tmp/yarn-global" ]
CMD ["start"]
ARG GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON
ENV GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON=${GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON}
RUN if [ -n "$GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON" ]; then \
echo $GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON > /tmp/google_workload_identity_federation_config.json && \
export GOOGLE_APPLICATION_CREDENTIALS=/tmp/google_workload_identity_federation_config.json && \
echo "GOOGLE_APPLICATION_CREDENTIALS set from JSON"; \
else \
echo "GOOGLE_APPLICATION_CREDENTIALS not set, no GOOGLE_CLOUD_WORKLOAD_IDENTITY_FEDERATION_CONFIG_JSON in environment"; \
fi
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/* && \
groupadd --system --gid 60000 hash && \
useradd --system tsworker -G hash && \
install -d -m 0775 -o tsworker -g hash /log
RUN mkdir -p officeParserTemp/tempfiles && \
chown -R tsworker:hash officeParserTemp
USER tsworker:hash
ENV NODE_ENV=production
HEALTHCHECK --interval=5s --timeout=3s --start-period=10s --retries=3 CMD curl -f http://localhost:4100/health || exit 1