-
Notifications
You must be signed in to change notification settings - Fork 1
Add github release workflow for reproducibly-built debian package #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ameba23
wants to merge
7
commits into
main
Choose a base branch
from
peg/debian-package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd608ad
Add makefile and dockerfile for release builds
ameba23 c5913c3
Tidy makefile
ameba23 7be9328
Add release workflow
ameba23 602f880
Merge branch 'main' into peg/debian-package
ameba23 76bafe2
Rm workflow stage for docker
ameba23 5a5fe00
Apply suggestions from review and add script to check reproducibility
ameba23 2c6c793
Use reproducible version of binary in deb package
ameba23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
| workflow_dispatch: | ||
| inputs: | ||
| draft-release: | ||
| default: false | ||
| description: "Draft Release" | ||
| required: false | ||
| type: boolean | ||
| build-docker: | ||
| default: false | ||
| description: "Build Docker" | ||
| required: false | ||
| type: boolean | ||
| build-binary: | ||
| default: true | ||
| description: "Build Binary" | ||
| required: false | ||
| type: boolean | ||
| features: | ||
| default: '' | ||
| description: "Binary Compilation Features" | ||
| options: | ||
| - '' | ||
| - 'redact-sensitive' | ||
| required: false | ||
| type: choice | ||
|
|
||
| jobs: | ||
| extract-version: | ||
| name: Extract version | ||
| runs-on: warp-ubuntu-2404-x64-2x | ||
| outputs: | ||
| VERSION: ${{ steps.extract_version.outputs.VERSION }} | ||
| steps: | ||
| - name: Extract version | ||
| id: extract_version | ||
| run: | | ||
| if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | ||
| VERSION="${GITHUB_REF#refs/tags/}" | ||
| else | ||
| VERSION="$(echo ${GITHUB_SHA} | cut -c1-7)" | ||
| fi | ||
| echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | ||
| echo "${VERSION}" | ||
|
|
||
| echo "### Version: \`${VERSION}\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "| | |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| ------------------- | ---------------------- |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`GITHUB_REF_TYPE\` | \`${GITHUB_REF_TYPE}\` |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`GITHUB_REF_NAME\` | \`${GITHUB_REF_NAME}\` |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`GITHUB_REF\` | \`${GITHUB_REF}\` |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`GITHUB_SHA\` | \`${GITHUB_SHA}\` |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`VERSION\` | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY | ||
| echo "| \`FEATURES\` | \`${{ github.event.inputs.features || 'none' }}\` |" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| build-binary: | ||
| name: Build binary | ||
| needs: extract-version | ||
| if: ${{ github.event.inputs.build-binary == 'true' || github.event_name == 'push'}} # when manually triggered or version tagged | ||
| runs-on: ${{ matrix.configs.runner }} | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| strategy: | ||
| matrix: | ||
| configs: | ||
| - target: x86_64-unknown-linux-gnu | ||
| runner: warp-ubuntu-latest-x64-32x | ||
| profile: reproducible | ||
| features: | ||
| - ${{ github.event.inputs.features || '' }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Install rust | ||
| run: | | ||
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
|
|
||
| - name: Build reproducible binary with Docker | ||
| run: | | ||
| RUST_TOOLCHAIN=$(rustc --version | cut -d' ' -f2) | ||
| docker build \ | ||
| --build-arg "RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" \ | ||
| --build-arg "FEATURES=${{ matrix.features }}" \ | ||
| --build-arg "VERSION=${{ needs.extract-version.outputs.VERSION }}" \ | ||
| -f Dockerfile.build-deb -t atp:release \ | ||
| --output type=local,dest=./target . | ||
|
|
||
| - name: Upload attested-tls-proxy artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: attested-tls-proxy-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.configs.target }}${{ matrix.features && '-' }}${{ matrix.features }} | ||
| path: target/${{ matrix.configs.profile }}/attested-tls-proxy | ||
|
|
||
| - name: Upload *.deb package | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: deb-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.configs.target }}${{ matrix.features && '-' }}${{ matrix.features }} | ||
| path: target/debian/*.deb | ||
|
|
||
|
|
||
| draft-release: | ||
| name: Draft release | ||
| if: ${{ github.event.inputs.draft-release == 'true' || github.event_name == 'push'}} # when manually triggered or version tagged | ||
| needs: [extract-version, build-binary] | ||
| runs-on: warp-ubuntu-2404-x64-16x | ||
| env: | ||
| VERSION: ${{ needs.extract-version.outputs.VERSION }} | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Download artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| merge-multiple: true | ||
| path: artifacts | ||
|
|
||
| - name: Record artifacts checksums | ||
| working-directory: artifacts | ||
| run: | | ||
| find ./ || true | ||
| for file in *; do sha256sum "$file" >> sha256sums.txt; done; | ||
| cat sha256sums.txt | ||
|
|
||
| - name: Create release draft | ||
| uses: softprops/[email protected] | ||
| id: create-release-draft | ||
| with: | ||
| draft: true | ||
| files: artifacts/* | ||
| generate_release_notes: true | ||
| name: ${{ env.VERSION }} | ||
| tag_name: ${{ env.VERSION }} | ||
|
|
||
| - name: Write Github Step Summary | ||
| run: | | ||
| echo "---" | ||
| echo "### Release Draft: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "${{ steps.create-release-draft.outputs.url }}" >> $GITHUB_STEP_SUMMARY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,11 @@ members = [".", "dummy-attestation-server"] | |
|
|
||
| [package] | ||
| name = "attested-tls-proxy" | ||
| description = "An HTTP attested TLS proxy server and client for secure communication with CVM services" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| license = "MIT" | ||
| repository = "https://github.com/flashbots/attested-tls-proxy" | ||
|
|
||
| [dependencies] | ||
| tokio = { version = "1.48.0", features = ["full"] } | ||
|
|
@@ -56,3 +58,29 @@ tdx-quote = { version = "0.0.4", features = ["mock"] } | |
| [features] | ||
| default = ["azure"] | ||
| azure = ["tss-esapi", "az-tdx-vtpm"] | ||
|
|
||
| [package.metadata.deb] | ||
| maintainer = "Flashbots Team <[email protected]>" | ||
| depends = "$auto" | ||
| section = "network" | ||
| priority = "optional" | ||
| maintainer-scripts = "pkg/debian" | ||
| assets = [ | ||
| [ | ||
| "target/reproducible/attested-tls-proxy", | ||
| "usr/bin/", | ||
| "755", | ||
| ], | ||
| [ | ||
| "LICENSE", | ||
| "usr/share/doc/attested-tls-proxy/", | ||
| "644", | ||
| ], | ||
| ] | ||
| systemd-units = { enable = false, start = false, unit-name = "attested-tls-proxy" } | ||
|
|
||
| [profile.reproducible] | ||
| inherits = "release" | ||
| lto = "thin" | ||
| panic = "abort" | ||
| incremental = false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ARG RUST_TOOLCHAIN=1.89.0 | ||
| FROM docker.io/rust:$RUST_TOOLCHAIN-trixie AS builder | ||
|
|
||
| ARG FEATURES VERSION | ||
| # Switch to snapshot repository | ||
| RUN sed -i '/^# http/{N;s|^# \(http[^ ]*\)\nURIs: .*|# \1\nURIs: \1|}' /etc/apt/sources.list.d/debian.sources | ||
| RUN apt-get -o Acquire::Check-Valid-Until=false update && \ | ||
| apt-get install -y \ | ||
| pkg-config clang libclang-dev \ | ||
| openssl libssl-dev libtss2-dev \ | ||
| cmake | ||
|
|
||
| WORKDIR /build | ||
| COPY . . | ||
| RUN make build && make build-deb | ||
|
|
||
| FROM scratch AS artifacts | ||
| COPY --from=builder /build/target/x86_64-unknown-linux-gnu/ / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Heavily inspired by rbuilder: https://github.com/flashbots/rbuilder/blob/develop/Makefile | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| GIT_VER ?= $(shell git describe --tags --always --dirty="-dev") | ||
| GIT_TAG ?= $(shell git describe --tags --abbrev=0) | ||
|
|
||
| FEATURES ?= | ||
|
|
||
| ##@ Help | ||
|
|
||
| .PHONY: help | ||
| help: ## Display this help. | ||
| @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
|
||
| .PHONY: v | ||
| v: ## Show the current version | ||
| @echo "Version: ${GIT_VER}" | ||
|
|
||
| ##@ Build | ||
|
|
||
| .PHONY: clean | ||
| clean: ## Clean up | ||
| cargo clean | ||
|
|
||
| # Detect the current architecture | ||
| ARCH := $(shell uname -m) | ||
|
|
||
| # Determine if we're on x86_64 | ||
| ifeq ($(ARCH),x86_64) | ||
| IS_X86_64 = 1 | ||
| else | ||
| IS_X86_64 = 0 | ||
| endif | ||
|
|
||
| # Set build profile and flags based on architecture | ||
| ifeq ($(IS_X86_64),1) | ||
| # x86_64: Use reproducible profile with reproducible build flags | ||
| BUILD_PROFILE = reproducible | ||
| BUILD_TARGET = x86_64-unknown-linux-gnu | ||
|
|
||
| # Environment variables for reproducible builds | ||
| # Initialize RUSTFLAGS | ||
| RUST_BUILD_FLAGS = | ||
| # Optimize for modern CPUs | ||
| RUST_BUILD_FLAGS += -C target-cpu=x86-64-v3 | ||
| # Remove build ID from the binary to ensure reproducibility across builds | ||
| RUST_BUILD_FLAGS += -C link-arg=-Wl,--build-id=none | ||
| # Remove metadata hash from symbol names to ensure reproducible builds | ||
| RUST_BUILD_FLAGS += -C metadata='' | ||
| # Remap paths to ensure reproducible builds | ||
| RUST_BUILD_FLAGS += --remap-path-prefix $(shell pwd)=. | ||
| # Set timestamp from last git commit for reproducible builds | ||
| SOURCE_DATE ?= $(shell git log -1 --pretty=%ct) | ||
| # Set C locale for consistent string handling and sorting | ||
| LOCALE_VAL = C | ||
| # Set UTC timezone for consistent time handling across builds | ||
| TZ_VAL = UTC | ||
|
|
||
| # Environment setup for reproducible builds | ||
| BUILD_ENV = SOURCE_DATE_EPOCH=$(SOURCE_DATE) \ | ||
| RUSTFLAGS="${RUST_BUILD_FLAGS}" \ | ||
| LC_ALL=${LOCALE_VAL} \ | ||
| TZ=${TZ_VAL} \ | ||
| JEMALLOC_OVERRIDE=/usr/lib/x86_64-linux-gnu/libjemalloc.a | ||
| else | ||
| # Non-x86_64: Use release profile without reproducible build flags | ||
| BUILD_PROFILE = release | ||
| BUILD_TARGET = | ||
| RUST_BUILD_FLAGS = | ||
| BUILD_ENV = | ||
| endif | ||
|
|
||
| .PHONY: build | ||
| build: ## Build (release version) | ||
| $(BUILD_ENV) cargo build --features "$(FEATURES)" --locked $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) --profile $(BUILD_PROFILE) | ||
|
|
||
| .PHONY: build-dev | ||
| build-dev: ## Build (debug version) | ||
| cargo build --features "$(FEATURES)" | ||
|
|
||
| ##@ Debian Packages | ||
|
|
||
| .PHONY: install-cargo-deb | ||
| install-cargo-deb: | ||
| @command -v cargo-deb >/dev/null 2>&1 || cargo install [email protected] --locked | ||
|
|
||
| .PHONY: build-deb | ||
| build-deb: install-cargo-deb ## Build Debian package | ||
| cargo deb --profile $(BUILD_PROFILE) --no-build --no-dbgsym --no-strip \ | ||
| -p attested-tls-proxy \ | ||
| $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) \ | ||
| $(if $(VERSION),--deb-version "1~$(VERSION)") | ||
|
|
||
| ##@ Dev | ||
|
|
||
| .PHONY: lint | ||
| lint: ## Run the linters | ||
| cargo fmt -- --check | ||
| cargo clippy --workspace --features "$(FEATURES)" -- -D warnings | ||
|
|
||
| .PHONY: test | ||
| test: | ||
| cargo test --verbose --features "$(FEATURES)" | ||
|
|
||
| .PHONY: lt | ||
| lt: lint test ## Run "lint" and "test" | ||
|
|
||
| .PHONY: fmt | ||
| fmt: ## Format the code | ||
| cargo fmt | ||
| cargo fix --allow-staged | ||
| cargo clippy --features "$(FEATURES)" --fix --allow-staged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Checks reproducibility by running a package build twice and printing hashes of .deb package | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not sure to what extent this really shows that the build is reproducible, but its better than nothing |
||
|
|
||
| set -euo pipefail | ||
|
|
||
| rm -rf /tmp/repro1 /tmp/repro2 | ||
| mkdir -p /tmp/repro1 /tmp/repro2 | ||
|
|
||
| docker build -f Dockerfile.build-deb --no-cache --output type=local,dest=/tmp/repro1 . | ||
| docker build -f Dockerfile.build-deb --no-cache --output type=local,dest=/tmp/repro2 . | ||
|
|
||
| sha256sum /tmp/repro1/debian/*.deb | ||
| sha256sum /tmp/repro2/debian/*.deb | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case it is helpful for you, here is a draft PR where I am adding reproducible debian packaging to lighthouse