forked from stellar/stellar-cli-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
120 lines (108 loc) · 4.99 KB
/
Copy pathDockerfile
File metadata and controls
120 lines (108 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# syntax=docker/dockerfile:1.10
# Reproducible stellar-cli image. See SEP-58 for the full contract:
# https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0058.md
#
# Every input is pinned. The base image is referenced by its multi-arch
# index digest exclusively — FROM never carries a tag — so a drifting tag
# cannot silently change what we build against. RUST_VERSION and
# RUST_BASE_SUFFIX are surfaced in labels (and RUST_VERSION drives
# RUSTUP_TOOLCHAIN) but are metadata, not load-bearing on FROM. The Rust
# toolchain is pinned by version, and stellar-cli by a specific upstream
# commit SHA. Build args are not optional; the build scripts and CI
# workflows always supply them.
ARG RUST_VERSION
ARG RUST_BASE_SUFFIX
ARG RUST_IMAGE_DIGEST
# Falls back to RUST_IMAGE_DIGEST so direct `docker build` usage keeps working
# without supplying CLI_RUST_IMAGE_DIGEST. The build scripts and CI always set
# it explicitly (from cli_rust_version) so the builder stage can diverge from
# the final stage's base image.
ARG CLI_RUST_IMAGE_DIGEST=${RUST_IMAGE_DIGEST}
ARG STELLAR_CLI_REV
ARG STELLAR_CLI_VERSION
ARG BUILD_DATE
ARG SOURCE_REPO
FROM rust@${CLI_RUST_IMAGE_DIGEST} AS builder
ARG STELLAR_CLI_REV
ARG STELLAR_CLI_VERSION
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
ENV CARGO_HOME=/usr/local/cargo \
DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
git \
libdbus-1-dev \
libssl-dev \
libudev-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
RUN cargo install --locked --root /out \
--git https://github.com/stellar/stellar-cli.git \
--rev "${STELLAR_CLI_REV}" \
stellar-cli
# Fail the build loudly if the binary's reported version disagrees with the
# version the caller declared. Catches accidental ref/version drift in
# builds.json at build time, not later when an image is already published.
#
# Full `stellar version` output is captured first, then parsed in memory.
# Piping `stellar version | head -n1` closes head's read end after the
# first line, leaving stellar with a broken pipe on its remaining writes;
# Rust 1.96+ panics on EPIPE from stdio rather than exiting quietly, and
# pipefail propagates that as a build failure even though the values matched.
RUN installed_version="$(/out/bin/stellar version --only-version)" \
&& stellar_version_output="$(/out/bin/stellar version)" \
&& installed_rev="$(printf '%s\n' "$stellar_version_output" | grep -oE '[0-9a-f]{40}' | head -n1)" \
&& test "$installed_version" = "${STELLAR_CLI_VERSION}" \
&& test "$installed_rev" = "${STELLAR_CLI_REV}" \
|| { echo "stellar-cli mismatch: binary reports version='$installed_version' rev='$installed_rev', expected version='${STELLAR_CLI_VERSION}' rev='${STELLAR_CLI_REV}'" >&2; exit 1; }
FROM rust@${RUST_IMAGE_DIGEST}
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
ARG RUST_VERSION
ARG RUST_BASE_SUFFIX
ARG RUST_IMAGE_DIGEST
ARG STELLAR_CLI_REV
ARG STELLAR_CLI_VERSION
ARG BUILD_DATE
ARG SOURCE_REPO
# RUSTUP_TOOLCHAIN is baked in so an in-source `rust-toolchain.toml` in a
# consumer's contract can't silently swap our pinned toolchain at build
# time. Required by SEP-58 "self-contained build environment". Consumers can
# still override with `-e RUSTUP_TOOLCHAIN=...` if they know what they're
# doing.
ENV DEBIAN_FRONTEND=noninteractive \
RUSTUP_TOOLCHAIN=${RUST_VERSION}
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
libdbus-1-3 \
libssl3 \
libudev1 \
&& rm -rf /var/lib/apt/lists/*
RUN rustup target add wasm32v1-none
RUN useradd --create-home --home-dir /stellar --uid 1000 --shell /bin/bash stellar \
&& mkdir -p /source /config /data \
&& chown stellar:stellar /source /config /data
COPY --from=builder --chown=root:root --chmod=0755 /out/bin/stellar /usr/local/bin/stellar
ENV CARGO_HOME=/stellar/.cargo \
HOME=/stellar \
STELLAR_CONFIG_HOME=/config \
STELLAR_DATA_HOME=/data \
STELLAR_NO_UPDATE_CHECK=1
USER stellar
WORKDIR /source
ENTRYPOINT ["stellar"]
CMD []
LABEL org.opencontainers.image.title="stellar-cli" \
org.opencontainers.image.description="Stellar CLI image (SEP-58-compatible image for Stellar smart contracts)." \
org.opencontainers.image.source="https://github.com/${SOURCE_REPO}" \
org.opencontainers.image.url="https://github.com/${SOURCE_REPO}" \
org.opencontainers.image.documentation="https://github.com/${SOURCE_REPO}" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.vendor="Stellar Development Foundation" \
org.opencontainers.image.version="${STELLAR_CLI_VERSION}" \
org.opencontainers.image.revision="${STELLAR_CLI_REV}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.base.name="docker.io/library/rust:${RUST_VERSION}-${RUST_BASE_SUFFIX}" \
org.opencontainers.image.base.digest="${RUST_IMAGE_DIGEST}"