Skip to content

Commit 08c19e9

Browse files
committed
Initial commit
0 parents  commit 08c19e9

File tree

6 files changed

+233
-0
lines changed

6 files changed

+233
-0
lines changed

.github/workflows/publish.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
concurrency:
11+
group: ${{ github.event_name }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
16+
docker:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
contents: read
21+
strategy:
22+
matrix:
23+
config:
24+
- tags: "latest,v0.30,v0.30.1"
25+
rustc: "v1.78.0"
26+
node: "v22.8.0"
27+
solana: "v1.18.17"
28+
anchor: "v0.30.1"
29+
- tags: "v0.30.0"
30+
rustc: "v1.78.0"
31+
node: "v22.8.0"
32+
solana: "v1.18.17"
33+
anchor: "v0.30.0"
34+
- tags: "v0.29,v0.29.0"
35+
rustc: "v1.78.0"
36+
node: "v22.8.0"
37+
solana: "v1.17.25"
38+
anchor: "v0.29.0"
39+
fail-fast: false
40+
steps:
41+
- name: Checkout Repository
42+
uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
- name: Build Docker Image
46+
run: |
47+
tags=$(echo "${{ matrix.config.tags }}" | sed 's/,/ --tag ghcr.io\/wjthieme\/anchor-build:/g')
48+
tags="--tag ghcr.io/wjthieme/anchor-build:$tags"
49+
docker build \
50+
--platform linux/x86_64 \
51+
--build-arg RUSTC_VERSION=${{ matrix.config.rustc }} \
52+
--build-arg NODE_VERSION=${{ matrix.config.node }} \
53+
--build-arg SOLANA_CLI=${{ matrix.config.solana }} \
54+
--build-arg ANCHOR_CLI=${{ matrix.config.anchor }} \
55+
$tags .
56+
- name: Push Docker Image
57+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
58+
run: |
59+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
60+
docker push --all-tags ghcr.io/wjthieme/anchor-build

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM debian:bullseye-slim
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG RUSTC_VERSION="v1.78.0"
5+
ARG NODE_VERSION="v22.8.0"
6+
ARG SOLANA_CLI="v1.17.25"
7+
ARG ANCHOR_CLI="v0.29.0"
8+
9+
ENV HOME="/root"
10+
ENV PATH="${HOME}/.cargo/bin:${PATH}"
11+
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
12+
ENV PATH="${HOME}/.nvm/versions/node/${NODE_VERSION}/bin:${PATH}"
13+
14+
# Install base utilities.
15+
RUN mkdir -p /workdir && mkdir -p /tmp && \
16+
apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
17+
build-essential git curl wget jq pkg-config python3-pip \
18+
libssl-dev libudev-dev
19+
20+
# Install rust.
21+
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
22+
sh rustup.sh --default-toolchain none -y && \
23+
rustup install ${RUSTC_VERSION#v} && \
24+
rustup default ${RUSTC_VERSION#v} && \
25+
rustup component add rustfmt clippy
26+
27+
# Install node / npm / yarn.
28+
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.40.1/install.sh | bash
29+
ENV NVM_DIR="${HOME}/.nvm"
30+
RUN . $NVM_DIR/nvm.sh && \
31+
nvm install ${NODE_VERSION} && \
32+
nvm use ${NODE_VERSION} && \
33+
nvm alias default node && \
34+
npm install -g yarn
35+
36+
# Install Solana tools.
37+
RUN sh -c "$(curl -sSfL https://release.anza.xyz/${SOLANA_CLI}/install)"
38+
39+
# Install anchor.
40+
RUN cargo install --git https://github.com/coral-xyz/anchor --tag ${ANCHOR_CLI} anchor-cli --locked
41+
42+
# Build a dummy program to bootstrap the BPF SDK (doing this speeds up builds).
43+
RUN mkdir -p /tmp && cd /tmp && anchor init dummy && cd dummy && (anchor build || true)
44+
RUN rm -r /tmp/dummy
45+
46+
# Set up the working directory
47+
WORKDIR /workdir
48+
49+
# Copy the entrypoint script
50+
COPY entrypoint.sh /entrypoint.sh
51+
RUN chmod +x /entrypoint.sh
52+
53+
# Define the entrypoint
54+
ENTRYPOINT ["/entrypoint.sh"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 wjthieme
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# anchor-build
2+
3+
Docker image for building Anchor programs.
4+
5+
### Usage
6+
7+
No inputs are required.
8+
9+
```yaml
10+
- uses: wjthieme/anchor-build@v1
11+
```
12+
13+
#### Run a different command
14+
15+
By default, `anchor build` is run. You can specify a different command with the `run` input.
16+
17+
```yaml
18+
- uses: wjthieme/anchor-build@v1
19+
with:
20+
run: "cargo build-sbf"
21+
```
22+
23+
#### Use a different version of Anchor
24+
25+
By default, the latest version of Anchor is used. You can specify a different version with the `anchor-version` input.
26+
27+
```yaml
28+
- uses: wjthieme/anchor-build@v1
29+
with:
30+
anchor-version: "v0.29.0"
31+
```
32+
33+
#### Supply a Solana private key
34+
35+
By default, you'll get a generated keypair to which 1 SOL is airdropped (devnet only). If you want to use your own keypair, you can supply it with the `solana-key` input.
36+
37+
```yaml
38+
- uses: wjthieme/anchor-build@v1
39+
with:
40+
solana-key: ${{ secrets.SOLANA_PRIVATE_KEY }}
41+
```
42+
43+
### Local Testing
44+
45+
Install `docker` and `act` and run:
46+
47+
```sh
48+
act workflow_dispatch
49+
```

action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Anchor Build Container'
2+
description: 'A container for building Anchor programs.'
3+
4+
branding:
5+
icon: anchor
6+
color: blue
7+
8+
inputs:
9+
solana-key:
10+
description: 'The private key to use for the solana sdk.'
11+
required: false
12+
solana-cluster:
13+
description: 'The cluster to use for the solana sdk.'
14+
required: false
15+
default: 'devnet'
16+
anchor-version:
17+
description: 'The version of anchor to use.'
18+
default: 'latest'
19+
run:
20+
description: 'The command(s) to run.'
21+
default: 'anchor build'
22+
23+
runs:
24+
using: "docker"
25+
image: "ghcr.io/wjthieme/anchor-build:${{ inputs.anchor-version }}"
26+
args:
27+
- ${{ inputs.solana-key }}
28+
- ${{ inputs.solana-cluster }}
29+
- ${{ inputs.run }}

entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -xeo pipefail
3+
4+
# Configure Solana
5+
solana config set --url "$2"
6+
7+
# Configure Solana Key
8+
if [ -z "$1" ]; then
9+
solana-keygen new --no-bip39-passphrase
10+
else
11+
echo "$1" > ~/.config/solana/id.json
12+
fi
13+
14+
# Airdrop Solana if on devnet
15+
if [ "$1" ] && [ "$2" == "devnet" ]; then
16+
solana airdrop 1 || true
17+
fi
18+
19+
# Run the provided commands
20+
eval "$3"

0 commit comments

Comments
 (0)