wireadmin/Dockerfile

94 lines
2.5 KiB
Docker
Raw Normal View History

2024-02-15 08:16:16 +00:00
ARG ALPINE_VERSION=3.19
FROM --platform=$BUILDPLATFORM chriswayg/tor-alpine:latest as tor
FROM --platform=$BUILDPLATFORM node:alpine${ALPINE_VERSION} as base
2023-11-02 13:02:33 +00:00
LABEL Maintainer="Shahrad Elahi <https://github.com/shahradelahi>"
WORKDIR /app
2023-09-24 19:18:39 +00:00
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2024-02-15 08:16:16 +00:00
COPY --from=tor /usr/local/bin/obfs4proxy /usr/local/bin/obfs4proxy
COPY --from=tor /usr/local/bin/meek-server /usr/local/bin/meek-server
2023-09-27 07:01:52 +00:00
2023-11-02 13:02:33 +00:00
# Update and upgrade packages
2024-02-12 06:55:37 +00:00
RUN apk update && apk upgrade &&\
2023-12-10 23:20:54 +00:00
# Install required packages
2024-02-12 06:55:37 +00:00
apk add -U --no-cache \
2023-12-10 23:20:54 +00:00
iproute2 iptables net-tools \
2023-12-19 05:00:54 +00:00
screen curl bash \
2023-12-10 23:20:54 +00:00
wireguard-tools \
tor &&\
# NPM packages
npm install -g @litehex/node-checksum &&\
2023-12-10 23:20:54 +00:00
# Clear APK cache
rm -rf /var/cache/apk/*
COPY /config/torrc.template /etc/tor/torrc.template
2023-12-19 09:51:23 +00:00
2024-02-12 06:55:37 +00:00
# Copy user scripts
2024-01-08 10:23:35 +00:00
COPY /bin /usr/local/bin
RUN chmod -R +x /usr/local/bin
2023-12-19 09:51:23 +00:00
2023-12-19 11:25:45 +00:00
COPY web/package.json web/pnpm-lock.yaml ./
2023-09-24 19:18:39 +00:00
2024-02-12 06:55:37 +00:00
# Base env
ENV PROTOCOL_HEADER=x-forwarded-proto
ENV HOST_HEADER=x-forwarded-host
2024-01-08 08:59:54 +00:00
2023-12-19 11:25:45 +00:00
FROM base AS build
2023-09-24 19:18:39 +00:00
2024-02-12 06:55:37 +00:00
# Setup Pnpm - Pnpm only used for build stage
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
2023-11-02 13:02:33 +00:00
COPY web .
2023-09-24 19:18:39 +00:00
2023-12-19 11:25:45 +00:00
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile \
# build
&& NODE_ENV=production pnpm run build \
# Omit devDependencies
&& pnpm prune --prod \
# Move the goods to a temporary location
&& mv node_modules /tmp/node_modules \
&& mv build /tmp/build \
# Remove everything else
&& rm -rf ./*
2023-09-24 19:18:39 +00:00
2023-11-02 13:02:33 +00:00
FROM base AS release
2023-09-24 19:18:39 +00:00
2024-02-12 06:55:37 +00:00
# Copy the goods from the build stage
2023-12-19 11:25:45 +00:00
COPY --from=build /tmp/node_modules node_modules
COPY --from=build /tmp/build build
2023-09-24 19:18:39 +00:00
2024-02-15 08:16:16 +00:00
# Fix permissions
RUN mkdir -p /data && chmod 700 /data
RUN mkdir -p /etc/torrc.d && chmod -R 400 /etc/torrc.d
RUN mkdir -p /var/vlogs && touch /var/vlogs/web && chmod -R 600 /var/vlogs
2023-11-02 13:02:33 +00:00
ENV NODE_ENV=production
2023-12-19 09:51:23 +00:00
ENV LOG_LEVEL=error
2023-09-24 19:18:39 +00:00
2024-02-12 06:55:37 +00:00
# Setup entrypoint
2023-12-10 23:20:54 +00:00
COPY docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
2024-02-12 06:55:37 +00:00
# Healthcheck
HEALTHCHECK --interval=60s --timeout=3s --start-period=20s --retries=3 \
CMD curl -f http://127.0.0.1:3000/api/health || exit 1
2024-02-12 06:55:37 +00:00
# Volumes
2023-12-19 05:00:54 +00:00
VOLUME ["/etc/torrc.d", "/data", "/var/vlogs"]
2023-12-10 23:20:54 +00:00
# Overwrite package version
ARG VERSION=0.0.0-canary
RUN node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('/app/package.json')); pkg.version = process.env.VERSION; fs.writeFileSync('/app/package.json', JSON.stringify(pkg, null, 2));"
2024-02-12 06:55:37 +00:00
# Run the app
2023-09-24 19:18:39 +00:00
EXPOSE 3000/tcp
2023-11-07 20:12:06 +00:00
CMD [ "npm", "run", "start" ]