Skip to content

Commit 23f3891

Browse files
authored
Merge pull request #44 from trailofbits/dev
New container image variant for CI use
2 parents cb26811 + d0a5dfd commit 23f3891

File tree

3 files changed

+136
-15
lines changed

3 files changed

+136
-15
lines changed

.github/workflows/docker.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
with:
3232
install: true
3333

34-
- name: Set Docker metadata
34+
- name: Set Docker metadata (interactive variant)
3535
id: metadata
3636
uses: docker/metadata-action@v5
3737
with:
@@ -45,6 +45,19 @@ jobs:
4545
type=ref,event=branch,prefix=testing-
4646
type=edge
4747
48+
- name: Set Docker metadata (CI variant)
49+
id: metadata-ci
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: |
53+
ghcr.io/${{ github.repository }}/ci
54+
tags: |
55+
type=schedule
56+
type=schedule,pattern=nightly-{{date 'YYYYMMDD'}}
57+
type=ref,event=tag
58+
type=ref,event=branch,prefix=testing-
59+
type=edge
60+
4861
- name: GitHub Container Registry Login
4962
uses: docker/login-action@v3
5063
with:
@@ -59,7 +72,7 @@ jobs:
5972
username: ${{ secrets.DOCKERHUB_USERNAME }}
6073
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
6174

62-
- name: Docker Build and Push
75+
- name: Docker Build and Push (interactive variant)
6376
uses: docker/build-push-action@v6
6477
with:
6578
platforms: linux/amd64,linux/arm64/v8
@@ -71,3 +84,16 @@ jobs:
7184
labels: ${{ steps.metadata.outputs.labels }}
7285
cache-from: ${{ (github.event_name != 'schedule' && 'type=gha') || '' }}
7386
cache-to: type=gha,mode=max
87+
88+
- name: Docker Build and Push (CI variant)
89+
uses: docker/build-push-action@v6
90+
with:
91+
platforms: linux/amd64
92+
target: toolbox-ci
93+
file: Dockerfile
94+
pull: true
95+
push: true
96+
tags: ${{ steps.metadata-ci.outputs.tags }}
97+
labels: ${{ steps.metadata-ci.outputs.labels }}
98+
cache-from: ${{ (github.event_name != 'schedule' && 'type=gha') || '' }}
99+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,23 @@ RUN chmod 755 /usr/local/bin/echidna
2323

2424

2525
###
26-
### ETH Security Toolbox
26+
### ETH Security Toolbox - base
2727
###
28-
FROM ubuntu:jammy AS toolbox
28+
FROM ubuntu:jammy AS toolbox-base
2929

3030
# Add common tools
3131
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
3232
bash-completion \
3333
curl \
3434
git \
3535
jq \
36-
python3-dev \
3736
python3-pip \
3837
python3-venv \
3938
sudo \
4039
unzip \
4140
wget \
4241
&& rm -rf /var/lib/apt/lists/*
4342

44-
# improve compatibility with amd64 solc in non-amd64 environments (e.g. Docker Desktop on M1 Mac)
45-
ENV QEMU_LD_PREFIX=/usr/x86_64-linux-gnu
46-
RUN if [ ! "$(uname -m)" = "x86_64" ]; then \
47-
export DEBIAN_FRONTEND=noninteractive \
48-
&& apt-get update \
49-
&& apt-get install -y --no-install-recommends libc6-amd64-cross \
50-
&& rm -rf /var/lib/apt/lists/*; fi
51-
5243
# Add n (node version manager), lts node, npm, and yarn
5344
RUN curl -fsSL https://raw.githubusercontent.com/tj/n/v10.1.0/bin/n -o n && \
5445
if [ ! "a09599719bd38af5054f87b8f8d3e45150f00b7b5675323aa36b36d324d087b9 n" = "$(sha256sum n)" ]; then \
@@ -57,7 +48,7 @@ RUN curl -fsSL https://raw.githubusercontent.com/tj/n/v10.1.0/bin/n -o n && \
5748
fi && \
5849
cat n | bash -s lts && rm n && \
5950
npm install -g n yarn && \
60-
n stable && n prune && npm --force cache clean
51+
n stable --cleanup && n prune && npm --force cache clean
6152

6253
# Include echidna
6354
COPY --chown=root:root --from=echidna /usr/local/bin/echidna /usr/local/bin/echidna
@@ -66,6 +57,22 @@ COPY --chown=root:root --from=echidna /usr/local/bin/echidna /usr/local/bin/echi
6657
COPY --chown=root:root --from=medusa /usr/local/bin/medusa /usr/local/bin/medusa
6758
RUN medusa completion bash > /etc/bash_completion.d/medusa
6859

60+
CMD ["/bin/bash"]
61+
62+
63+
###
64+
### ETH Security Toolbox - interactive variant
65+
###
66+
FROM toolbox-base AS toolbox
67+
68+
# improve compatibility with amd64 solc in non-amd64 environments (e.g. Docker Desktop on M1 Mac)
69+
ENV QEMU_LD_PREFIX=/usr/x86_64-linux-gnu
70+
RUN if [ ! "$(uname -m)" = "x86_64" ]; then \
71+
export DEBIAN_FRONTEND=noninteractive \
72+
&& apt-get update \
73+
&& apt-get install -y --no-install-recommends libc6-amd64-cross \
74+
&& rm -rf /var/lib/apt/lists/*; fi
75+
6976
# Add a user with passwordless sudo
7077
RUN useradd -m ethsec && \
7178
usermod -aG sudo ethsec && \
@@ -114,4 +121,39 @@ RUN git clone --depth 1 https://github.com/crytic/building-secure-contracts.git
114121
COPY --link --chown=root:root motd /etc/motd
115122
RUN echo '\ncat /etc/motd\n' >> ~/.bashrc
116123

117-
CMD ["/bin/bash"]
124+
125+
###
126+
### ETH Security Toolbox - CI variant
127+
### Differences:
128+
### * Runs as root
129+
### * No Foundry autocompletions
130+
### * No pyevmasm
131+
### * No preinstalled solc binaries
132+
### * No BSC copy
133+
###
134+
FROM toolbox-base AS toolbox-ci
135+
136+
ENV HOME="/root"
137+
ENV PATH="${PATH}:${HOME}/.crytic/bin:${HOME}/.vyper/bin:${HOME}/.foundry/bin"
138+
139+
# Install vyper compiler
140+
RUN python3 -m venv ${HOME}/.vyper && \
141+
${HOME}/.vyper/bin/pip3 install --no-cache-dir vyper && \
142+
echo '\nexport PATH=${PATH}:${HOME}/.vyper/bin' >> ~/.bashrc
143+
144+
# Install foundry
145+
RUN curl -fsSL https://raw.githubusercontent.com/foundry-rs/foundry/27cabbd6c905b1273a5ed3ba7c10acce90833d76/foundryup/install -o install && \
146+
if [ ! "e4456a15d43054b537b329f6ca6d00962242050d24de4c59657a44bc17ad8a0c install" = "$(sha256sum install)" ]; then \
147+
echo "Foundry installer does not match expected checksum! exiting"; \
148+
exit 1; \
149+
fi && \
150+
cat install | SHELL=/bin/bash bash && rm install && \
151+
foundryup
152+
153+
# Install python tools
154+
RUN python3 -m venv ${HOME}/.crytic && \
155+
${HOME}/.crytic/bin/pip3 install --no-cache-dir \
156+
solc-select \
157+
crytic-compile \
158+
slither-analyzer && \
159+
echo '\nexport PATH=${PATH}:${HOME}/.crytic/bin' >> ~/.bashrc

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,59 @@ $ node --version
9191
v14.21.3
9292
```
9393

94+
## Usage in CI
95+
96+
A variant of the image is published on GitHub Container Registry as
97+
[`ghcr.io/trailofbits/eth-security-toolbox/ci`](https://github.com/trailofbits/eth-security-toolbox/pkgs/container/eth-security-toolbox%2Fci).
98+
This variant is meant to be slightly lighter, and better suited for its use in
99+
CI contexts such as [GitHub workflow jobs](https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/running-jobs-in-a-container):
100+
101+
102+
```yaml
103+
# workflow triggers, ...
104+
105+
jobs:
106+
tests:
107+
runs-on: ubuntu-latest
108+
container: ghcr.io/trailofbits/eth-security-toolbox/ci:nightly
109+
steps:
110+
# other steps ...
111+
- run: medusa fuzz # or any tool from the image
112+
```
113+
114+
The main differences are:
115+
* The container does not have a dedicated non-root user. All tools are
116+
installed under the root user.
117+
* Most autocompletions are not installed.
118+
* No solc binaries are preinstalled. You may continue to use `solc-select` to
119+
install any binaries you may need.
120+
* pyevmasm and the building secure contracts repository are not included.
121+
122+
## Container image labels
123+
124+
Both `eth-security-toolbox` and `eth-security-toolbox/ci` use the following
125+
label convention:
126+
127+
| Label | Description
128+
|--------------------|--------------------------------------------------------
129+
| `nightly-YYYYMMDD` | Image built from the code in `master` on day YYYY-MM-DD
130+
| `nightly` | Alias for the latest `nightly-YYYYMMDD` container image
131+
| `testing-BRANCH` | Image built when the tip of `BRANCH` was last updated
132+
| `edge` | Alias for `testing-master`
133+
| `TAG` | Image built when `TAG` was tagged
134+
| `latest` | Alias for the latest `TAG` container image
135+
136+
To keep tooling in CI predictable, we recommend picking a `nightly-YYYYMMDD`
137+
image and pinning it by hash on your workflow file. Then, establish a process
138+
to review the changes and update the container reference on a regular cadence,
139+
so that you can continue to benefit from tool improvements. The following
140+
snippet shows the syntax used to pin the image on a GitHub Actions workflow;
141+
the hashes may be obtained from the [container registry page](https://github.com/orgs/trailofbits/packages?repo_name=eth-security-toolbox).
142+
143+
```yaml
144+
container: ghcr.io/trailofbits/eth-security-toolbox/ci:nightly-YYYYMMDD@sha256:HASH_GOES_HERE
145+
```
146+
94147
## Getting Help
95148

96149
Feel free to stop by our [Slack channel](https://slack.empirehacking.nyc/) for

0 commit comments

Comments
 (0)