forked from GreptimeTeam/greptimedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: refine release-cn-artifacts action (GreptimeTeam#2600)
* ci: add copy-image.sh and upload-artifacts-to-s3.sh * ci: remove unused options in dev build * ci: use 'upload-artifacts-to-s3.sh' and 'copy-image.sh' in release-cn-artifacts action * refactor: refine copy-image.sh
- Loading branch information
Showing
6 changed files
with
236 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
SRC_IMAGE=$1 | ||
DST_REGISTRY=$2 | ||
SKOPEO_STABLE_IMAGE="quay.io/skopeo/stable:latest" | ||
|
||
# Check if necessary variables are set. | ||
function check_vars() { | ||
for var in DST_REGISTRY_USERNAME DST_REGISTRY_PASSWORD DST_REGISTRY SRC_IMAGE; do | ||
if [ -z "${!var}" ]; then | ||
echo "$var is not set or empty." | ||
echo "Usage: DST_REGISTRY_USERNAME=<your-dst-registry-username> DST_REGISTRY_PASSWORD=<your-dst-registry-password> $0 <dst-registry> <src-image>" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Copies images from DockerHub to the destination registry. | ||
function copy_images_from_dockerhub() { | ||
# Check if docker is installed. | ||
if ! command -v docker &> /dev/null; then | ||
echo "docker is not installed. Please install docker to continue." | ||
exit 1 | ||
fi | ||
|
||
# Extract the name and tag of the source image. | ||
IMAGE_NAME=$(echo "$SRC_IMAGE" | sed "s/.*\///") | ||
|
||
echo "Copying $SRC_IMAGE to $DST_REGISTRY/$IMAGE_NAME" | ||
|
||
docker run "$SKOPEO_STABLE_IMAGE" copy -a docker://"$SRC_IMAGE" \ | ||
--dest-creds "$DST_REGISTRY_USERNAME":"$DST_REGISTRY_PASSWORD" \ | ||
docker://"$DST_REGISTRY/$IMAGE_NAME" | ||
} | ||
|
||
function main() { | ||
check_vars | ||
copy_images_from_dockerhub | ||
} | ||
|
||
# Usage example: | ||
# DST_REGISTRY_USERNAME=123 DST_REGISTRY_PASSWORD=456 \ | ||
# ./copy-image.sh greptime/greptimedb:v0.4.0 greptime-registry.cn-hangzhou.cr.aliyuncs.com | ||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
ARTIFACTS_DIR=$1 | ||
VERSION=$2 | ||
AWS_S3_BUCKET=$3 | ||
RELEASE_DIRS="releases/greptimedb" | ||
GREPTIMEDB_REPO="GreptimeTeam/greptimedb" | ||
|
||
# Check if necessary variables are set. | ||
function check_vars() { | ||
for var in AWS_S3_BUCKET VERSION ARTIFACTS_DIR; do | ||
if [ -z "${!var}" ]; then | ||
echo "$var is not set or empty." | ||
echo "Usage: $0 <artifacts-dir> <version> <aws-s3-bucket>" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Uploads artifacts to AWS S3 bucket. | ||
function upload_artifacts() { | ||
# The bucket layout will be: | ||
# releases/greptimedb | ||
# ├── latest-version.txt | ||
# ├── latest-nightly-version.txt | ||
# ├── v0.1.0 | ||
# │ ├── greptime-darwin-amd64-pyo3-v0.1.0.sha256sum | ||
# │ └── greptime-darwin-amd64-pyo3-v0.1.0.tar.gz | ||
# └── v0.2.0 | ||
# ├── greptime-darwin-amd64-pyo3-v0.2.0.sha256sum | ||
# └── greptime-darwin-amd64-pyo3-v0.2.0.tar.gz | ||
find "$ARTIFACTS_DIR" -type f \( -name "*.tar.gz" -o -name "*.sha256sum" \) | while IFS= read -r file; do | ||
aws s3 cp \ | ||
"$file" "s3://$AWS_S3_BUCKET/$RELEASE_DIRS/$VERSION/$(basename "$file")" | ||
done | ||
} | ||
|
||
# Updates the latest version information in AWS S3 if UPDATE_VERSION_INFO is true. | ||
function update_version_info() { | ||
if [ "$UPDATE_VERSION_INFO" == "true" ]; then | ||
# If it's the officail release(like v1.0.0, v1.0.1, v1.0.2, etc.), update latest-version.txt. | ||
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "Updating latest-version.txt" | ||
echo "$VERSION" > latest-version.txt | ||
aws s3 cp \ | ||
latest-version.txt "s3://$AWS_S3_BUCKET/$RELEASE_DIRS/latest-version.txt" | ||
fi | ||
|
||
# If it's the nightly release, update latest-nightly-version.txt. | ||
if [[ "$VERSION" == *"nightly"* ]]; then | ||
echo "Updating latest-nightly-version.txt" | ||
echo "$VERSION" > latest-nightly-version.txt | ||
aws s3 cp \ | ||
latest-nightly-version.txt "s3://$AWS_S3_BUCKET/$RELEASE_DIRS/latest-nightly-version.txt" | ||
fi | ||
fi | ||
} | ||
|
||
# Downloads artifacts from Github if DOWNLOAD_ARTIFACTS_FROM_GITHUB is true. | ||
function download_artifacts_from_github() { | ||
if [ "$DOWNLOAD_ARTIFACTS_FROM_GITHUB" == "true" ]; then | ||
# Check if jq is installed. | ||
if ! command -v jq &> /dev/null; then | ||
echo "jq is not installed. Please install jq to continue." | ||
exit 1 | ||
fi | ||
|
||
# Get the latest release API response. | ||
RELEASES_API_RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/$GREPTIMEDB_REPO/releases/latest") | ||
|
||
# Extract download URLs for the artifacts. | ||
# Exclude source code archives which are typically named as 'greptimedb-<version>.zip' or 'greptimedb-<version>.tar.gz'. | ||
ASSET_URLS=$(echo "$RELEASES_API_RESPONSE" | jq -r '.assets[] | select(.name | test("greptimedb-.*\\.(zip|tar\\.gz)$") | not) | .browser_download_url') | ||
|
||
# Download each asset. | ||
while IFS= read -r url; do | ||
if [ -n "$url" ]; then | ||
curl -LJO "$url" | ||
echo "Downloaded: $url" | ||
fi | ||
done <<< "$ASSET_URLS" | ||
fi | ||
} | ||
|
||
function main() { | ||
check_vars | ||
download_artifacts_from_github | ||
upload_artifacts | ||
update_version_info | ||
} | ||
|
||
# Usage example: | ||
# AWS_ACCESS_KEY_ID=<your_access_key_id> \ | ||
# AWS_SECRET_ACCESS_KEY=<your_secret_access_key> \ | ||
# AWS_DEFAULT_REGION=<your_region> \ | ||
# UPDATE_VERSION_INFO=true \ | ||
# DOWNLOAD_ARTIFACTS_FROM_GITHUB=false \ | ||
# ./upload-artifacts-to-s3.sh <artifacts-dir> <version> <aws-s3-bucket> | ||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.