Skip to content

Commit ba22c6d

Browse files
committed
Initial commit
0 parents  commit ba22c6d

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

.github/workflows/publish.yml

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

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM ubuntu:22.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG RUSTC_VERSION
5+
ARG NODE_VERSION
6+
ARG SOLANA_CLI
7+
ARG ANCHOR_CLI
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.33.11/install.sh | sh
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
44+
45+
# Set up the working directory
46+
WORKDIR /workdir
47+
48+
# Copy the entrypoint script
49+
COPY entrypoint.sh /entrypoint.sh
50+
RUN chmod +x /entrypoint.sh
51+
52+
# Define the entrypoint
53+
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# anchor-build
2+
3+
Docker image for building Anchor programs.
4+
5+
### TODO
6+
7+
- [ ] Don't hardcode node path in path
8+
- [ ] Use alpine linux for smaller image size

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)