浏览代码

fix: workflows

Signed-off-by: zu1k <[email protected]>
zu1k 3 年之前
父节点
当前提交
6fed8955c6
共有 6 个文件被更改,包括 100 次插入8 次删除
  1. 31 0
      .github/workflows/build-docker-image.yml
  2. 4 3
      .github/workflows/build-release.yml
  3. 14 3
      Cargo.lock
  4. 12 0
      Cross.toml
  5. 36 0
      Dockerfile
  6. 3 2
      core/Cargo.toml

+ 31 - 0
.github/workflows/build-docker-image.yml

@@ -0,0 +1,31 @@
+name: Build Docker Images
+on:
+  release:
+    types: [published]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+      - name: Setup Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Login to GitHub Container Registry
+        uses: docker/login-action@v1 
+        with:
+          registry: ghcr.io
+          username: ${{ github.repository_owner }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Docker metadata
+        id: metadata
+        uses: docker/metadata-action@v3
+        with:
+          images: ghcr.io/${{ github.repository_owner }}/good-mitm
+      - name: Build and release Docker images
+        uses: docker/build-push-action@v2
+        with:
+          platforms: linux/amd64,linux/arm64/v8
+          target: good-mitm
+          tags: ${{ steps.metadata.outputs.tags }}
+          push: true

+ 4 - 3
.github/workflows/build-release.yml

@@ -43,6 +43,8 @@ jobs:
 
       - name: Build ${{ matrix.target }}
         timeout-minutes: 120
+        env:
+          PKG_CONFIG_ALLOW_CROSS: "1"
         run: |
           compile_target=${{ matrix.target }}
 
@@ -76,11 +78,10 @@ jobs:
     steps:
       - uses: actions/checkout@v2
 
-      - name: Install GNU tar
+      - name: Install Dependences
         if: runner.os == 'macOS'
         run: |
-          brew install gnu-tar
-          # echo "::add-path::/usr/local/opt/gnu-tar/libexec/gnubin"
+          brew install gnu-tar pkg-config openssl
           echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
 
       - name: Install Rust

+ 14 - 3
Cargo.lock

@@ -237,9 +237,9 @@ dependencies = [
 
 [[package]]
 name = "cargo_metadata"
-version = "0.14.3"
+version = "0.14.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf1007653411165d371d51e7174a6f0e81ec815ecb425c0440c30d5f1ae64e0f"
+checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa"
 dependencies = [
  "camino",
  "cargo-platform",
@@ -710,7 +710,7 @@ dependencies = [
 
 [[package]]
 name = "good-mitm-core"
-version = "0.1.0"
+version = "0.1.1"
 dependencies = [
  "anyhow",
  "bytes",
@@ -725,6 +725,7 @@ dependencies = [
  "hyper-tls",
  "log",
  "moka",
+ "openssl",
  "quick-js",
  "rand",
  "rcgen",
@@ -1211,6 +1212,15 @@ version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 
+[[package]]
+name = "openssl-src"
+version = "111.21.0+1.1.1p"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d0a8313729211913936f1b95ca47a5fc7f2e04cd658c115388287f8a8361008"
+dependencies = [
+ "cc",
+]
+
 [[package]]
 name = "openssl-sys"
 version = "0.9.74"
@@ -1220,6 +1230,7 @@ dependencies = [
  "autocfg",
  "cc",
  "libc",
+ "openssl-src",
  "pkg-config",
  "vcpkg",
 ]

+ 12 - 0
Cross.toml

@@ -0,0 +1,12 @@
+[build]
+pre-build = [
+    "dpkg --add-architecture $CROSS_DEB_ARCH", 
+    "apt-get update && apt-get --assume-yes install pkg-config:$CROSS_DEB_ARCH libssl-dev:$CROSS_DEB_ARCH"
+]
+
+[build.env]
+passthrough = [
+    "RUST_BACKTRACE",
+    "RUST_LOG",
+    "PKG_CONFIG_ALLOW_CROSS"
+]

+ 36 - 0
Dockerfile

@@ -0,0 +1,36 @@
+FROM --platform=$BUILDPLATFORM rust:1.61.0-buster AS build
+
+ARG TARGETARCH
+
+RUN apt-get update && apt-get install -y build-essential curl musl-tools upx pkg-config libssl-dev
+
+WORKDIR /root/good-mitm
+
+ADD . .
+
+RUN rustup install nightly && rustup default nightly && \
+    case "$TARGETARCH" in \
+    "amd64") \
+        RUST_TARGET="x86_64-unknown-linux-musl" \
+        MUSL="x86_64-linux-musl" \
+        ;; \
+    "arm64") \
+        RUST_TARGET="aarch64-unknown-linux-musl" \
+        MUSL="aarch64-linux-musl" \
+        ;; \
+    *) \
+        echo "Doesn't support $TARGETARCH architecture" \
+        exit 1 \
+        ;; \
+    esac && \
+    wget -qO- "https://musl.cc/$MUSL-cross.tgz" | tar -xzC /root/ && \
+    CC=/root/$MUSL-cross/bin/$MUSL-gcc && \
+    rustup target add $RUST_TARGET && \
+    PKG_CONFIG_ALLOW_CROSS=1 RUSTFLAGS="-C linker=$CC" CC=$CC cargo build --target "$RUST_TARGET" --release && \
+    mv target/$RUST_TARGET/release/good-mitm target/release/ && \
+    upx -9 target/release/good-mitm
+
+FROM alpine:3.14 AS good-mitm
+
+COPY --from=build /root/good-mitm/target/release/good-mitm /usr/bin
+ENTRYPOINT [ "good-mitm" ]

+ 3 - 2
core/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "good-mitm-core"
-version = "0.1.0"
+version = "0.1.1"
 edition = "2021"
 description = "Use MITM technology to provide features like rewrite, redirect."
 homepage = "https://github.com/zu1k/good-mitm"
@@ -21,6 +21,7 @@ hyper-rustls = { version = "0.23" }
 hyper-tls = { version = "0.5", optional = true }
 log = "0.4"
 moka = { version = "0.8", features = ["future"] }
+openssl = { version = "0.10", features = ["vendored"], optional = true }
 rcgen = { version = "0.9", features = ["x509-parser"] }
 serde = { version = "1.0", features = ["derive"] }
 thiserror = "1"
@@ -36,5 +37,5 @@ rand = "0.8.5"
 
 [features]
 default = ["h2", "request-native-tls"]
-request-native-tls = ["hyper-tls"]
+request-native-tls = ["hyper-tls", "openssl"]
 h2 = ["hyper-rustls/http2"]