Skip to content

Commit 43d1e04

Browse files
Merge pull request #8 from runtimeverification/copilot/fix-github-actions-build-publish
fix(ci): create Docker Hub repository before first push
2 parents 6223999 + 9de1888 commit 43d1e04

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,39 @@ jobs:
113113
run: docker run --rm ${TAG} komet-node --help
114114

115115
- name: 'Push Docker image to Docker Hub'
116+
env:
117+
DOCKERHUB_USERNAME: rvdockerhub
118+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
119+
DOCKERHUB_NAMESPACE: runtimeverificationinc
120+
DOCKERHUB_REPO: komet-node
116121
run: |
117-
echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login --username rvdockerhub --password-stdin
122+
# Log in to Docker Hub
123+
echo "${DOCKERHUB_PASSWORD}" | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
124+
125+
# Ensure the Docker Hub repository exists (create if missing).
126+
# Obtain a Docker Hub JWT for API access.
127+
TOKEN=$(curl -s -H "Content-Type: application/json" \
128+
-X POST -d "{\"username\":\"${DOCKERHUB_USERNAME}\",\"password\":\"${DOCKERHUB_PASSWORD}\"}" \
129+
https://hub.docker.com/v2/users/login/ | jq -r '.token // empty')
130+
if [ -z "${TOKEN}" ]; then
131+
echo "::warning::Failed to obtain Docker Hub API token; skipping repo creation"
132+
else
133+
HTTP_CODE=$(curl -s -o /tmp/dockerhub-response.json -w "%{http_code}" \
134+
-H "Authorization: JWT ${TOKEN}" \
135+
-H "Content-Type: application/json" \
136+
-X POST \
137+
-d "{\"namespace\":\"${DOCKERHUB_NAMESPACE}\",\"name\":\"${DOCKERHUB_REPO}\",\"is_private\":false,\"description\":\"Komet Node — local Stellar testnet backed by K semantics\"}" \
138+
"https://hub.docker.com/v2/repositories/")
139+
if [ "${HTTP_CODE}" = "201" ]; then
140+
echo "Docker Hub repository created successfully"
141+
elif [ "${HTTP_CODE}" = "409" ]; then
142+
echo "Docker Hub repository already exists"
143+
else
144+
echo "::warning::Docker Hub repo creation returned HTTP ${HTTP_CODE}: $(cat /tmp/dockerhub-response.json)"
145+
fi
146+
fi
147+
148+
# Push the image
118149
docker image push ${TAG}
119150
120151
- name: 'On failure, delete drafted release'

0 commit comments

Comments
 (0)