Commit 9cf781b6 authored by Clara Engler's avatar Clara Engler
Browse files

Merge branch 'onionmasq-linux-binary-packages' into 'main'

CI: build linux binaries as artifacts, packages and releases.

Closes #190

See merge request !698
parents e6757abd 498594b6
Loading
Loading
Loading
Loading
Loading
+72 −1
Original line number Diff line number Diff line
@@ -148,6 +148,27 @@ rust-latest:
  after_script:
    - cargo clean

# Build a standalone Linux onionmasq binary. The artifact is consumed by deploy
# jobs and is also useful for quick testing from CI pipelines.
linux-release-binary:
  <<: *rules_build_test
  stage: build_rust
  needs:
    - job: resolve-image
  image: "$IMAGE_REF"
  script:
    - ': "${IMAGE_REF:?Missing IMAGE_REF from resolve-image dotenv}"'
    - cargo build -p onionmasq --release --verbose
    - mkdir -p build/onionmasq-linux-x86_64
    - cp target/release/onionmasq build/onionmasq-linux-x86_64/onionmasq
  after_script:
    - cargo clean
  artifacts:
    name: "onionmasq-linux-x86_64-${CI_COMMIT_REF_SLUG}"
    expire_in: 30d
    paths:
      - build/onionmasq-linux-x86_64/onionmasq

# Runs in MR, branch, tag, and web pipelines (via .rules_build_test).
rust-clippy:
  <<: *rules_build_test
@@ -278,6 +299,57 @@ rust-coverage-aggregated:
    # Otherwise skip (e.g., forks or dev branches)
    - when: never

# Publish the standalone Linux binary to GitLab's generic package registry.
# Default-branch builds update the single "main" package version; tag builds
# publish a tag-versioned package and link it from the GitLab Release.
deploy-linux-release-binary:
  needs:
    - job: resolve-image
    - job: linux-release-binary
      artifacts: true
  image: "$IMAGE_REF"
  stage: deploy
  rules:
    - if: '$CI_COMMIT_TAG'
      when: on_success
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      when: on_success
    - when: never
  script: |
    set -euo pipefail

    : "${IMAGE_REF:?Missing IMAGE_REF from resolve-image dotenv}"

    PACKAGE_VERSION="${CI_COMMIT_TAG:-main}"
    PACKAGE_NAME="onionmasq-linux-x86_64"
    FILE_NAME="onionmasq"
    FILE_PATH="build/onionmasq-linux-x86_64/onionmasq"
    PACKAGE_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/${FILE_NAME}"

    curl --fail \
      --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
      --upload-file "${FILE_PATH}" \
      "${PACKAGE_URL}"

    if [[ -n "${CI_COMMIT_TAG:-}" ]]; then
      RELEASE_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases"
      RELEASE_LINK_URL="${RELEASE_URL}/${CI_COMMIT_TAG}/assets/links"

      curl --fail --request POST \
        --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
        --data-urlencode "name=onionmasq ${CI_COMMIT_TAG}" \
        --data-urlencode "tag_name=${CI_COMMIT_TAG}" \
        --data-urlencode "description=onionmasq ${CI_COMMIT_TAG}" \
        "${RELEASE_URL}" || true

      curl --fail --request POST \
        --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
        --data-urlencode "name=onionmasq-linux-x86_64" \
        --data-urlencode "url=${PACKAGE_URL}" \
        --data "link_type=package" \
        "${RELEASE_LINK_URL}"
    fi

# deploy onionmasq - this job requires manual intervention, when merged to main
deploy-onionmasq:
  needs: 
@@ -315,4 +387,3 @@ deploy-onionmasq-debug:
    - popd
  after_script:
    - rm -fr ./android/OnionmasqAndroid/{onionmasq,sampleapp}/build/intermediates
+19 −2
Original line number Diff line number Diff line
@@ -60,9 +60,26 @@ We are hanging out on `#tor-vpn` on the IRC network OFTC. You can also reach thi

## Running outside Android

The VPN logic can also be run outside the Android app, on a standalone Linux
computer. Run the `onionmasq` crate to give this a go:
Onionmasq is both a reusable library stack and a standalone Linux binary. The
VPN logic can be run outside the Android app, on a standalone Linux computer.

Recent Linux x86_64 development builds are published as the `main` version of
the `onionmasq-linux-x86_64` package in the
[GitLab package registry](https://gitlab.torproject.org/tpo/core/onionmasq/-/packages).
Tagged builds are published with the tag as the package version and linked from
the corresponding [GitLab Release](https://gitlab.torproject.org/tpo/core/onionmasq/-/releases).

For quick testing from a recent `main` pipeline, you can also fetch the
short-lived `linux-release-binary` CI artifact directly:

    $ curl -L -o onionmasq 'https://gitlab.torproject.org/tpo/core/onionmasq/-/jobs/artifacts/main/raw/build/onionmasq-linux-x86_64/onionmasq?job=linux-release-binary'
    $ chmod +x onionmasq

If you prefer not to download a prebuilt binary, clone the repository and run
the crate locally:

    $ git clone https://gitlab.torproject.org/tpo/core/onionmasq.git
    $ cd onionmasq
    $ cargo run -p onionmasq

On first run, this will complain of a missing TUN interface.