Initial version
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
commit
cdc62c50c5
|
@ -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
|
|
@ -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/
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue