Skip to content

Commit 5cabfc0

Browse files
committed
initial commit
0 parents  commit 5cabfc0

6 files changed

Lines changed: 784 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request: {}
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-24.04
11+
permissions:
12+
id-token: write
13+
packages: write
14+
contents: read
15+
attestations: write
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v5
23+
- name: Set up QEMU
24+
id: qemu
25+
uses: docker/setup-qemu-action@v3
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
- run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >>"$GITHUB_ENV"
35+
- run: echo "TOR_VERSION=$(tr -d '\n' <VERSION) >>"$GITHUB_ENV"
36+
- name: Build and push image
37+
uses: docker/build-push-action@v6
38+
id: push
39+
env:
40+
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
41+
with:
42+
context: .
43+
outputs: type=registry,rewrite-timestamp=true
44+
sbom: true
45+
push: ${{ github.event_name != 'pull_request' }}
46+
provenance: "max"
47+
build-args: TOR_VERSION=${{ env.TOR_VERSION }}
48+
platforms: "linux/amd64,linux/arm64"
49+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TOR_VERSION }}
50+
- name: Attest
51+
uses: actions/attest-build-provenance@v2
52+
id: attest
53+
if: ${{ github.event_name == 'push' }}
54+
with:
55+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
56+
subject-digest: ${{ steps.push.outputs.digest }}
57+
push-to-registry: true

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# syntax=docker/dockerfile:1
2+
FROM gentoo/portage:latest AS portage
3+
FROM gentoo/stage3:latest AS builder
4+
5+
# https://gitlab.torproject.org/tpo/core/tor/-/tags
6+
ARG TOR_VERSION
7+
8+
COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
9+
10+
RUN <<EOF
11+
set -euo pipefail
12+
13+
export MAKEOPTS="-j$(nproc)"
14+
export EMERGE_DEFAULT_OPTS="--jobs 2"
15+
export USE="${USE:-""} hardened zstd static-libs"
16+
17+
# Allows us to install any version of tor (we specify it anyways)
18+
echo 'net-vpn/tor **' >/etc/portage/package.accept_keywords/tor
19+
20+
# Use static libs for tor
21+
mkdir -p /etc/portage/env
22+
echo 'EXTRA_ECONF="--enable-static-tor --with-libevent-dir=/usr/lib64 --with-openssl-dir=/usr/lib64 --with-zlib-dir=/usr/lib64"' >/etc/portage/env/torstatic.conf
23+
echo 'net-vpn/tor torstatic.conf' >>/etc/portage/package.env
24+
25+
# Build tor dependencies first (this ensures they're updated and built
26+
# with static-libs)
27+
emerge dev-libs/libevent dev-libs/openssl sys-libs/libcap sys-libs/libseccomp \
28+
sys-libs/zlib app-arch/xz-utils app-arch/zstd
29+
30+
emerge "=net-vpn/tor-${TOR_VERSION}"
31+
strip /usr/bin/tor
32+
EOF
33+
34+
FROM gcr.io/distroless/static-debian12:nonroot
35+
COPY --from=builder /usr/bin/tor /usr/bin/tor
36+
ENTRYPOINT ["/usr/bin/tor"]

0 commit comments

Comments
 (0)