Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

96 lines · 4.7 KBRaw History
1# Diffinery runner image (Cloudflare Containers, linux/amd64).
2# Build context: containers/runner. Run `pnpm build` first so dist/agent.mjs exists.
3#
4# docker build --platform linux/amd64 -t diffinery-runner containers/runner
5ARG BASE_IMAGE=ubuntu:24.04
6FROM ${BASE_IMAGE}
7
8ARG NODE_VERSION=22.22.0
9
10ENV DEBIAN_FRONTEND=noninteractive \
11 LANG=C.UTF-8 \
12 LC_ALL=C.UTF-8 \
13 DIFFINERY_WORK_ROOT=/workspace \
14 RUNNER_TOOL_CACHE=/opt/hostedtoolcache \
15 AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache \
16 COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
17 # What hosted ubuntu-24.04 runners report; setup-* actions key their caches on it.
18 ImageOS=ubuntu24 \
19 ImageVersion=20250101.1 \
20 # Ubuntu 24.04 marks the system Python as externally managed (PEP 668);
21 # CI scripts commonly `pip install` directly, so allow it like hosted runners do.
22 PIP_BREAK_SYSTEM_PACKAGES=1
23
24# The -dev libraries are what ruby/setup-ruby's prebuilt Rubies link against (psych needs
25# libyaml) and what gems' native extensions build with, as on hosted runners.
26RUN apt-get update \
27 && apt-get install -y --no-install-recommends \
28 ca-certificates curl git git-lfs jq zip unzip xz-utils tar gzip zstd \
29 build-essential pkg-config openssh-client gnupg \
30 python3 python3-pip python3-venv python-is-python3 \
31 libyaml-dev libssl-dev libffi-dev zlib1g-dev libreadline-dev libgmp-dev \
32 bubblewrap \
33 && git config --system --add safe.directory '*' \
34 && git lfs install --system --skip-repo \
35 && apt-get clean \
36 && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
37
38# Node.js LTS from the official tarball (checksum-verified), with corepack shims for pnpm/yarn.
39RUN set -eux; \
40 cd /tmp; \
41 file="node-v${NODE_VERSION}-linux-x64.tar.xz"; \
42 curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/${file}"; \
43 curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt" | grep " ${file}\$" | sha256sum -c -; \
44 tar -xJf "${file}" -C /usr/local --strip-components=1 --no-same-owner \
45 --exclude='*/CHANGELOG.md' --exclude='*/README.md' --exclude='*/LICENSE' --exclude='*/include/*' --exclude='*/share/doc/*'; \
46 rm -f "${file}"; \
47 corepack enable; \
48 corepack prepare pnpm@10.28.0 --activate; \
49 corepack prepare yarn@1.22.22 --activate; \
50 node --version; npm --version; pnpm --version; yarn --version; \
51 npm cache clean --force; \
52 rm -rf /root/.npm /tmp/*
53
54# nvm, as on hosted runners: login shells (`shell: bash -l {0}`) can `nvm install` other Node.js versions.
55# A fixed tag, checked against its commit.
56ARG NVM_VERSION=v0.40.7
57ARG NVM_COMMIT=f0b0c6bb0b281ceeb106c8cf9ab8fde141215092
58ENV NVM_DIR=/usr/local/nvm
59RUN set -eux; \
60 git clone -q --depth 1 --branch "${NVM_VERSION}" https://github.com/nvm-sh/nvm.git "${NVM_DIR}"; \
61 test "$(git -C "${NVM_DIR}" rev-parse HEAD)" = "${NVM_COMMIT}"; \
62 rm -rf "${NVM_DIR}/.git"; \
63 printf '%s\n' 'export NVM_DIR=/usr/local/nvm' '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' > /etc/profile.d/nvm.sh; \
64 bash -lc 'nvm --version'
65
66# GitHub CLI (preinstalled on hosted runners; workflows call `gh` with GH_TOKEN).
67RUN set -eux; \
68 install -m 0755 -d /etc/apt/keyrings; \
69 curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /etc/apt/keyrings/githubcli-archive-keyring.gpg; \
70 echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list; \
71 apt-get update; \
72 apt-get install -y --no-install-recommends gh; \
73 apt-get clean; \
74 rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
75
76# Docker Engine, started on first use by the /usr/local/bin/docker wrapper. Cloudflare
77# Containers run it rootful with iptables, so bridge networks, service DNS, port
78# publishing and builds all work like on GitHub's hosted runners.
79RUN set -eux; \
80 install -m 0755 -d /etc/apt/keyrings; \
81 curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc; \
82 echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable" > /etc/apt/sources.list.d/docker.list; \
83 apt-get update; \
84 apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin iptables; \
85 apt-get clean; \
86 rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
87COPY image/daemon.json /etc/docker/daemon.json
88COPY image/docker /usr/local/bin/docker
89
90RUN mkdir -p /workspace /opt/hostedtoolcache /opt/diffinery
91# image-tag (written by scripts/runner-image.sh) names this image in each job's log and API.
92COPY dist/agent.mjs dist/image-tag* /opt/diffinery/
93
94WORKDIR /workspace
95EXPOSE 8080
96ENTRYPOINT ["node", "/opt/diffinery/agent.mjs"]