jlelse
/
ProxyExposer
Archived
1
Fork 0

Initial version
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jan-Lukas Else 2021-10-30 10:54:41 +02:00
commit cdc62c50c5
4 changed files with 91 additions and 0 deletions

21
.drone.yml Normal file
View File

@ -0,0 +1,21 @@
kind: pipeline
name: default
type: docker
steps:
- name: publish
image: plugins/docker
settings:
username: nologin
password:
from_secret: docker_password
repo: rg.fr-par.scw.cloud/jlelse/proxyexposer
registry: rg.fr-par.scw.cloud/jlelse
tags: latest
mirror: https://mirror.gcr.io
trigger:
branch:
- master
event:
- push

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM golang:1.17-alpine3.14 as build
WORKDIR /app
ADD *.go go.mod /app/
RUN go build -ldflags '-w -s' -o proxyexposer
FROM alpine:3.14
WORKDIR /app
CMD ["proxyexposer"]
COPY --from=build /app/proxyexposer /bin/

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.jlel.se/jlelse/ProxyExposer
go 1.17

58
main.go Normal file
View File

@ -0,0 +1,58 @@
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
)
func main() {
proxy := os.Getenv("PE_PROXY")
if proxy == "" {
log.Fatal("PE_PROXY not specified")
return
}
proxyUrl, err := url.Parse(proxy)
if err != nil {
log.Fatal(err.Error())
return
}
upstream := os.Getenv("PE_UPSTREAM")
if upstream == "" {
log.Fatal("PE_UPSTREAM not specified")
return
}
upstreamUrl, err := url.Parse(upstream)
if err != nil {
log.Fatal(err.Error())
return
}
portString := os.Getenv("PE_PORT")
if portString == "" {
log.Fatal("PE_PORT not specified")
return
}
port, err := strconv.Atoi(portString)
if err != nil {
log.Fatal(err.Error())
return
}
rp := httputil.NewSingleHostReverseProxy(upstreamUrl)
rp.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}
err = http.ListenAndServe(":"+strconv.Itoa(port), rp)
if err != nil {
log.Fatal(err.Error())
return
}
}