-
Notifications
You must be signed in to change notification settings - Fork 1.3k
206 lines (175 loc) · 7.48 KB
/
Copy pathdocker-dev-release.yml
File metadata and controls
206 lines (175 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Development Docker Build
# Note: do not add a GitHub Actions cache (type=gha) here when running in the
# dragonflydb/dragonfly repo: the shared 10 GB cache is limited and better used
# by the far more frequent CI builds. This runs only on a daily schedule.
on:
schedule:
- cron: '15 0 * * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
image: ghcr.io/dragonflydb/dragonfly-dev
GCS_IMAGE: us-central1-docker.pkg.dev/dragonflydb-public/dragonfly-registry/dragonfly-dev
jobs:
build_and_tag:
if: github.repository == 'dragonflydb/dragonfly'
name: Build and Push ${{matrix.flavor}} ${{ matrix.os.arch }} image
strategy:
matrix:
flavor: [alpine,ubuntu,distroless]
os:
- image: ubuntu-24.04
arch: amd64
- image: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.os.image }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: checkout
uses: actions/checkout@v7
with:
fetch-depth: 1
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Registries
uses: ./.github/actions/multi-registry-docker-login
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Configure AWS Credentials
if: github.repository_owner == 'dragonflydb' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_CI_S3_ROLE_ARN }}
aws-region: us-east-1
- name: Get Build Information
id: build_info
run: |
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Docker meta
id: metadata
uses: docker/metadata-action@v6
with:
images: |
${{ env.image }}
${{ env.GCS_IMAGE }}
tags: |
type=sha,enable=true,prefix=${{ matrix.flavor}}-,suffix=-${{ matrix.os.arch }},format=short
labels: |
org.opencontainers.image.vendor=DragonflyDB LTD
org.opencontainers.image.title=Dragonfly Development Image
org.opencontainers.image.description=The fastest in-memory store
- name: Build image
id: build
uses: docker/build-push-action@v7
with:
context: .
push: true
provenance: false # Prevent pushing a docker manifest
tags: |
${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
file: tools/packaging/Dockerfile.${{ matrix.flavor }}-dev
load: true # Load the build images into the local docker.
- name: Test Image
run: |
echo ${{ steps.build.outputs.digest }}
image_tags=(${{ steps.metadata.outputs.tags }})
# install redis-tools
sudo apt-get update && sudo apt-get install redis-tools -y
for image_tag in "${image_tags[@]}"; do
echo "Testing image: ${image_tag}"
docker image inspect ${image_tag}
echo "Testing ${{ matrix.flavor }} image"
# docker run with port-forwarding
docker run -d -p 6379:6379 ${image_tag}
sleep 5
redis-cli -h localhost ping | grep -q "PONG" || exit 1
docker stop $(docker ps -q --filter ancestor=${image_tag})
done
- name: Extract and Upload Binaries
if: matrix.flavor == 'ubuntu' # Only run once per flavor
run: |
# Get the image tag
image_tags=(${{ steps.metadata.outputs.tags }})
image_tag=${image_tags[0]}
# Extract version from the image
echo "Extracting version from image..."
VERSION=$(docker run --rm ${image_tag} dragonfly --version | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" | head -n1 | cut -d' ' -f2 | cut -d'-' -f1)
# Check if version starts with a release version (v*.*.*)
if [[ ! $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
# Get the latest release version to use as prefix
LATEST_RELEASE=$(curl -s https://api.github.com/repos/dragonflydb/dragonfly/releases/latest | jq -r .tag_name)
VERSION="${LATEST_RELEASE}+${VERSION}"
fi
echo "Dragonfly version: $VERSION"
echo "Extracting binary from ${image_tag} for ${{ matrix.os.arch }}"
# Create a temporary container and copy the binary
container_id=$(docker create ${image_tag})
docker cp ${container_id}:/usr/local/bin/dragonfly ./dragonfly
docker rm ${container_id}
# Create a tar archive
if [[ "${{ matrix.os.arch }}" == "arm64" ]]; then
arch_name="aarch64"
else
arch_name="x86_64"
fi
tar_name="dragonfly-${arch_name}-dbgsym.tar.gz"
tar czf ${tar_name} dragonfly
# Upload to GCS
echo "Uploading ${tar_name} to GCS"
gcloud storage cp "$tar_name" "gs://${{ secrets.STAGING_BINARY_BUCKET }}/dragonfly/$VERSION/$tar_name"
# Upload to AWS
echo "Uploading ${tar_name} to AWS"
aws s3 cp "$tar_name" "s3://${{ secrets.STAGING_BINARY_BUCKET }}/dragonfly/$VERSION/$tar_name"
# Cleanup
rm -f dragonfly ${tar_name}
outputs:
# matrix jobs outputs override each other, but we use the same sha
# for all images, so we can use the same output name.
sha: ${{ steps.build_info.outputs.short_sha }}
merge_manifest:
if: github.repository == 'dragonflydb/dragonfly'
needs: [build_and_tag]
runs-on: ubuntu-latest
strategy:
matrix:
flavor: [alpine,ubuntu,distroless]
steps:
- name: checkout
uses: actions/checkout@v7
- name: Login to Registries
uses: ./.github/actions/multi-registry-docker-login
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
- name: Merge and Push
run: |
# Function to create and push manifests for a given registry
create_and_push_manifests() {
local registry=$1
local flavor=$2
local sha=$3
# Create and push the manifest like dragonfly-dev:alpine-<sha>
local sha_tag="${registry}:${flavor}-${sha}"
docker manifest create ${sha_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
docker manifest push ${sha_tag}
# Create and push the manifest like dragonfly-dev:alpine
local flavor_tag="${registry}:${flavor}"
docker manifest create ${flavor_tag} --amend ${sha_tag}-amd64 --amend ${sha_tag}-arm64
docker manifest push ${flavor_tag}
}
# GitHub Container Registry manifests
create_and_push_manifests "${{ env.image }}" "${{ matrix.flavor }}" "${{ needs.build_and_tag.outputs.sha }}"
# Google Artifact Registry manifests
create_and_push_manifests "${{ env.GCS_IMAGE }}" "${{ matrix.flavor }}" "${{ needs.build_and_tag.outputs.sha }}"