Skip to content

Commit 62dbb5a

Browse files
authored
Merge pull request #73 from opensafely-core/fix-deploy
Fix deployment workflow
2 parents f7b6f71 + 6609fb3 commit 62dbb5a

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

.github/workflows/build_and_publish.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
branches: [main]
55
workflow_dispatch:
66
env:
7-
SSH_AUTH_SOCK: /tmp/agent.sock
7+
APP_NAME: proxy
88
IMAGE_NAME: opensafely-proxy
9-
IMAGE_ID: ghcr.io/opensafely-core/opensafely-proxy
9+
PUBLIC_IMAGE_NAME: ghcr.io/opensafely-core/opensafely-proxy
10+
HOST: dokku4.ebmdatalab.net
11+
SSH_AUTH_SOCK: /tmp/agent.sock
1012
permissions:
1113
packages: write
1214
jobs:
@@ -24,14 +26,32 @@ jobs:
2426
run: docker login https://ghcr.io -u ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }}
2527
- name: Push image to GitHub Container Registry
2628
run: |
27-
docker tag $IMAGE_NAME $IMAGE_ID:latest
28-
docker push $IMAGE_ID:latest
29+
docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:latest
30+
docker push $PUBLIC_IMAGE_NAME:latest
2931
- name: Setup SSH Agent
3032
run: |
3133
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
3234
ssh-add - <<< "${{ secrets.DOKKU4_DEPLOY_SSH_KEY }}"
33-
- name: Deploy
35+
- name: Deploy image
3436
run: |
35-
SHA=$(docker inspect --format='{{index .RepoDigests 0}}' $IMAGE_ID:latest)
36-
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" dokku@dokku4.ebmdatalab.net git:from-image proxy $SHA
37+
set -euo pipefail
38+
39+
# Find the full qualified "repo digest" for this image
40+
IMAGE_DIGEST="$(
41+
docker inspect --format='{{join .RepoDigests "\n"}}' "$PUBLIC_IMAGE_NAME:latest" \
42+
| grep --fixed-strings "$PUBLIC_IMAGE_NAME" || true
43+
)"
44+
# Fail if we have none or more than one (as indicated by the presence of whitespace)
45+
if [[ -z "$IMAGE_DIGEST" || "$IMAGE_DIGEST" =~ [[:space:]] ]]; then
46+
echo "Expected exactly one value in IMAGE_DIGEST, got: $IMAGE_DIGEST"
47+
echo
48+
echo "Debug info:"
49+
set -x
50+
docker inspect --format='{{join .RepoDigests "\n"}}' "$PUBLIC_IMAGE_NAME:latest"
51+
exit 1
52+
fi
3753
54+
echo "Deploying to $HOST"
55+
echo "dokku git:from-image $APP_NAME $IMAGE_DIGEST"
56+
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" \
57+
"dokku@$HOST" git:from-image "$APP_NAME" "$IMAGE_DIGEST"

0 commit comments

Comments
 (0)