@@ -3,14 +3,113 @@ name: Docker
33
44on :
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
715defaults :
816 run :
917 shell : bash
1018
1119jobs :
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 @-
0 commit comments