-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c05df5
Showing
9 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# Created by https://www.toptal.com/developers/gitignore/api/go | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go | ||
|
||
### Go ### | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
### Go Patch ### | ||
/vendor/ | ||
/Godeps/ | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# syntax=docker/dockerfile:1.2 | ||
FROM golang:1.16-alpine as build | ||
WORKDIR /go/src/app | ||
COPY go.mod go.sum ./ | ||
RUN --mount=type=cache,target=/root/.cache/go-build go mod download | ||
COPY main.go . | ||
RUN --mount=type=cache,target=/root/.cache/go-build go build -o go-http-proxy | ||
|
||
FROM alpine:3.14 as runtime | ||
COPY --from=build /go/src/app/go-http-proxy /bin | ||
ENTRYPOINT [ "/bin/go-http-proxy" ] | ||
CMD [ "--port=8080" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Go Http Proxy | ||
This is a squid-like HTTP proxy based on [github@smartystreets/cproxy](https://github.com/smartystreets/cproxy). | ||
This git repo is to use the Cproxy library and web app from it as binary artifact can be reused every, as such using any http proxy (Squid, .. so on) | ||
|
||
# Prerequisites | ||
- docker (v20 or above) | ||
- docker-compose ( v1.29.x or above) | ||
|
||
# Getting started | ||
|
||
- Run the app `go run .` | ||
- Validate it `curl -x localhost:8080 https://google.com` or using env var `HTTP_PROXY=http://localhost:8080` for other clients | ||
|
||
or Run the app with custom port: | ||
<details> | ||
- Run the app with custom port `go run . --port=9191` | ||
- Validate it `curl -x localhost:9191 https://google.com` or using env var `HTTP_PROXY=http://localhost:8080` for other clients | ||
</details> | ||
|
||
|
||
or Run it inside container: | ||
<details> | ||
- up it `docker-compose up -d` | ||
- then validate `curl -x $(docker-compose port app 8080) https://google.com` | ||
- clean up it `docker-compose down` | ||
</details> | ||
|
||
# License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3.9' | ||
|
||
services: | ||
app: | ||
build: . | ||
ports: | ||
- 8080 | ||
## custom port | ||
# app-with-custom-port: | ||
# build: . | ||
# ports: | ||
# - 9191 | ||
# command: --port=9191 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/abdennour/go-http-proxy | ||
|
||
go 1.16 | ||
|
||
require github.com/smartystreets/cproxy/v2 v2.0.3 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= | ||
github.com/smartystreets/cproxy/v2 v2.0.3 h1:2QZt+pcC7s114RJyv2sie3te7EYaAkMgTU7t/pjND8A= | ||
github.com/smartystreets/cproxy/v2 v2.0.3/go.mod h1:6vp0ha5Zwl83i12bH5v484+dXLZqb9OSDqioTL5w7Yg= | ||
github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env sh | ||
|
||
# $1: tag | ||
build_function() | ||
{ | ||
IMMUTABLE_TAG=$1 | ||
# if no tag provided | ||
if [ -z "${IMMUTABLE_TAG}" ]; then | ||
if [ ! -z "${SOURCE_COMMIT}" ]; then | ||
export IMMUTABLE_TAG=v$(echo $SOURCE_COMMIT | tail -c +2|head -c 3) | ||
else | ||
timestamp=v$(date +%s) | ||
export IMMUTABLE_TAG=v$(echo $timestamp | tail -c +2|head -c 3) | ||
fi | ||
fi | ||
|
||
echo "------ HOOK START - BUILD -------" | ||
export BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` | ||
export IMMUTABLE_IMAGE_NAME=${DOCKER_REPO}:${IMMUTABLE_TAG} | ||
echo '--- Env vars just before building' | ||
printenv | ||
COMPOSE_FILE=docker-compose.yaml:hooks/docker-compose.ci.yaml \ | ||
docker-compose build app; | ||
# release | ||
docker tag ${IMMUTABLE_IMAGE_NAME} ${IMAGE_NAME} | ||
|
||
echo "---publish immutable artifact ----" | ||
docker push ${IMMUTABLE_IMAGE_NAME} | ||
echo "------ HOOK END - BUILD -------" | ||
} | ||
|
||
|
||
build_function | ||
build_function latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.9' | ||
|
||
services: | ||
app: | ||
image: ${IMMUTABLE_IMAGE_NAME} | ||
labels: | ||
maintainer: "Abdennour Toumi <https://kubernetes.tn>" | ||
tn.kubernetes.license: "MIT" | ||
tn.kubernetes.name: "abdennour/${IMAGE_NAME_ONLY}" | ||
tn.kubernetes.url: "https://github.com/abdennour/bakery-images" | ||
tn.kubernetes.vcs-url: "https://github.com/abdennour/bakery-images.git" | ||
tn.kubernetes.vcs-type: Git | ||
tn.kubernetes.build-date: ${BUILD_DATE} | ||
tn.kubernetes.version: ${IMMUTABLE_TAG} | ||
tn.kubernetes.vcs-ref: ${SOURCE_COMMIT} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/smartystreets/cproxy/v2" | ||
) | ||
|
||
func main() { | ||
port := flag.String("port", "8080", "proxy port") | ||
flag.Parse() | ||
handler := cproxy.New() | ||
log.Printf("Listening on: *:%s", *port) | ||
_ = http.ListenAndServe(":"+*port, handler) | ||
} |