Skip to content

Commit e5e900f

Browse files
authored
Build docker container for all linux target architectures386, amd64, arm/v6, arm/v7, arm64/v8, ppc64le, s390x (#797)
* Fixes #768 * buildx build * We need `setuptools_scm` to run `Makefile` * Build `docker` container using `wheel` * Download package distribution * Adjust supported platforms * Alpine only supports v6 * . * May-be fix `lsb_release` * Enable `multiarch` env for docker buildx * Deprecate `DOCKER_IMAGE_TAG` which removes `write-scm-version.py` dependency. Also pass targetplatform as an argument to `container-buildx` make target * Remove `setuptools_scm` dep for docker workflow step * woof * Match all target platforms to match `python-alpine` docker * yamllint * Use `yamllint disable rule:line-length` for `Dockerfile` * Tag the container using `dist-version` * Replace + with . for dev version tag * Add `PROXYPY_CONTAINER_VERSION` step
1 parent 3ff7f21 commit e5e900f

File tree

6 files changed

+131
-66
lines changed

6 files changed

+131
-66
lines changed

.dockerignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# Ignore everything
22
**
33

4-
# Except proxy
5-
!.git
6-
!proxy
7-
!requirements.txt
8-
!pyproject.toml
9-
!setup.cfg
4+
!dist/*.whl
105
!README.md
11-
12-
# Ignore __pycache__ directory
13-
proxy/__pycache__

.github/buildkitd.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[worker.oci]
2+
max-parallelism = 4
3+
[registry."docker.io"]
4+
mirrors = ["mirror.gcr.io"]

.github/workflows/test-library.yml

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# yamllint disable rule:line-length
23
name: lib
34

45
on: # yamllint disable-line rule:truthy
@@ -609,7 +610,7 @@ jobs:
609610
matrix:
610611
os: [ubuntu, windows, macOS]
611612
node: ['10.x', '11.x', '12.x']
612-
max-parallel: 4
613+
# max-parallel: 4
613614
fail-fast: false
614615
steps:
615616
- uses: actions/checkout@v2
@@ -629,37 +630,62 @@ jobs:
629630
cd ..
630631
631632
docker:
632-
# To build our docker container, we must wait for check,
633+
# TODO: To build our docker container, we must wait for check,
633634
# so that we can use the same distribution available.
634-
#
635-
# TL;DR -- Docker must be packaged with package from
636-
# test.pypi.org or from pypi.org.
637-
# needs:
638-
# - publish-pypi
639635
runs-on: ${{ matrix.os }}-latest
640-
name: 🐳 🐍${{ matrix.python }} @ ${{ matrix.os }}
636+
needs:
637+
- build
638+
- pre-setup # transitive, for accessing settings
639+
name: 🐳 🐍${{ matrix.python }} @ ${{ matrix.targetplatform }}
641640
strategy:
642641
matrix:
643-
os: [ubuntu]
644-
python: ['3.10']
645-
max-parallel: 1
642+
os:
643+
- Ubuntu
644+
python:
645+
- '3.10'
646+
targetplatform:
647+
- 'linux/386'
648+
- 'linux/amd64'
649+
- 'linux/arm/v6'
650+
- 'linux/arm/v7'
651+
- 'linux/arm64/v8'
652+
- 'linux/ppc64le'
653+
- 'linux/s390x'
654+
# max-parallel: 1
646655
fail-fast: false
647656
steps:
648-
- uses: actions/checkout@v2
649-
- name: Setup Python
650-
uses: actions/setup-python@v2
657+
- name: Checkout
658+
uses: actions/checkout@v2
659+
- name: Set up Docker Buildx
660+
id: buildx
661+
uses: docker/setup-buildx-action@v1
651662
with:
652-
python-version: ${{ matrix.python }}
653-
- name: Install dependencies
663+
buildkitd-flags: --debug
664+
config: .github/buildkitd.toml
665+
install: true
666+
- name: Download all the dists
667+
uses: actions/download-artifact@v2
668+
with:
669+
name: python-package-distributions
670+
path: dist/
671+
- name: Enable Multiarch # This slows down arm build by 4-5x
672+
run: |
673+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
674+
- name: Create builder
675+
run: |
676+
docker buildx create --name proxypybuilder
677+
docker buildx use proxypybuilder
678+
docker buildx inspect
679+
docker buildx ls
680+
- name: Set PROXYPY_CONTAINER_VERSION
654681
run: |
655-
python -m pip install --upgrade pip
656-
pip install -r requirements.txt
657-
pip install -r requirements-release.txt
658-
pip install -r requirements-testing.txt
659-
pip install -r requirements-tunnel.txt
660-
- name: Build
682+
echo "PROXYPY_CONTAINER_VERSION=$(echo '${{ needs.pre-setup.outputs.dist-version }}' | tr + .)" > $GITHUB_ENV
683+
- name: Build container
661684
run: |
662-
make container
685+
make container-buildx \
686+
-e PROXYPY_PKG_PATH='dist/${{ needs.pre-setup.outputs.wheel-artifact-name }}' \
687+
-e BUILDX_TARGET_PLATFORM='${{ matrix.targetplatform }}' \
688+
-e PROXYPY_CONTAINER_VERSION='${{ env.PROXYPY_CONTAINER_VERSION }}'
663689
664690
check: # This job does nothing and is only used for the branch protection
665691
needs:

Dockerfile

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
FROM python:3.10-alpine as base
2-
RUN apk add git
3-
4-
FROM base as builder
5-
6-
COPY .git /app/.git
7-
COPY requirements.txt /app/
8-
COPY pyproject.toml /app/
9-
COPY setup.cfg /app/
10-
COPY README.md /app/
11-
COPY proxy/ /app/proxy/
12-
WORKDIR /app
13-
RUN pip install --upgrade pip && \
14-
pip install --prefix=/deps .
15-
16-
FROM base
17-
182
LABEL com.abhinavsingh.name="abhinavsingh/proxy.py" \
19-
com.abhinavsingh.description="⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on \
20-
Network monitoring, controls & Application development, testing, debugging." \
21-
com.abhinavsingh.url="https://github.com/abhinavsingh/proxy.py" \
22-
com.abhinavsingh.vcs-url="https://github.com/abhinavsingh/proxy.py" \
23-
com.abhinavsingh.docker.cmd="docker run -it --rm -p 8899:8899 abhinavsingh/proxy.py"
3+
com.abhinavsingh.description="⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • \
4+
😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • \
5+
👮🏿 \"Proxy Server\" framework • 🌐 \"Web Server\" framework • ➵ ➶ ➷ ➠ \"PubSub\" framework • \
6+
👷 \"Work\" acceptor & executor framework" \
7+
com.abhinavsingh.url="https://github.com/abhinavsingh/proxy.py" \
8+
com.abhinavsingh.vcs-url="https://github.com/abhinavsingh/proxy.py" \
9+
com.abhinavsingh.docker.cmd="docker run -it --rm -p 8899:8899 abhinavsingh/proxy.py"
10+
ENV PYTHONUNBUFFERED 1
11+
ARG PROXYPY_PKG_PATH
2412

25-
COPY --from=builder /deps /usr/local
13+
COPY README.md /
14+
COPY $PROXYPY_PKG_PATH /
15+
RUN pip install --upgrade pip && \
16+
pip install \
17+
--no-index \
18+
--find-links file:/// \
19+
proxy.py && \
20+
rm *.whl
2621

27-
# Install openssl to enable TLS interception within container
22+
# Install openssl to enable TLS interception & HTTPS proxy options within container
23+
# NOTE: You can comment out this line if you don't intend to use those features.
2824
RUN apk update && apk add openssl
2925

3026
EXPOSE 8899/tcp

Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ SHELL := /bin/bash
22

33
NS ?= abhinavsingh
44
IMAGE_NAME ?= proxy.py
5-
LATEST_TAG := $(NS)/$(IMAGE_NAME):latest
6-
IMAGE_TAG := $(NS)/$(IMAGE_NAME):$(shell ./write-scm-version.sh)
5+
# Override to target specific versions of proxy.py
6+
PROXYPY_CONTAINER_VERSION := latest
7+
# Used by container build and run targets
8+
PROXYPY_CONTAINER_TAG := $(NS)/$(IMAGE_NAME):$(PROXYPY_CONTAINER_VERSION)
79

810
HTTPS_KEY_FILE_PATH := https-key.pem
911
HTTPS_CERT_FILE_PATH := https-cert.pem
@@ -14,6 +16,10 @@ CA_KEY_FILE_PATH := ca-key.pem
1416
CA_CERT_FILE_PATH := ca-cert.pem
1517
CA_SIGNING_KEY_FILE_PATH := ca-signing-key.pem
1618

19+
# Dummy invalid hardcoded value
20+
PROXYPY_PKG_PATH := dist/proxy.py.whl
21+
BUILDX_TARGET_PLATFORM := linux/amd64
22+
1723
OPEN=$(shell which open)
1824
UNAME := $(shell uname)
1925
ifeq ($(UNAME), Linux)
@@ -24,7 +30,7 @@ endif
2430
.PHONY: lib-check lib-clean lib-test lib-package lib-coverage lib-lint lib-pytest
2531
.PHONY: lib-release-test lib-release lib-profile lib-doc
2632
.PHONY: lib-dep lib-flake8 lib-mypy
27-
.PHONY: container container-run container-release
33+
.PHONY: container container-run container-release container-build container-buildx
2834
.PHONY: devtools dashboard dashboard-clean
2935

3036
all: lib-test
@@ -151,12 +157,25 @@ dashboard:
151157
dashboard-clean:
152158
if [[ -d dashboard/public ]]; then rm -rf dashboard/public; fi
153159

154-
container:
155-
docker build -t $(LATEST_TAG) -t $(IMAGE_TAG) .
156-
157-
container-release:
158-
docker push $(IMAGE_TAG)
159-
docker push $(LATEST_TAG)
160+
container: lib-package
161+
$(MAKE) container-build -e PROXYPY_PKG_PATH=$$(ls dist/*.whl)
162+
163+
# Usage:
164+
#
165+
# make container-buildx \
166+
# -e PROXYPY_PKG_PATH=$(ls dist/*.whl) \
167+
# -e BUILDX_TARGET_PLATFORM=linux/arm64 \
168+
# -e PROXYPY_CONTAINER_VERSION=latest
169+
container-buildx:
170+
docker buildx build \
171+
--platform $(BUILDX_TARGET_PLATFORM) \
172+
-t $(PROXYPY_CONTAINER_TAG) \
173+
--build-arg PROXYPY_PKG_PATH=$(PROXYPY_PKG_PATH) .
174+
175+
container-build:
176+
docker build \
177+
-t $(PROXYPY_CONTAINER_TAG) \
178+
--build-arg PROXYPY_PKG_PATH=$(PROXYPY_PKG_PATH) .
160179

161180
container-run:
162-
docker run -it -p 8899:8899 --rm $(LATEST_TAG)
181+
docker run -it -p 8899:8899 --rm $(PROXYPY_CONTAINER_TAG)

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,30 @@ or from GitHub `master` branch
257257

258258
## Using Docker
259259

260+
Stable version container releases are available for following platforms:
261+
262+
- `linux/386`
263+
- `linux/amd64`
264+
- `linux/arm/v6`
265+
- `linux/arm/v7`
266+
- `linux/arm64/v8`
267+
- `linux/ppc64le`
268+
- `linux/s390x`
269+
260270
### Stable Version from Docker Hub
261271

272+
Run `proxy.py` latest container:
273+
262274
```console
263275
docker run -it -p 8899:8899 --rm abhinavsingh/proxy.py:latest
264276
```
265277

278+
To run specific target platform container on multi-platform supported servers:
279+
280+
```console
281+
docker run -it -p 8899:8899 --rm --platform linux/arm64/v8 abhinavsingh/proxy.py:latest
282+
```
283+
266284
### Build Development Version Locally
267285

268286
```console
@@ -394,6 +412,16 @@ To start `proxy.py` from source code follow these instructions:
394412
❯ make lib-dep
395413
```
396414

415+
- Generate `proxy/common/_scm_version.py`
416+
417+
NOTE: *Following step is not necessary for editable installs.*
418+
419+
This file writes SCM detected version to `proxy/common/_scm_version.py` file.
420+
421+
```console
422+
❯ ./write-scm-version.sh
423+
```
424+
397425
- Optionally, run tests
398426

399427
```console
@@ -2038,7 +2066,7 @@ usage: -m [-h] [--enable-events] [--enable-conn-pool] [--threadless]
20382066
[--filtered-url-regex-config FILTERED_URL_REGEX_CONFIG]
20392067
[--cloudflare-dns-mode CLOUDFLARE_DNS_MODE]
20402068

2041-
proxy.py v2.3.2.dev183+g808caa1.d20211124
2069+
proxy.py v2.3.2.dev190+ge60d80d.d20211124
20422070

20432071
options:
20442072
-h, --help show this help message and exit

0 commit comments

Comments
 (0)