Skip to content

Commit b36124d

Browse files
authored
Publish docker image. (#2448)
1 parent 84c254d commit b36124d

File tree

3 files changed

+158
-19
lines changed

3 files changed

+158
-19
lines changed

.github/workflows/docker.yml

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,113 @@ name: Docker
33

44
on:
55
workflow_dispatch:
6+
inputs:
7+
ref:
8+
description: "The git ref to build from (branch, tag, or commit SHA)."
9+
type: string
10+
required: true
11+
default: main
12+
release:
13+
types: [published]
614

715
defaults:
816
run:
917
shell: bash
1018

1119
jobs:
20+
build:
21+
strategy:
22+
matrix:
23+
include:
24+
- runs-on: ubuntu-latest
25+
arch: amd64
26+
- runs-on: ubuntu-24.04-arm
27+
arch: arm64
28+
runs-on: ${{ matrix.runs-on }}
29+
permissions:
30+
contents: read
31+
steps:
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33+
with:
34+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
35+
36+
- name: Install build dependencies
37+
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libudev-dev libdbus-1-dev
38+
39+
- name: Build binary
40+
run: cargo build --package stellar-cli --release
41+
42+
- name: Upload binary
43+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
44+
with:
45+
name: stellar-${{ matrix.arch }}
46+
path: target/release/stellar
47+
retention-days: 1
48+
1249
docker:
50+
needs: build
1351
runs-on: ubuntu-latest
14-
permissions: {}
52+
permissions:
53+
contents: read
1554
steps:
16-
- run: echo "Building and pushing Docker image..."
55+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
56+
with:
57+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
58+
fetch-depth: 0
59+
60+
- name: Download binaries
61+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
62+
with:
63+
pattern: stellar-*
64+
merge-multiple: false
65+
66+
- name: Set up QEMU
67+
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
71+
72+
- name: Log in to Docker Hub
73+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
74+
with:
75+
username: ${{ secrets.DOCKERHUB_USERNAME }}
76+
password: ${{ secrets.DOCKERHUB_TOKEN }}
77+
78+
# Compute Docker tags from the ref.
79+
# - Version tag (e.g. v1.2.3): push versioned + latest tags.
80+
# - Any other ref: push a tag for the resolved commit SHA.
81+
- name: Compute tags
82+
run: |
83+
ref="${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref_name }}"
84+
85+
if [[ "$ref" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
86+
version="${ref#v}"
87+
echo "DOCKER_TAGS=stellar/stellar-cli:${version},stellar/stellar-cli:latest" >> $GITHUB_ENV
88+
elif [[ "${{ github.event_name }}" == "release" ]]; then
89+
echo "::error::Release tag '${ref}' is not a valid version tag (expected vX.Y.Z)."
90+
exit 1
91+
else
92+
commit="$(git rev-parse HEAD)"
93+
echo "DOCKER_TAGS=stellar/stellar-cli:${commit}" >> $GITHUB_ENV
94+
fi
95+
96+
- name: Build and push
97+
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
98+
with:
99+
context: .
100+
platforms: linux/amd64,linux/arm64
101+
push: true
102+
tags: ${{ env.DOCKER_TAGS }}
103+
104+
- name: Update Docker Hub description
105+
run: |
106+
TOKEN=$(curl -s -X POST "https://hub.docker.com/v2/users/login/" \
107+
-H "Content-Type: application/json" \
108+
-d '{"username":"${{ secrets.DOCKERHUB_USERNAME }}","password":"${{ secrets.DOCKERHUB_TOKEN }}"}' \
109+
| jq -r .token)
110+
111+
jq -n --arg desc "$(cat ./docker/README.md)" '{"full_description": $desc}' | \
112+
curl -s -X PATCH "https://hub.docker.com/v2/repositories/stellar/stellar-cli/" \
113+
-H "Content-Type: application/json" \
114+
-H "Authorization: Bearer ${TOKEN}" \
115+
-d @-

Dockerfile

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
FROM rust:latest AS builder
2-
3-
ARG STELLAR_CLI_REF=main
4-
5-
RUN apt-get update && \
6-
apt-get install -y --no-install-recommends libdbus-1-dev libudev-dev pkg-config git && \
7-
rm -rf /var/lib/apt/lists/*
8-
9-
RUN git clone https://github.com/stellar/stellar-cli.git /tmp/stellar-cli && \
10-
cd /tmp/stellar-cli && \
11-
git fetch origin "${STELLAR_CLI_REF}" && \
12-
git checkout "${STELLAR_CLI_REF}" && \
13-
cargo install --locked --path cmd/stellar-cli && \
14-
rm -rf /tmp/stellar-cli
15-
161
FROM rust:latest
172

183
RUN rustup target add wasm32v1-none
@@ -21,13 +6,15 @@ RUN apt-get update && \
216
apt-get install -y --no-install-recommends dbus gnome-keyring libdbus-1-3 libudev1 libssl3 && \
227
rm -rf /var/lib/apt/lists/*
238

24-
COPY --from=builder /usr/local/cargo/bin/stellar /usr/local/bin/stellar
9+
ARG TARGETARCH
10+
COPY stellar-${TARGETARCH}/stellar /usr/local/bin/stellar
2511

2612
ENV STELLAR_CONFIG_HOME=/config
2713
ENV STELLAR_DATA_HOME=/data
2814

2915
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
30-
RUN chmod +x /usr/local/bin/entrypoint.sh
16+
RUN chmod +x /usr/local/bin/entrypoint.sh && \
17+
chmod +x /usr/local/bin/stellar
3118

3219
WORKDIR /source
3320

docker/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Stellar CLI
2+
3+
Command-line interface for building and deploying smart contracts on the [Stellar](https://stellar.org) network.
4+
5+
For full documentation, visit [https://developers.stellar.org](https://developers.stellar.org).
6+
7+
## Quick Start
8+
9+
```sh
10+
docker run --rm -it -v "$(pwd)":/source stellar/stellar-cli version
11+
```
12+
13+
## Usage
14+
15+
The container expects your project files to be mounted at `/source` (the default working directory). Any `stellar` subcommand can be passed directly:
16+
17+
```sh
18+
# Build a contract
19+
docker run --rm -it -v "$(pwd)":/source stellar/stellar-cli contract build
20+
21+
# Deploy a contract
22+
docker run --rm -it \
23+
-v "$(pwd)":/source \
24+
-e STELLAR_RPC_URL=https://soroban-testnet.stellar.org:443 \
25+
-e STELLAR_NETWORK_PASSPHRASE="Test SDF Network ; September 2015" \
26+
stellar/stellar-cli contract deploy --wasm target/wasm32v1-none/release/my_contract.wasm --source <key>
27+
```
28+
29+
### Persisting Configuration
30+
31+
Configuration and data are stored inside the container by default and lost when it exits. Mount volumes to keep them across runs:
32+
33+
```sh
34+
docker run --rm -it \
35+
-v "$(pwd)":/source \
36+
-v stellar-config:/config \
37+
-v stellar-data:/data \
38+
stellar/stellar-cli contract build
39+
```
40+
41+
## Container Paths
42+
43+
| Path | Description |
44+
| --- | --- |
45+
| `/source` | Working directory where project files should be mounted. |
46+
| `/config` | CLI configuration directory (`STELLAR_CONFIG_HOME`). Mount a volume to persist networks and keys across runs. |
47+
| `/data` | CLI data directory (`STELLAR_DATA_HOME`). Mount a volume to persist cached contract specs and data. |
48+
49+
## Image Tags
50+
51+
- `latest` — most recent release.
52+
- `X.Y.Z` — specific release version (e.g. `22.6.0`).
53+
- `<commit-sha>` — build from a specific commit.

0 commit comments

Comments
 (0)