Skip to content

Commit d969d16

Browse files
authored
ci: Fix the Publish to Docker Hub workflow for good (#3689)
I didn't have the time to fully test the changes made #3650 before I decided to merge it to (hopefully) fix a problem with our cloud deployments. The lack of testing has left us with a series of issues in the new workflow. In this branch, I'm testing the workflow by letting it run all the way through. Only once it's proven to do what it has been designed to do will it be merged. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Sync-service Docker images are automatically published to Docker Hub when a sync-service release is published. * Cloud infrastructure update is triggered automatically when a new Electric release is published. * **Improvements** * Release workflow now coordinates package publishing and Docker image publishing, with explicit release vs canary tagging. * Docker repository names are configurable via environment and the workflow uses the built-in release token. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent bbaf243 commit d969d16

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

.github/workflows/changesets_release.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
runs-on: ubuntu-latest
1919
outputs:
2020
published: ${{ steps.changesets.outputs.published }}
21+
sync_service_release_tag: ${{ steps.sync_service_release_tag.outputs.tag }}
2122
steps:
2223
- uses: actions/checkout@v4
2324
with:
24-
ref: ${{ github.event.pull_request.head.sha }}
2525
fetch-depth: 0
2626
- uses: pnpm/action-setup@v4
2727
- uses: actions/setup-node@v4
@@ -43,8 +43,17 @@ jobs:
4343
publish: pnpm ci:publish
4444
title: 'chore: publish new package versions'
4545
env:
46-
GITHUB_TOKEN: ${{ secrets.OLEKSII_PAT_TOKEN_FOR_DOCKERHUB_RELEASE_WORKFLOW }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
48+
- name: Capture the new sync-service release as an output (if any)
49+
id: sync_service_release_tag
50+
if: steps.changesets.outputs.published == 'true'
51+
run: |
52+
# Assign publishedPackages to a variable first to avoid any interpretation of JSON special chars by the shell
53+
PUBLISHED_PACKAGES='${{ steps.changesets.outputs.publishedPackages }}'
54+
# Use jq to pick the relevant package from the JSON array and format it into a <package>@<version> output
55+
TAGS=$(echo "$PUBLISHED_PACKAGES" | jq -r '.[] | select(.name == "@core/sync-service") | .name + "@" + .version')
56+
echo "tag=$TAGS" >> "$GITHUB_OUTPUT"
4857
- name: Add latest tag to published packages
4958
if: steps.changesets.outputs.published == 'true'
5059
run: node scripts/tag-latest.mjs
@@ -54,14 +63,22 @@ jobs:
5463
env:
5564
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5665
PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
66+
67+
publish-to-dockerhub:
68+
needs: changesets
69+
if: ${{ needs.changesets.outputs.published == 'true' && needs.changesets.outputs.sync_service_release_tag != '' }}
70+
uses: ./.github/workflows/sync_service_dockerhub_image.yml
71+
secrets: inherit
72+
with:
73+
release_tag: ${{ needs.changesets.outputs.sync_service_release_tag }}
74+
5775
update-cloud:
5876
name: Update Electric version used by Cloud
5977
runs-on: ubuntu-latest
6078
needs: changesets
6179
steps:
6280
- uses: actions/checkout@v4
6381
with:
64-
ref: ${{ github.event.pull_request.head.sha }}
6582
fetch-depth: 0
6683
# Get the Electric version of the Docker image
6784
- name: Get Electric version

.github/workflows/sync_service_dockerhub_image.yml

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,65 @@
11
name: Publish Electric images to Docker Hub
22

33
# If you decide to modify the list of triggers for this action, don't forget to also update the
4-
# conditional logic in the derive_build_vars and publish_tagged_image jobs.
4+
# conditional logic based on ${{ github.event_name }} in the derive_build_vars job.
55
on:
66
push:
77
branches: ['main']
88
release:
99
types: [released]
10+
# Allows the workflow to be called by the Changesets workflow
11+
workflow_call:
12+
inputs:
13+
release_tag:
14+
description: 'The @core/sync-service@... tag passed from caller'
15+
required: true
16+
type: string
17+
# Allows the workflow to be triggered manually from the UI
1018
workflow_dispatch:
1119
inputs:
1220
release_tag:
13-
description: 'The @core/sync-service@... tag to run for (e.g. @core/sync-service@v1.2.10)'
21+
description: 'The @core/sync-service@... tag to run the workflow for (e.g. @core/sync-service@1.2.10)'
1422
required: true
1523
type: string
1624

25+
env:
26+
DOCKERHUB_REPO: electricsql/electric
27+
DOCKERHUB_CANARY_REPO: electricsql/electric-canary
28+
1729
jobs:
1830
derive_build_vars:
1931
name: Derive build variables from the source code
2032
runs-on: blacksmith-2vcpu-ubuntu-2404
2133
outputs:
34+
git_ref: ${{ steps.git_ref.outputs.git_ref }}
35+
is_release: ${{ steps.git_ref.outputs.is_release }}
2236
short_commit_sha: ${{ steps.vars.outputs.short_commit_sha }}
2337
electric_version: ${{ steps.vars.outputs.electric_version }}
2438

2539
steps:
40+
- name: Determine the ref to check out
41+
id: git_ref
42+
run: |
43+
case ${{ github.event_name }} in
44+
push)
45+
ref="${{ github.sha }}"
46+
is_release=false
47+
;;
48+
49+
release)
50+
ref="refs/tags/${{ github.event.release.tag_name }}"
51+
is_release=true
52+
;;
53+
54+
workflow_dispatch | workflow_call)
55+
ref="refs/tags/${{ inputs.release_tag }}"
56+
is_release=true
57+
;;
58+
esac
59+
60+
echo "git_ref=$ref" >> $GITHUB_OUTPUT
61+
echo "is_release=$is_release" >> $GITHUB_OUTPUT
62+
2663
- uses: actions/checkout@v4
2764
with:
2865
# The checked out commit influences the value of the ELECTRIC_VERSION variable
@@ -35,10 +72,7 @@ jobs:
3572
#
3673
# For manual triggers via workflow_dispatch, we check out the tag specified manually
3774
# by the actor.
38-
ref: ${{
39-
github.event_name == 'release' && format('refs/tags/{0}', github.event.release.tag_name) ||
40-
github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.release_tag) ||
41-
github.sha }}
75+
ref: ${{ steps.git_ref.outputs.git_ref }}
4276
# Also important to fetch the whole history since otherwise we won't get that tags
4377
# that are required to determine the correct ELECTRIC_VERSION.
4478
fetch-depth: 0
@@ -69,6 +103,8 @@ jobs:
69103
needs: [derive_build_vars]
70104
steps:
71105
- uses: actions/checkout@v4
106+
with:
107+
ref: ${{ needs.derive_build_vars.outputs.git_ref }}
72108

73109
- uses: useblacksmith/setup-docker-builder@v1
74110

@@ -93,8 +129,8 @@ jobs:
93129
# the subsequent merge job will assemble the manifest list and apply tags
94130
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
95131
tags: |
96-
electricsql/electric
97-
electricsql/electric-canary
132+
${{ env.DOCKERHUB_REPO }}
133+
${{ env.DOCKERHUB_CANARY_REPO }}
98134
99135
# Save the digest so the merge job can find both platform images
100136
- name: Export digest
@@ -126,39 +162,38 @@ jobs:
126162

127163
- name: Derive image tags from the GitHub Actions event
128164
run: |
129-
case ${{ github.event_name }} in
130-
push)
131-
# A regular push to the main branch triggers canary image publishing
132-
echo "ELECTRIC_TAGS=-t electricsql/electric:canary" >> $GITHUB_ENV
133-
echo "ELECTRIC_CANARY_TAGS=-t electricsql/electric-canary:latest -t electricsql/electric-canary:${{ needs.derive_build_vars.outputs.short_commit_sha }}" >> $GITHUB_ENV
134-
;;
135-
release | workflow_dispatch)
136-
# A release triggers official release image publishing
137-
echo "ELECTRIC_TAGS=-t electricsql/electric:latest -t electricsql/electric:${{ needs.derive_build_vars.outputs.electric_version }}" >> $GITHUB_ENV
138-
esac
165+
if [ "${{ needs.derive_build_vars.outputs.is_release }}" = "true" ]; then
166+
# A release triggers official release image publishing
167+
echo "ELECTRIC_TAGS=-t $DOCKERHUB_REPO:latest -t $DOCKERHUB_REPO:${{ needs.derive_build_vars.outputs.electric_version }}" >> $GITHUB_ENV
168+
echo "ELECTRIC_CANARY_TAGS=" >> $GITHUB_ENV
169+
else
170+
# A regular push to the main branch triggers canary image publishing
171+
echo "ELECTRIC_TAGS=-t $DOCKERHUB_REPO:canary" >> $GITHUB_ENV
172+
echo "ELECTRIC_CANARY_TAGS=-t $DOCKERHUB_CANARY_REPO:latest -t $DOCKERHUB_CANARY_REPO:${{ needs.derive_build_vars.outputs.short_commit_sha }}" >> $GITHUB_ENV
173+
fi
139174
140175
- name: Create multi-arch manifest list
141176
run: |
142177
set -euo pipefail
143178
144-
# Build a list of electricsql/electric@sha256:... source images
179+
# Build a list of $DOCKERHUB_REPO@sha256:... source images
145180
ELECTRIC_IMAGES=$(
146181
for f in /tmp/digests/*.digest; do
147-
echo electricsql/electric@$(cat $f)
182+
echo $DOCKERHUB_REPO@$(cat $f)
148183
done
149184
)
150185
151-
# Create a manifest list for electricsql/electric:canary that includes both platforms
186+
# Create a manifest list for $DOCKERHUB_REPO:canary that includes both platforms
152187
docker buildx imagetools create $ELECTRIC_TAGS $ELECTRIC_IMAGES
153188
154189
if [ -n "$ELECTRIC_CANARY_TAGS" ]; then
155-
# Build a list of electricsql/electric-canary@sha256:... source images
190+
# Build a list of $DOCKERHUB_CANARY_REPO@sha256:... source images
156191
ELECTRIC_CANARY_IMAGES=$(
157192
for f in /tmp/digests/*.digest; do
158-
echo electricsql/electric-canary@$(cat $f)
193+
echo $DOCKERHUB_CANARY_REPO@$(cat $f)
159194
done
160195
)
161196
162-
# Create a manifest list for electricsql/electric-canary:... that includes both platforms
197+
# Create a manifest list for $DOCKERHUB_CANARY_REPO:... that includes both platforms
163198
docker buildx imagetools create $ELECTRIC_CANARY_TAGS $ELECTRIC_CANARY_IMAGES
164199
fi

0 commit comments

Comments
 (0)