From e585ac612528627ceea53b25a5fbbf1d2394746f Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Mon, 25 Dec 2023 17:40:52 +0800 Subject: [PATCH] feat(packages): add meta data into the OCI artifacts The delivery jobs can utilize the meta data to publish TiUP packages, etc... Signed-off-by: wuhuizuo --- packages/packages.yaml.tmpl | 4 +-- .../scripts/build-package-artifacts.sh.tmpl | 26 ++++++++++++++++--- .../gen-package-artifacts-with-config.sh | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/packages.yaml.tmpl b/packages/packages.yaml.tmpl index 89cad07f..043d4ccf 100644 --- a/packages/packages.yaml.tmpl +++ b/packages/packages.yaml.tmpl @@ -428,7 +428,7 @@ components: src: path: bin/tidb-server tiup: - description: > + description: >- TiDB is an open source distributed HTAP database compatible with the MySQL protocol. entrypoint: tidb-server - name: "br-{{ .Release.version }}-{{ .Release.os }}-{{ .Release.arch }}.tar.gz" @@ -448,7 +448,7 @@ components: path: bin/dumpling tiup: entrypoint: dumpling - description: > + description: >- Dumpling is a CLI tool that helps you dump MySQL/TiDB data. - name: "tidb-lightning-ctl-{{ .Release.version }}-{{ .Release.os }}-{{ .Release.arch }}.tar.gz" files: diff --git a/packages/scripts/build-package-artifacts.sh.tmpl b/packages/scripts/build-package-artifacts.sh.tmpl index 49daa1ac..3d61e0de 100644 --- a/packages/scripts/build-package-artifacts.sh.tmpl +++ b/packages/scripts/build-package-artifacts.sh.tmpl @@ -33,7 +33,7 @@ function parse_arguments() { ;; o) result_path=${OPTARG} - ;; + ;; a) need_package=true ;; @@ -155,19 +155,39 @@ function archive() { } {{ if has .artifactory "package_repo" -}} +function prepare_artifact_config() { + local save_file="$1" + + :> "$save_file" + yq -p json -o json -i '.os = "{{ .os }}"' "$save_file" + yq -p json -o json -i '.architecture = "{{ .arch }}"' "$save_file" + yq -p json -o json -i '.profile = "{{ .profile }}"' "$save_file" + yq -p json -o json -i '.version = "{{ .version }}"' "$save_file" + yq -p json -o json -i '.tiup = []' "$save_file" + + {{- range (.artifacts | jq `map(select((.type == "file" or .type == null) and .tiup != null))`) }} + {{- with .tiup }} + yq -p json -o json -i '.tiup += {{ . | toJSON }}' "$save_file" + {{- end }} + yq -p json -o json -i '.tiup[-1].file = "{{ .name }}"' "$save_file" + {{- end }} +} + function push_files() { local release_ws="$1" local tag="{{ index .artifactory.tags 0 }}-{{ .profile }}_{{ .os }}_{{ .arch }}" local destination="{{ .artifactory.package_repo }}:$tag" + prepare_artifact_config "$release_ws/artifact-config.json" + # You should login before call this script, default it use credential with docker `config`` file: ~/.docker/config.json # Login steps: # local registry=$(echo "${destination}" | cut -d/ -f) # oras login -u ${ORAS_USER} -p ${ORAS_PASSWD} ${registry} pushd "$release_ws" - oras push --artifact-type application/gzip ${destination} + oras push --artifact-type application/gzip --config artifact-config.json ${destination} {{- range (.artifacts | jq `map(select(.type == "file" or .type == null))`) }}{{ printf " %s" .name }}{{- end }} {{- range (.artifacts | jq `map(select(.type == "file" or .type == null))`) }}{{ printf " %s.sha256" .name }}{{- end }} popd @@ -190,7 +210,7 @@ function write_push_results() { # local registry=$(echo "${destination}" | cut -d/ -f) # oras login -u ${ORAS_USER} -p ${ORAS_PASSWD} ${registry} digest="$(oras discover "${destination}" --distribution-spec v1.1-referrers-tag -o tree | cut -d@ -f2)" - + cat < "$result_file" oci: repo: {{ .artifactory.package_repo }} diff --git a/packages/scripts/gen-package-artifacts-with-config.sh b/packages/scripts/gen-package-artifacts-with-config.sh index a2e2a71c..c08e8395 100755 --- a/packages/scripts/gen-package-artifacts-with-config.sh +++ b/packages/scripts/gen-package-artifacts-with-config.sh @@ -52,6 +52,7 @@ function main() { yq -i ".os = \"$os\"" release-router.yaml yq -i ".arch = \"$arch\"" release-router.yaml yq -i ".profile = \"$profile\"" release-router.yaml + yq -i ".version = \"$version\"" release-router.yaml yq -i ".steps = .steps[.profile]" release-router.yaml yq -i ".steps = (.steps | map(select(.os == null or .os == \"$os\")))" release-router.yaml yq -i ".steps = (.steps | map(select(.arch == null or .arch == \"$arch\")))" release-router.yaml