Skip to content

Commit 3e4558b

Browse files
committed
feat: add Docker support with Dockerfile, docker-compose, and example config files
1 parent 53f3975 commit 3e4558b

8 files changed

Lines changed: 155 additions & 2 deletions

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
https_proxy
2+
https_proxy_static
3+
*.pem
4+
config.yaml
5+
config.http.yaml
6+
config.https.yaml
7+
.git
8+
.github
9+
README.md
10+
Makefile
11+
test.sh
12+
generate_certs.sh
13+
packaging

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.22-alpine AS builder
4+
WORKDIR /src
5+
COPY go.mod go.sum* ./
6+
RUN go mod download
7+
COPY main.go ./
8+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /out/https_proxy main.go
9+
10+
FROM alpine:3.20
11+
RUN apk add --no-cache ca-certificates tini \
12+
&& adduser -D -H -u 10001 proxy
13+
COPY --from=builder /out/https_proxy /usr/bin/https_proxy
14+
COPY config.docker.yaml /etc/https_proxy/config.yaml
15+
EXPOSE 8080 8443
16+
USER proxy
17+
ENTRYPOINT ["/sbin/tini","--","/usr/bin/https_proxy"]
18+
CMD ["-config","/etc/https_proxy/config.yaml"]

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ VERSION = $(shell cat VERSION | tr -d '[:space:]')
33
INSTALL_DIR = /usr/bin
44
CONFIG_DIR = /etc/$(PROJECT_NAME)
55
SYSTEMD_DIR = /etc/systemd/system
6+
DOCKER_IMAGE = hightemp/$(PROJECT_NAME)
67

7-
.PHONY: build run clean install uninstall install-service uninstall-service start stop restart status enable disable release
8+
.PHONY: build run clean install uninstall install-service uninstall-service start stop restart status enable disable release docker-build docker-push docker-release
89

910
build:
1011
CGO_ENABLED=0 go build -o $(PROJECT_NAME) main.go
@@ -97,4 +98,14 @@ release:
9798
git tag -f "v$(VERSION)"
9899
git push
99100
git push -f --tags
100-
@echo "Released v$(VERSION)"
101+
@echo "Released v$(VERSION)"
102+
103+
docker-build:
104+
docker build -t $(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_IMAGE):latest .
105+
106+
docker-push: docker-build
107+
docker push $(DOCKER_IMAGE):$(VERSION)
108+
docker push $(DOCKER_IMAGE):latest
109+
110+
docker-release: docker-push
111+
@echo "Pushed $(DOCKER_IMAGE):$(VERSION) and :latest"

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,50 @@ A secure HTTP/HTTPS proxy server in Go with Basic authentication, TLS support, a
2828

2929
Download the latest binary from the [Releases](https://github.com/hightemp/https_proxy/releases) page.
3030

31+
### Docker
32+
33+
One-liner (HTTP proxy on port 8080, default user/pass `user`/`pass`):
34+
35+
```sh
36+
docker run -d --name https_proxy -p 8080:8080 hightemp/https_proxy:latest
37+
```
38+
39+
With a custom config:
40+
41+
```sh
42+
docker run -d --name https_proxy -p 8080:8080 -v $(pwd)/config.yaml:/etc/https_proxy/config.yaml:ro hightemp/https_proxy:latest
43+
```
44+
45+
### Docker Compose (HTTP + HTTPS with Let's Encrypt)
46+
47+
The bundled [docker-compose.yml](docker-compose.yml) starts an HTTP proxy, an HTTPS proxy, and a `certbot` sidecar that issues and auto-renews Let's Encrypt certificates into a shared volume.
48+
49+
1. Copy example configs and edit them (set domain, credentials, ports):
50+
51+
```sh
52+
cp config.http.example.yaml config.http.yaml
53+
cp config.https.example.yaml config.https.yaml
54+
```
55+
56+
2. Issue the initial Let's Encrypt certificate (port 80 must be reachable on your domain):
57+
58+
```sh
59+
docker compose run --rm --service-ports certbot certonly \
60+
--standalone -d example.com -m you@example.com --agree-tos --no-eff-email
61+
```
62+
63+
3. Start the stack:
64+
65+
```sh
66+
docker compose up -d
67+
```
68+
69+
Certbot will renew certificates automatically every 12 hours. Restart the HTTPS proxy after renewal if needed:
70+
71+
```sh
72+
docker compose restart https-proxy
73+
```
74+
3175
### Build from source
3276
3377
1. Clone the repository:
@@ -131,6 +175,9 @@ make start / stop / restart / status
131175
| `make uninstall` | Remove binary and service (keep config) |
132176
| `make uninstall-full` | Remove everything including config |
133177
| `make release` | Tag version from `VERSION` file and push |
178+
| `make docker-build` | Build Docker image `hightemp/https_proxy:VERSION` and `:latest` |
179+
| `make docker-push` | Build and push image to Docker Hub |
180+
| `make docker-release` | Alias for `docker-push` |
134181

135182
## Release
136183

config.docker.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
proxy_addr: 0.0.0.0:8080
2+
username: user
3+
password: pass
4+
proto: http
5+
cert_path: ""
6+
key_path: ""
7+
# upstream_proxy: https://user:pass@upstream-proxy:8080

config.http.example.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
proxy_addr: 0.0.0.0:8080
2+
username: user
3+
password: pass
4+
proto: http
5+
cert_path: ""
6+
key_path: ""
7+
# upstream_proxy: https://user:pass@upstream-proxy:8080

config.https.example.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
proxy_addr: 0.0.0.0:8443
2+
username: user
3+
password: pass
4+
proto: https
5+
cert_path: /etc/letsencrypt/live/example.com/fullchain.pem
6+
key_path: /etc/letsencrypt/live/example.com/privkey.pem
7+
# upstream_proxy: https://user:pass@upstream-proxy:8080

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
# Plain HTTP proxy
3+
http-proxy:
4+
image: hightemp/https_proxy:latest
5+
container_name: https_proxy_http
6+
restart: unless-stopped
7+
ports:
8+
- "8080:8080"
9+
volumes:
10+
- ./config.http.yaml:/etc/https_proxy/config.yaml:ro
11+
12+
# HTTPS proxy with Let's Encrypt certificates (read from shared volume)
13+
https-proxy:
14+
image: hightemp/https_proxy:latest
15+
container_name: https_proxy_https
16+
restart: unless-stopped
17+
ports:
18+
- "8443:8443"
19+
volumes:
20+
- ./config.https.yaml:/etc/https_proxy/config.yaml:ro
21+
- letsencrypt:/etc/letsencrypt:ro
22+
depends_on:
23+
- certbot
24+
25+
# Let's Encrypt certificate manager.
26+
# First-time issue (replace DOMAIN and EMAIL):
27+
# docker compose run --rm --service-ports certbot certonly \
28+
# --standalone -d DOMAIN -m EMAIL --agree-tos --no-eff-email
29+
# Then `docker compose up -d` runs auto-renewal in a loop.
30+
certbot:
31+
image: certbot/certbot:latest
32+
container_name: https_proxy_certbot
33+
restart: unless-stopped
34+
ports:
35+
- "80:80"
36+
volumes:
37+
- letsencrypt:/etc/letsencrypt
38+
- certbot-www:/var/www/certbot
39+
entrypoint: /bin/sh -c "trap exit TERM; while :; do certbot renew --quiet; sleep 12h & wait $${!}; done"
40+
41+
volumes:
42+
letsencrypt:
43+
certbot-www:

0 commit comments

Comments
 (0)