From baa19a89a4ac75325fd64c15ec1a077ee71b0055 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Thu, 2 Nov 2023 03:16:18 +0100 Subject: [PATCH] build docker image --- Dockerfile | 19 ----------- Dockerfile.alpine | 37 --------------------- Dockerfile.test | 46 -------------------------- README.md | 11 ++++--- cmd/main.go | 78 ++++++++++++--------------------------------- docker-compose.yaml | 7 ++-- handlers/form.go | 2 +- 7 files changed, 30 insertions(+), 170 deletions(-) delete mode 100644 Dockerfile.alpine delete mode 100644 Dockerfile.test diff --git a/Dockerfile b/Dockerfile index 5e32c6a..8bd6af9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,40 +3,21 @@ FROM golang:1.21 AS build WORKDIR /go/src/ladder -# Copy all the Code and stuff to compile everything COPY . . -# Downloads all the dependencies in advance (could be left out, but it's more clear this way) RUN go mod download -# Builds the application as a staticly linked one, to allow it to run on alpine -#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o ladder cmd/main.go -#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags netgo -a -installsuffix cgo -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags netgo -a -o ladder cmd/main.go RUN CGO_ENABLED=0 GOOS=linux go build -o ladder cmd/main.go - -# Moving the binary to the 'final Image' to make it smaller FROM debian:12-slim as release -#FROM debian:latest as release -#FROM ubuntu:latest as release -#FROM golang:bookworm as release WORKDIR /app -# Create the `public` dir and copy all the assets into it -RUN mkdir ./public -COPY ./public ./public - COPY --from=build /go/src/ladder/ladder . RUN chmod +x /app/ladder RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* -# Exposes port 2000 and 3000 because our program listens on that port #EXPOSE 2000 -#EXPOSE 3000 #ENTRYPOINT ["/usr/bin/dumb-init", "--"] \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine deleted file mode 100644 index f2faf91..0000000 --- a/Dockerfile.alpine +++ /dev/null @@ -1,37 +0,0 @@ -# Building the binary of the App -FROM golang:1.21 AS build - -WORKDIR /go/src/ladder - -# Copy all the Code and stuff to compile everything -COPY . . - -# Downloads all the dependencies in advance (could be left out, but it's more clear this way) -RUN go mod download - -# Builds the application as a staticly linked one, to allow it to run on alpine -#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o ladder cmd/main.go -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -a -installsuffix cgo -o ladder cmd/main.go - - -# Moving the binary to the 'final Image' to make it smaller -FROM alpine:latest as release - -WORKDIR /app - -# Create the `public` dir and copy all the assets into it -RUN mkdir ./public -COPY ./public ./public - -COPY --from=build /go/src/ladder/ladder . - -# Add packages -RUN apk -U upgrade \ - && apk add --no-cache dumb-init ca-certificates \ - && chmod +x /app/ladder - -# Exposes port 2000 and 3000 because our program listens on that port -#EXPOSE 2000 -#EXPOSE 3000 - -#ENTRYPOINT ["/usr/bin/dumb-init", "--"] \ No newline at end of file diff --git a/Dockerfile.test b/Dockerfile.test deleted file mode 100644 index ddfd7d8..0000000 --- a/Dockerfile.test +++ /dev/null @@ -1,46 +0,0 @@ -# Building the binary of the App -FROM golang:bookworm AS build - -WORKDIR /go/src/ladder - -# Copy all the Code and stuff to compile everything -COPY . . - -# Downloads all the dependencies in advance (could be left out, but it's more clear this way) -RUN go mod download - -# Builds the application as a staticly linked one, to allow it to run on alpine -#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o ladder cmd/main.go -#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags netgo -a -installsuffix cgo -o ladder cmd/main.go -#RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags netgo -a -o ladder cmd/main.go -RUN CGO_ENABLED=0 GOOS=linux go build -o ladder cmd/main.go - - -# Moving the binary to the 'final Image' to make it smaller -FROM debian:12-slim as release -#FROM debian:latest as release -#FROM ubuntu:latest as release -#FROM golang:bookworm as release - -WORKDIR /app - -RUN apt update && apt install -y ca-certificates - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o ladder cmd/main.go - -# Create the `public` dir and copy all the assets into it -RUN mkdir ./public -COPY ./public ./public - -COPY --from=build /go/src/ladder/ladder . -RUN chmod +x /app/ladder - -RUN rm -rf /var/lib/apt/lists/* - -# Exposes port 2000 and 3000 because our program listens on that port -#EXPOSE 2000 -#EXPOSE 3000 - -#ENTRYPOINT ["/usr/bin/dumb-init", "--"] \ No newline at end of file diff --git a/README.md b/README.md index 2607563..5712f5e 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,23 @@ Freedom of information is an essential pillar of democracy and informed decision-making. While media organizations have legitimate financial interests, it is crucial to strike a balance between profitability and the public's right to access information. The proliferation of paywalls raises concerns about the erosion of this fundamental freedom, and it is imperative for society to find innovative ways to preserve access to vital information without compromising the sustainability of journalism. In a world where knowledge should be shared and not commodified, paywalls should be critically examined to ensure that they do not undermine the principles of an open and informed society. +Some site might have missing images. This is due to the fact that the site using javascript or CSS to load the images. This is a limitation of this proxy. If you prefer a full experience, please concider buying a subscription for the site. ### Features - [x] Bypass Paywalls - [x] Remove CORS -- [ ] Docker Container +- [x] Keep Site browsable +- [x] Docker Container - [x] Linux Binary - [x] Mac OS Binary -- [ ] Windows Binary +- [x] Windows Binary (Untested) ## How to use 1) Download Binary 2) Run Binary -3) Open Browser (Default: https://localhost:2000) +3) Open Browser (Default: http://localhost:2000) 4) Enter URL 5) Hit Enter @@ -35,5 +37,4 @@ Freedom of information is an essential pillar of democracy and informed decision | Variable | Description | Default | | --- | --- | --- | | `PORT` | Port to listen on | `2000` | -| `PORT_PROXY` | Port the proxy listens on | `3000` | -| `HTTP_PROXY` | Proxy to use | `http://127.0.0.1:3000` | +| `PREFORK` | Spawn multiple server instances | `false` | diff --git a/cmd/main.go b/cmd/main.go index 15a15de..34df46b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,73 +1,35 @@ package main import ( - "fmt" "log" - "net/http" "os" "paywall-ladder/handlers" - "runtime" - "syscall" + "strconv" - "github.com/elazarl/goproxy" "github.com/gofiber/fiber/v2" ) func main() { - if os.Getenv("PORT_PROXY") == "" { - os.Setenv("PORT_PROXY", "3000") - } - if os.Getenv("HTTP_PROXY") == "" { - os.Setenv("HTTP_PROXY", "http://127.0.0.1:"+os.Getenv("PORT_PROXY")) - } - - proxyForkID := uintptr(0) - if runtime.GOOS == "darwin" { - _, proxyForkID, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0) - } else if runtime.GOOS == "linux" { - proxyForkID, _, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0) - } - - fmt.Println("Proxy fork id", proxyForkID) - - if proxyForkID == 0 { - - app := fiber.New( - fiber.Config{ - Prefork: false, - }, - ) - - //app.Static("/", "./public") - app.Get("/", handlers.Form) - - app.Get("/proxy/*", handlers.FetchSite) - app.Get("debug/*", handlers.Debug) - app.Get("debug2/*", handlers.Debug2) - app.Get("/*", handlers.ProxySite) - - port := os.Getenv("PORT") - if os.Getenv("PORT") == "" { - port = "2000" - } - app.Listen(":" + port) - } else { - proxy := goproxy.NewProxyHttpServer() - proxy.Verbose = true - proxy.OnRequest().DoFunc( - func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { - req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)") - req.Header.Set("X-Forwarded-For", "66.249.66.1") - return req, nil - }) - - proxyport := os.Getenv("PORT_PROXY") - if os.Getenv("PORT_PROXY") == "" { - proxyport = "3000" - } - log.Println("Proxy listening on port " + proxyport) - log.Fatal(http.ListenAndServe(":"+proxyport, proxy)) + prefork, _ := strconv.ParseBool(os.Getenv("PREFORK")) + app := fiber.New( + fiber.Config{ + Prefork: prefork, + }, + ) + + //app.Static("/", "./public") + app.Get("/", handlers.Form) + + app.Get("/proxy/*", handlers.FetchSite) + app.Get("debug/*", handlers.Debug) + app.Get("debug2/*", handlers.Debug2) + app.Get("/*", handlers.ProxySite) + + port := os.Getenv("PORT") + if os.Getenv("PORT") == "" { + port = "2000" } + log.Fatal(app.Listen(":" + port)) } diff --git a/docker-compose.yaml b/docker-compose.yaml index 6f88883..6d7c540 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,14 +5,13 @@ services: container_name: ladder #restart: always #command: tail -f /dev/null - command: ./ladder + command: sh -c ./ladder environment: - PORT=2000 - - PORT_PROXY=3000 - - GODEBUG=netdns=go+4 + - PREFORK=true + #- GODEBUG=netdns=go+4 ports: - "2000:2000" - - "8080:3000" deploy: resources: limits: diff --git a/handlers/form.go b/handlers/form.go index d0fa8b5..3b13019 100644 --- a/handlers/form.go +++ b/handlers/form.go @@ -53,7 +53,7 @@ const html = `
-
+