build docker image

This commit is contained in:
Gianni Carafa
2023-11-02 03:16:18 +01:00
parent 59041549db
commit baa19a89a4
7 changed files with 30 additions and 170 deletions

View File

@@ -3,40 +3,21 @@ FROM golang:1.21 AS build
WORKDIR /go/src/ladder WORKDIR /go/src/ladder
# Copy all the Code and stuff to compile everything
COPY . . COPY . .
# Downloads all the dependencies in advance (could be left out, but it's more clear this way)
RUN go mod download 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 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:12-slim as release
#FROM debian:latest as release
#FROM ubuntu:latest as release
#FROM golang:bookworm as release
WORKDIR /app 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 . COPY --from=build /go/src/ladder/ladder .
RUN chmod +x /app/ladder RUN chmod +x /app/ladder
RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/* 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 2000
#EXPOSE 3000
#ENTRYPOINT ["/usr/bin/dumb-init", "--"] #ENTRYPOINT ["/usr/bin/dumb-init", "--"]

View File

@@ -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", "--"]

View File

@@ -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", "--"]

View File

@@ -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. 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 ### Features
- [x] Bypass Paywalls - [x] Bypass Paywalls
- [x] Remove CORS - [x] Remove CORS
- [ ] Docker Container - [x] Keep Site browsable
- [x] Docker Container
- [x] Linux Binary - [x] Linux Binary
- [x] Mac OS Binary - [x] Mac OS Binary
- [ ] Windows Binary - [x] Windows Binary (Untested)
## How to use ## How to use
1) Download Binary 1) Download Binary
2) Run Binary 2) Run Binary
3) Open Browser (Default: https://localhost:2000) 3) Open Browser (Default: http://localhost:2000)
4) Enter URL 4) Enter URL
5) Hit Enter 5) Hit Enter
@@ -35,5 +37,4 @@ Freedom of information is an essential pillar of democracy and informed decision
| Variable | Description | Default | | Variable | Description | Default |
| --- | --- | --- | | --- | --- | --- |
| `PORT` | Port to listen on | `2000` | | `PORT` | Port to listen on | `2000` |
| `PORT_PROXY` | Port the proxy listens on | `3000` | | `PREFORK` | Spawn multiple server instances | `false` |
| `HTTP_PROXY` | Proxy to use | `http://127.0.0.1:3000` |

View File

@@ -1,73 +1,35 @@
package main package main
import ( import (
"fmt"
"log" "log"
"net/http"
"os" "os"
"paywall-ladder/handlers" "paywall-ladder/handlers"
"runtime" "strconv"
"syscall"
"github.com/elazarl/goproxy"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func main() { func main() {
if os.Getenv("PORT_PROXY") == "" { prefork, _ := strconv.ParseBool(os.Getenv("PREFORK"))
os.Setenv("PORT_PROXY", "3000") app := fiber.New(
} fiber.Config{
if os.Getenv("HTTP_PROXY") == "" { Prefork: prefork,
os.Setenv("HTTP_PROXY", "http://127.0.0.1:"+os.Getenv("PORT_PROXY")) },
} )
proxyForkID := uintptr(0) //app.Static("/", "./public")
if runtime.GOOS == "darwin" { app.Get("/", handlers.Form)
_, proxyForkID, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
} else if runtime.GOOS == "linux" { app.Get("/proxy/*", handlers.FetchSite)
proxyForkID, _, _ = syscall.Syscall(syscall.SYS_FORK, 0, 0, 0) app.Get("debug/*", handlers.Debug)
} app.Get("debug2/*", handlers.Debug2)
app.Get("/*", handlers.ProxySite)
fmt.Println("Proxy fork id", proxyForkID)
port := os.Getenv("PORT")
if proxyForkID == 0 { if os.Getenv("PORT") == "" {
port = "2000"
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))
} }
log.Fatal(app.Listen(":" + port))
} }

View File

@@ -5,14 +5,13 @@ services:
container_name: ladder container_name: ladder
#restart: always #restart: always
#command: tail -f /dev/null #command: tail -f /dev/null
command: ./ladder command: sh -c ./ladder
environment: environment:
- PORT=2000 - PORT=2000
- PORT_PROXY=3000 - PREFORK=true
- GODEBUG=netdns=go+4 #- GODEBUG=netdns=go+4
ports: ports:
- "2000:2000" - "2000:2000"
- "8080:3000"
deploy: deploy:
resources: resources:
limits: limits:

View File

@@ -53,7 +53,7 @@ const html = `
</header> </header>
<form id="inputForm" class="col s12" method="get"> <form id="inputForm" class="col s12" method="get">
<div class="row"> <div class="row">
<div class="input-field col s10"> <div class="input-field col s12">
<input type="text" id="inputField" name="inputField" class="validate" required> <input type="text" id="inputField" name="inputField" class="validate" required>
<label for="inputField">URL</label> <label for="inputField">URL</label>
</div> </div>