Skip to content

Commit 30ce734

Browse files
authored
feat(docker): push dragonfly image to gcp artifact registry (#4716)
* feat(docker): push dragonfly image to gcp aritfact registry --------- Signed-off-by: Abhradeep Chakraborty <[email protected]>
1 parent 2a3a156 commit 30ce734

File tree

3 files changed

+128
-67
lines changed

3 files changed

+128
-67
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Multi-Registry Docker Login'
2+
description: 'Authenticate with both GHCR and Google Artifact Registry'
3+
inputs:
4+
GITHUB_TOKEN:
5+
description: 'GitHub token for GHCR'
6+
required: true
7+
GCP_SA_KEY:
8+
description: 'Google Service Account JSON key'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Login to GHCR
15+
uses: docker/login-action@v3
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.repository_owner }}
19+
password: ${{ inputs.GITHUB_TOKEN }}
20+
21+
- name: Login to Google Artifact Registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: us-central1-docker.pkg.dev
25+
username: _json_key
26+
password: ${{ inputs.GCP_SA_KEY }}

.github/workflows/docker-dev-release.yml

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ on:
55
- cron: '15 0 * * *'
66
workflow_dispatch:
77

8-
98
concurrency:
109
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1110
cancel-in-progress: true
1211

1312
env:
1413
image: ghcr.io/dragonflydb/dragonfly-dev
14+
GCS_IMAGE: us-central1-docker.pkg.dev/dragonflydb-public/dragonfly-registry/dragonfly-dev
1515

1616
jobs:
1717
build_and_tag:
@@ -36,14 +36,16 @@ jobs:
3636
with:
3737
fetch-depth: 1
3838
submodules: true
39+
3940
- name: Set up Docker Buildx
4041
uses: docker/setup-buildx-action@v3
41-
- name: Login to GitHub Container Registry
42-
uses: docker/login-action@v3
42+
43+
- name: Login to Registries
44+
uses: ./.github/actions/multi-registry-docker-login
4345
with:
44-
registry: ghcr.io
45-
username: ${{ github.repository_owner }}
46-
password: ${{ secrets.GITHUB_TOKEN }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
48+
4749
- name: Get Build Information
4850
id: build_info
4951
run: |
@@ -55,8 +57,9 @@ jobs:
5557
with:
5658
images: |
5759
${{ env.image }}
60+
${{ env.GCS_IMAGE }}
5861
tags: |
59-
type=sha,enable=true,prefix=${{ matrix.flavor}}-,suffix=-${{ matrix.os.arch }},format=short
62+
type=sha,enable=true,prefix=${{ matrix.flavor}}-,suffix=-${{ matrix.os.arch }},format=short
6063
labels: |
6164
org.opencontainers.image.vendor=DragonflyDB LTD
6265
org.opencontainers.image.title=Dragonfly Development Image
@@ -77,25 +80,23 @@ jobs:
7780
load: true # Load the build images into the local docker.
7881
- name: Test Image
7982
run: |
80-
image_tag=${{ steps.metadata.outputs.tags }}
8183
echo ${{ steps.build.outputs.digest }}
82-
image_digest=${{ env.image }}@${{ steps.build.outputs.digest }}
83-
84+
image_tags=(${{ steps.metadata.outputs.tags }})
85+
8486
# install redis-tools
8587
sudo apt-get install redis-tools -y
86-
87-
docker image inspect ${image_tag}
88-
echo "Testing ${{ matrix.flavor }} image"
89-
90-
# docker run with port-forwarding
91-
docker run -d -p 6379:6379 ${image_tag}
92-
sleep 5
93-
if [[ $(redis-cli -h localhost ping) != "PONG" ]]; then
94-
echo "Redis ping failed"
95-
exit 1
96-
fi
97-
echo "Redis ping succeeded"
98-
exit 0
88+
89+
for image_tag in "${image_tags[@]}"; do
90+
echo "Testing image: ${image_tag}"
91+
docker image inspect ${image_tag}
92+
echo "Testing ${{ matrix.flavor }} image"
93+
94+
# docker run with port-forwarding
95+
docker run -d -p 6379:6379 ${image_tag}
96+
sleep 5
97+
redis-cli -h localhost ping | grep -q "PONG" || exit 1
98+
docker stop $(docker ps -q --filter ancestor=${image_tag})
99+
done
99100
100101
outputs:
101102
# matrix jobs outputs override each other, but we use the same sha
@@ -109,23 +110,36 @@ jobs:
109110
matrix:
110111
flavor: [alpine,ubuntu]
111112
steps:
112-
- name: Login to GitHub Container Registry
113-
uses: docker/login-action@v3
113+
- name: checkout
114+
uses: actions/checkout@v4
115+
116+
- name: Login to Registries
117+
uses: ./.github/actions/multi-registry-docker-login
114118
with:
115-
registry: ghcr.io
116-
username: ${{ github.repository_owner }}
117-
password: ${{ secrets.GITHUB_TOKEN }}
118-
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
121+
119122
- name: Merge and Push
120123
run: |
121-
flavor_tag=${{ env.image }}:${{matrix.flavor}}
122-
sha_tag=${flavor_tag}-${{ needs.build_and_tag.outputs.sha }}
123-
124-
# Create and push the manifest like dragonfly-dev:alpine-<sha>
125-
docker manifest create ${sha_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
126-
docker manifest push ${sha_tag}
127-
128-
# Create and push the manifest like dragonfly-dev:alpine
129-
docker manifest create ${flavor_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
130-
docker manifest push ${flavor_tag}
131-
124+
# Function to create and push manifests for a given registry
125+
create_and_push_manifests() {
126+
local registry=$1
127+
local flavor=$2
128+
local sha=$3
129+
130+
# Create and push the manifest like dragonfly-dev:alpine-<sha>
131+
local sha_tag="${registry}:${flavor}-${sha}"
132+
docker manifest create ${sha_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
133+
docker manifest push ${sha_tag}
134+
135+
# Create and push the manifest like dragonfly-dev:alpine
136+
local flavor_tag="${registry}:${flavor}"
137+
docker manifest create ${flavor_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
138+
docker manifest push ${flavor_tag}
139+
}
140+
141+
# GitHub Container Registry manifests
142+
create_and_push_manifests "${{ env.image }}" "${{ matrix.flavor }}" "${{ needs.build_and_tag.outputs.sha }}"
143+
144+
# Google Artifact Registry manifests
145+
create_and_push_manifests "${{ env.GCS_IMAGE }}" "${{ matrix.flavor }}" "${{ needs.build_and_tag.outputs.sha }}"

.github/workflows/docker-release2.yml

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
2323
IS_PRERELEASE: ${{ github.event.release.prerelease || github.event.inputs.PRERELEASE }}
2424
IMAGE: ghcr.io/dragonflydb/dragonfly
25+
GCS_IMAGE: us-central1-docker.pkg.dev/dragonflydb-public/dragonfly-registry/dragonfly
2526

2627
jobs:
2728
build_and_tag:
@@ -49,12 +50,12 @@ jobs:
4950
submodules: true
5051
- name: Set up Docker Build
5152
uses: docker/setup-buildx-action@v3
52-
- name: Login to GitHub Container Registry
53-
uses: docker/login-action@v3
53+
54+
- name: Login to Registries
55+
uses: ./.github/actions/multi-registry-docker-login
5456
with:
55-
registry: ghcr.io
56-
username: ${{ github.repository_owner }}
57-
password: ${{ secrets.GITHUB_TOKEN }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
5859

5960
- name: Fetch release asset
6061
uses: dsaltares/[email protected]
@@ -80,6 +81,7 @@ jobs:
8081
with:
8182
images: |
8283
${{ env.IMAGE }}
84+
${{ env.GCS_IMAGE }}
8385
flavor: |
8486
latest=false
8587
prefix=${{ matrix.flavor}}-
@@ -129,35 +131,54 @@ jobs:
129131
matrix:
130132
flavor: [ubuntu]
131133
steps:
132-
- name: Login to GitHub Container Registry
133-
uses: docker/login-action@v3
134+
- name: checkout
135+
uses: actions/checkout@v4
136+
137+
- name: Login to Registries
138+
uses: ./.github/actions/multi-registry-docker-login
134139
with:
135-
registry: ghcr.io
136-
username: ${{ github.repository_owner }}
137-
password: ${{ secrets.GITHUB_TOKEN }}
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
138142

139143
- name: Merge and Push
140144
run: |
141-
sha_amd=${{ env.IMAGE }}@${{ needs.build_and_tag.outputs.sha_amd }}
142-
sha_arm=${{ env.IMAGE }}@${{ needs.build_and_tag.outputs.sha_arm }}
143-
echo "shas: $sha_amd $sha_arm"
144-
145-
if [[ "${{ env.IS_PRERELEASE }}" == 'true' ]]; then
146-
# Create and push the manifest like dragonfly:alpha-ubuntu
147-
tag="${{ env.IMAGE }}:alpha-${{ matrix.flavor }}"
145+
# Function to create and push manifests for a given registry
146+
create_and_push_manifests() {
147+
local registry=$1
148+
local sha_amd=$2
149+
local sha_arm=$3
150+
local flavor=$4
151+
local tag_name=$5
152+
local is_prerelease=$6
153+
154+
if [[ "$is_prerelease" == 'true' ]]; then
155+
# Create and push the manifest like dragonfly:alpha-ubuntu
156+
tag="${registry}:alpha-${flavor}"
157+
docker manifest create ${tag} --amend ${sha_amd} --amend ${sha_arm}
158+
docker manifest push ${tag}
159+
elif [[ "$flavor" == 'ubuntu' ]]; then
160+
tag="${registry}:latest"
161+
# Create and push the manifest like dragonfly:latest
162+
docker manifest create ${tag} --amend ${sha_amd} --amend ${sha_arm}
163+
docker manifest push ${tag}
164+
fi
165+
166+
# Create and push the manifest like dragonfly:v1.26.4
167+
tag="${registry}:${tag_name}"
148168
docker manifest create ${tag} --amend ${sha_amd} --amend ${sha_arm}
149169
docker manifest push ${tag}
150-
elif [[ "${{matrix.flavor}}" == 'ubuntu' ]]; then
151-
tag="${{ env.IMAGE }}:latest"
152-
# Create and push the manifest like dragonfly:latest
153-
docker manifest create ${tag} --amend ${sha_amd} --amend ${sha_arm}
154-
docker manifest push ${tag}
155-
fi
170+
}
171+
172+
# GitHub Container Registry manifests
173+
ghcr_sha_amd=${{ env.IMAGE }}@${{ needs.build_and_tag.outputs.sha_amd }}
174+
ghcr_sha_arm=${{ env.IMAGE }}@${{ needs.build_and_tag.outputs.sha_arm }}
175+
create_and_push_manifests "${{ env.IMAGE }}" "$ghcr_sha_amd" "$ghcr_sha_arm" "${{ matrix.flavor }}" "${{ env.TAG_NAME }}" "${{ env.IS_PRERELEASE }}"
176+
177+
# Google Artifact Registry manifests
178+
gar_sha_amd=${{ env.GCS_IMAGE }}@${{ needs.build_and_tag.outputs.sha_amd }}
179+
gar_sha_arm=${{ env.GCS_IMAGE }}@${{ needs.build_and_tag.outputs.sha_arm }}
180+
create_and_push_manifests "${{ env.GCS_IMAGE }}" "$gar_sha_amd" "$gar_sha_arm" "${{ matrix.flavor }}" "${{ env.TAG_NAME }}" "${{ env.IS_PRERELEASE }}"
156181
157-
# Create and push the manifest like dragonfly:v1.26.4
158-
tag=${{ env.IMAGE }}:${{ env.TAG_NAME }}
159-
docker manifest create ${tag} --amend ${sha_amd} --amend ${sha_arm}
160-
docker manifest push ${tag}
161182
release_helm_and_notify:
162183
needs: [merge_manifest]
163184
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)