diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41866f17..b1c2f6e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,12 @@ name: CI # See https://help.github.com/en/actions/reference/events-that-trigger-workflows -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - main jobs: clippy_check: name: Run clippy check @@ -14,16 +20,11 @@ jobs: toolchain: nightly components: clippy override: true - - - name: Install gui library packages - run: sudo apt-get update && sudo apt-get install -y libwebkit2gtk-4.0-dev build-essential libayatana-appindicator3-dev librsvg2-dev libgtk-3-dev libsoup2.4-dev libjavascriptcoregtk-4.0-dev - - name: Install trunk uses: actions-rs/cargo@v1 with: command: install args: --locked --debug trunk - - name: Install webassembly rust target run: rustup target add wasm32-unknown-unknown @@ -45,7 +46,6 @@ jobs: run: cargo build working-directory: . - rustfmt: name: Check style runs-on: ubuntu-latest @@ -66,7 +66,42 @@ jobs: with: command: fmt args: --all -- --check - + image: + name: Build docker image + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install docker + uses: docker/setup-buildx-action@v2 + - name: Get image tag + id: vars + run: | + rel="$( echo "${GITHUB_REF#refs/*/}" )" + if grep -qE '^\d+\.\d+\.\d+' <<< "$rel" ; then + echo "Using $rel as image tag" + echo "IMAGE_TAG=$rel" >> $GITHUB_ENV + elif [ "$rel" = "main" ]; then + echo "Using dev as image tag" + echo "IMAGE_TAG=dev" >> $GITHUB_ENV + else + rel=$(echo "$GITHUB_SHA" | cut -c1-7) + echo "Using $rel as image tag" + echo "IMAGE_TAG=$rel" >> $GITHUB_ENV + fi + - name: 'Auth to GitHub Container Registry' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + - name: Build and push image + env: + IMAGE_TAG: ${{ env.IMAGE_TAG }} + run: >- + docker buildx build --platform linux/arm64/v8,linux/amd64 + --push -t "ghcr.io/joshrmcdaniel/privaxy:${IMAGE_TAG}" . ci: name: Build runs-on: ${{ matrix.os }} @@ -78,7 +113,7 @@ jobs: rust: stable target: x86_64-unknown-linux-gnu - build: linux - os: ubuntu-latest + os: ubuntu-24.04-arm rust: stable target: aarch64-unknown-linux-gnu steps: @@ -128,11 +163,11 @@ jobs: args: --release --target ${{ matrix.target }} --bin privaxy --target-dir target - name: Build deb run: cargo install cargo-deb && cargo deb -p privaxy --target ${{ matrix.target }} -o target/${{ matrix.target }}/release - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: privaxy-deb-${{ matrix.target }} path: target/${{ matrix.target }}/release/privaxy_*.deb - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: privaxy-${{ matrix.target }} path: | diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4b7eabe1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# syntax=docker/dockerfile:1 + +ARG PRIVAXY_BASE_PATH="/conf" + +FROM rust:1 AS builder +WORKDIR /app + +RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash \ + & rustup target add wasm32-unknown-unknown \ + && cargo binstall trunk +RUN apt-get update && apt-get install -qy \ + pkg-config \ + build-essential \ + cmake \ + clang \ + libssl-dev \ + git +RUN curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh \ + && bash nodesource_setup.sh \ + && apt-get install -qy nodejs + +COPY . . + +RUN cd web_frontend \ + && npm i \ + && trunk build --release \ + && cd .. && cargo build --release + +FROM gcr.io/distroless/cc-debian12:nonroot + +COPY --from=builder /app/target/release/privaxy /app/privaxy + +ARG PRIVAXY_BASE_PATH="/conf" +ENV PRIVAXY_BASE_PATH="${PRIVAXY_BASE_PATH}" +# todo: add support for reading proxy vars +ARG PRIVAXY_PROXY_PORT=8100 +ARG PRIVAXY_WEB_PORT=8200 + +VOLUME [ "${PRIVAXY_BASE_PATH}" ] + + +EXPOSE ${PRIVAXY_PROXY_PORT} ${PRIVAXY_WEB_PORT} +WORKDIR /app +ENTRYPOINT ["/app/privaxy"] \ No newline at end of file diff --git a/privaxy/src/resources/error.html b/privaxy/src/resources/error.html index 98942818..e9201ebe 100644 --- a/privaxy/src/resources/error.html +++ b/privaxy/src/resources/error.html @@ -11,7 +11,7 @@

Bad

Reason: -

#{request_error_reson}#
+
#{request_error_reason}#

diff --git a/privaxy/src/server/configuration/mod.rs b/privaxy/src/server/configuration/mod.rs index 8da4d785..6119f44b 100644 --- a/privaxy/src/server/configuration/mod.rs +++ b/privaxy/src/server/configuration/mod.rs @@ -270,12 +270,9 @@ impl Configuration { } pub(crate) fn get_config_file() -> PathBuf { - get_base_directory() - .unwrap() - .join(CONFIGURATION_FILE_NAME) + get_base_directory().unwrap().join(CONFIGURATION_FILE_NAME) } - fn get_base_directory() -> ConfigurationResult { let base_directory: PathBuf = match env::var("PRIVAXY_BASE_PATH") { Ok(val) => PathBuf::from(&val), diff --git a/privaxy/src/server/proxy/serve.rs b/privaxy/src/server/proxy/serve.rs index 8e4f5a1b..e5df75f3 100644 --- a/privaxy/src/server/proxy/serve.rs +++ b/privaxy/src/server/proxy/serve.rs @@ -155,7 +155,7 @@ pub(crate) async fn serve( fn get_informative_error_response(reason: &str) -> Response { let mut response_body = String::from(include_str!("../../resources/head.html")); response_body += - &include_str!("../../resources/error.html").replace("#{request_error_reson}#", reason); + &include_str!("../../resources/error.html").replace("#{request_error_reason}#", reason); let mut response = Response::new(Body::from(response_body)); *response.status_mut() = http::StatusCode::BAD_GATEWAY;