Skip to content

Commit dce5cfd

Browse files
cli, docker: Version verifiable builder with cli (#145)
1 parent 3f31be2 commit dce5cfd

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ incremented for features.
1111

1212
## [Unreleased]
1313

14+
* cli: Version verifiable docker builder ([#145](https://github.com/project-serum/anchor/pull/145)).
15+
1416
## [0.4.0] - 2021-04-04
1517

1618
## Features

cli/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use std::string::ToString;
3131
mod config;
3232
mod template;
3333

34+
// Version of the docker image.
35+
const DOCKER_BUILDER_VER: &str = env!("CARGO_PKG_VERSION");
36+
3437
#[derive(Debug, Clap)]
3538
pub struct Opts {
3639
#[clap(subcommand)]
@@ -380,7 +383,7 @@ fn build_cwd(
380383
fn build_cwd_verifiable(workspace_dir: &Path) -> Result<()> {
381384
// Docker vars.
382385
let container_name = "anchor-program";
383-
let image_name = "projectserum/build";
386+
let image_name = format!("projectserum/build:v{}", DOCKER_BUILDER_VER);
384387
let volume_mount = format!(
385388
"{}:/workdir",
386389
workspace_dir.canonicalize()?.display().to_string()

docker/Makefile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
IMG_ORG ?= projectserum
2-
IMG_VER ?= latest
3-
41
WORKDIR=$(PWD)
2+
#
3+
# Extract anchor version from the Cargo.toml.
4+
#
5+
ANCHOR_CLI=v$(shell awk -F ' = ' '$$1 ~ /version/ { gsub(/[\"]/, "", $$2); printf("%s",$$2) }' ../cli/Cargo.toml)
6+
#
7+
# Solana toolchain.
8+
#
9+
SOLANA_CLI=v1.6.3
10+
#
11+
# Build version should match the Anchor cli version.
12+
#
13+
IMG_ORG ?= projectserum
14+
IMG_VER ?= $(ANCHOR_CLI)
515

616
.PHONY: build build-push build-shell
717

818
default:
919

1020
build: build/Dockerfile
11-
@docker build $@ -t $(IMG_ORG)/$@:$(IMG_VER)
21+
@docker build \
22+
--build-arg ANCHOR_CLI=$(ANCHOR_CLI) \
23+
--build-arg SOLANA_CLI=$(SOLANA_CLI) \
24+
$@ -t $(IMG_ORG)/$@:$(IMG_VER)
1225

1326
build-push:
1427
@docker push $(IMG_ORG)/anchorbuild:$(IMG_VER)

docker/build/Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
#
2+
# Docker image to generate deterministic, verifiable builds of Anchor programs.
3+
# This must be run *after* a given ANCHOR_CLI version is published and a git tag
4+
# is released on GitHub.
5+
#
6+
17
FROM ubuntu:18.04
28

39
ARG DEBIAN_FRONTEND=noninteractive
410

5-
ARG SOLANA_CHANNEL=v1.2.17
6-
ARG SOLANA_CLI=v1.5.6
11+
ARG SOLANA_CLI
12+
ARG ANCHOR_CLI
713

814
ENV HOME="/root"
915
ENV PATH="${HOME}/.cargo/bin:${PATH}"
@@ -21,16 +27,10 @@ RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
2127
rustup component add rustfmt clippy
2228

2329
# Install Solana tools.
24-
RUN curl -sSf https://raw.githubusercontent.com/solana-labs/solana/${SOLANA_CLI}/install/solana-install-init.sh | sh -s - ${SOLANA_CLI} && \
25-
# BPF sdk.
26-
curl -L --retry 5 --retry-delay 2 -o bpf-sdk.tar.bz2 http://solana-sdk.s3.amazonaws.com/${SOLANA_CHANNEL}/bpf-sdk.tar.bz2 && \
27-
rm -rf bpf-sdk && \
28-
mkdir -p bpf-sdk && \
29-
tar jxf bpf-sdk.tar.bz2 && \
30-
rm -f bpf-sdk.tar.bz2
30+
RUN sh -c "$(curl -sSfL https://release.solana.com/${SOLANA_CLI}/install)"
3131

3232
# Install anchor.
33-
RUN cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
33+
RUN cargo install --git https://github.com/project-serum/anchor --tag ${ANCHOR_CLI} anchor-cli --locked
3434

3535
# Build a dummy program to bootstrap the BPF SDK (doing this speeds up builds).
3636
RUN mkdir -p /tmp && cd tmp && anchor init dummy && cd dummy && anchor build

0 commit comments

Comments
 (0)