Compare commits

..

3 Commits

Author SHA1 Message Date
Vladislav Yarmak
56a10f2a32 fix docker example 2020-04-18 12:44:40 +03:00
Snawoot
801178a7de Merge pull request #2 from Snawoot/docker
add docker support
2020-04-18 12:33:59 +03:00
Vladislav Yarmak
6d627de3d7 add docker support 2020-04-18 12:30:26 +03:00
4 changed files with 39 additions and 6 deletions

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
bin/

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM golang AS build
WORKDIR /go/src/github.com/Snawoot/hola-proxy
COPY . .
RUN CGO_ENABLED=0 go build -a -tags netgo -ldflags '-s -w -extldflags "-static"'
ADD https://curl.haxx.se/ca/cacert.pem /certs.crt
RUN chmod 0644 /certs.crt
FROM scratch
COPY --from=build /go/src/github.com/Snawoot/hola-proxy/hola-proxy /
COPY --from=build /certs.crt /etc/ssl/certs/ca-certificates.crt
USER 9999:9999
EXPOSE 8080/tcp
ENTRYPOINT ["/hola-proxy", "-bind-address", "0.0.0.0:8080"]

View File

@@ -20,6 +20,17 @@ Alternatively, you may install hola-proxy from source. Run within source directo
go install
```
Docker image is available as well. Here is an example for running proxy via DE as a background service:
```sh
docker run -d \
--security-opt no-new-privileges \
-p 127.0.0.1:8080:8080 \
--restart unless-stopped \
--name hola-proxy \
yarmak/hola-proxy -country de
```
## Usage
List available countries:

19
main.go
View File

@@ -71,13 +71,13 @@ func parse_args() CLIArgs {
return args
}
func main() {
func run() int {
args := parse_args()
if args.list_countries {
os.Exit(print_countries(args.timeout))
return print_countries(args.timeout)
}
if args.list_proxies {
os.Exit(print_proxies(args.country, args.limit, args.timeout))
return print_proxies(args.country, args.limit, args.timeout)
}
logWriter := NewLogWriter(os.Stderr)
@@ -96,22 +96,29 @@ func main() {
resolver, err := NewResolver(args.resolver, args.timeout)
if err != nil {
mainLogger.Critical("Unable to instantiate DNS resolver: %v", err)
os.Exit(6)
return 6
}
mainLogger.Info("Initializing configuration provider...")
auth, tunnels, err := CredService(args.rotate, args.timeout, args.country, credLogger)
if err != nil {
mainLogger.Critical("Unable to instantiate credential service: %v", err)
os.Exit(4)
logWriter.Close()
return 4
}
endpoint, err := get_endpoint(tunnels, args.proxy_type)
if err != nil {
mainLogger.Critical("Unable to determine proxy endpoint: %v", err)
os.Exit(5)
logWriter.Close()
return 5
}
mainLogger.Info("Starting proxy server...")
handler := NewProxyHandler(endpoint, auth, resolver, proxyLogger)
err = http.ListenAndServe(args.bind_address, handler)
mainLogger.Critical("Server terminated with a reason: %v", err)
mainLogger.Info("Shutting down...")
return 0
}
func main() {
os.Exit(run())
}