Skip to content

Commit 12a4ece

Browse files
committed
Initial commit
0 parents  commit 12a4ece

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

.github/workflows/publish.yml

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

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)