improve docker image

This commit is contained in:
wait-what 2024-04-23 00:37:39 +03:00
parent f986884f85
commit 8d8b098d86
3 changed files with 50 additions and 126 deletions

View file

@ -1,99 +1,21 @@
#################################################################################
# INSTALLERS #
# These images provide the dependencies required to build the other images. #
#################################################################################
# docker build -t pproxy .
# docker run -p 6003:6003 -v ./whitelist.json:/pproxy/whitelist.json:ro pproxy
FROM quay.io/almalinuxorg/9-base AS builder-installer
# Base
FROM node:18-alpine
# Needed for node 18+
# RUN dnf module --assumeyes enable nodejs
# Install dependencies
RUN apk add --no-cache git build-base python3
RUN --mount=type=cache,target=/var/cache/dnf \
dnf install --assumeyes --nodocs nodejs ca-certificates jq make gcc g++
# Set Work Directory
WORKDIR /pproxy
RUN npm install -g \
npm@$(curl "https://release-monitoring.org/api/v2/versions/?project_id=190206" | jq --raw-output '.stable_versions[0]')
# Install dependencies
# Honestly less effort this way
RUN yarn add express undici
# Copy files
COPY server.js .
# Runtime dependencies
FROM quay.io/almalinuxorg/9-base AS installer
COPY --from=quay.io/almalinuxorg/9-micro / /rpms
RUN --mount=type=cache,target=/var/cache/dnf \
dnf install --assumeyes \
--installroot /rpms \
--releasever=9 \
--setopt=install_weak_deps=false \
--nodocs \
nodejs ca-certificates
RUN dnf clean all \
--installroot /rpms
# Proxy + certbot
FROM quay.io/almalinuxorg/9-base AS proxy-installer
RUN dnf install epel-release --assumeyes
COPY --from=quay.io/almalinuxorg/9-micro / /rpms
RUN --mount=type=cache,target=/var/cache/dnf \
dnf install --assumeyes \
--installroot /rpms \
--releasever=9 \
--setopt=install_weak_deps=false \
--setopt=reposdir=/etc/yum.repos.d \
--nodocs \
nginx-core certbot python3-certbot-nginx
RUN dnf clean all \
--installroot /rpms
#################################################################################
# BUILDER #
#################################################################################
FROM builder-installer AS builder
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install --frozen-lockfile
# COPY ./ ./
COPY p/server.js ./
#################################################################################
# FINAL IMAGE #
#################################################################################
FROM quay.io/almalinuxorg/9-micro AS release-base
# Grab npm
COPY --from=installer /rpms /
# Grab site
COPY --from=builder /usr/src/app /app
WORKDIR /app
ENV NODE_ENV production
# Final image
FROM release-base as release
# EXPOSE 3000/tcp
CMD [ "node", "server.js" ]
# Final image with extras
FROM release-base AS release-aio
# Grab nginx and certbot
COPY --from=proxy-installer /rpms /
COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh
COPY nginx.conf.example /etc/nginx/conf.d/poketube.conf
# EXPOSE 80/tcp
# EXPOSE 443/tcp
ENTRYPOINT [ "/usr/bin/bash", "./entrypoint.sh" ]
# Entrypoint
CMD [ "node", "server.js" ]

View file

@ -1,41 +1,10 @@
const express = require("express");
const fetch = require("node-fetch");
// const fetch = require("node-fetch");
const { URL } = require("url");
const { Readable } = require("node:stream");
// Array of hostnames that will be proxied
const URL_WHITELIST = [
"i.ytimg.com",
"yt3.googleusercontent.com",
"cdn.glitch.global",
"cdn.statically.io",
"site-assets.fontawesome.com",
"fonts.gstatic.com",
"cdn.jsdelivr.net",
"yt3.ggpht.com",
"tube.kuylar.dev",
"lh3.googleusercontent.com",
"is4-ssl.mzstatic.com",
"is2-ssl.mzstatic.com",
"is1-ssl.mzstatic.com",
"fonts.bunny.net",
"demo.matomo.org",
"is5-ssl.mzstatic.com",
"is3-ssl.mzstatic.com",
"twemoji.maxcdn.com",
"unpkg.com",
"lite.duckduckgo.com",
"youtube.com",
"returnyoutubedislikeapi.com",
"cdn.zptr.cc",
"inv.vern.cc",
"invidious.privacydev.net",
"inv.zzls.xyz",
"vid.puffyan.us",
"invidious.lidarshield.cloud",
"invidious.epicsite.xyz",
"invidious.esmailelbob.xyz",
];
const URL_WHITELIST = require("./whitelist.json");
const app = express();
@ -162,6 +131,7 @@ const { fetch } = await import("undici")
});
app.get("/bangs", async (req, res) => {
const { fetch } = await import("undici")
let f = await fetch("https://lite.duckduckgo.com/lite/?q=" + req.query.q, {
method: req.method,

32
p/whitelist.json Normal file
View file

@ -0,0 +1,32 @@
[
"i.ytimg.com",
"yt3.googleusercontent.com",
"cdn.glitch.global",
"cdn.statically.io",
"site-assets.fontawesome.com",
"fonts.gstatic.com",
"cdn.jsdelivr.net",
"yt3.ggpht.com",
"tube.kuylar.dev",
"lh3.googleusercontent.com",
"is4-ssl.mzstatic.com",
"is2-ssl.mzstatic.com",
"is1-ssl.mzstatic.com",
"fonts.bunny.net",
"demo.matomo.org",
"is5-ssl.mzstatic.com",
"is3-ssl.mzstatic.com",
"twemoji.maxcdn.com",
"unpkg.com",
"lite.duckduckgo.com",
"youtube.com",
"returnyoutubedislikeapi.com",
"cdn.zptr.cc",
"inv.vern.cc",
"invidious.privacydev.net",
"inv.zzls.xyz",
"vid.puffyan.us",
"invidious.lidarshield.cloud",
"invidious.epicsite.xyz",
"invidious.esmailelbob.xyz"
]