From 426ed0b1a4ea58d7e1f35ef55d3a2a67a233b2cc Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Mon, 19 Feb 2024 23:58:48 +0900 Subject: [PATCH 01/11] Added workflow to update Red Hat Container Catalog --- .github/scripts/rhel_description.py | 31 +++++++++++++++++++ .../workflows/rhel_registry_description.yml | 29 +++++++---------- 2 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 .github/scripts/rhel_description.py diff --git a/.github/scripts/rhel_description.py b/.github/scripts/rhel_description.py new file mode 100644 index 000000000..124b91343 --- /dev/null +++ b/.github/scripts/rhel_description.py @@ -0,0 +1,31 @@ +import sys +import requests +import json +import markdown +import os + +repository_description = '' + +if ("DESCRIPTION_FILE" not in os.environ): + print("Description file environment variable is not specified") + sys.exit(1) + +if (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.md')): + repository_description=markdown.markdownFromFile(input=os.environ["DESCRIPTION_FILE"] + '.md') +elif (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.html')): + file = open(os.environ["DESCRIPTION_FILE"] + '.html', mode='r') + repository_description = file.read() + file.close() + +if (len(repository_description)) == 0: + print("No description") + sys.exit(1) + +data = dict() +data['container'] = dict() +data['container']['repository_description'] = repository_description[:32768] + +headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} +result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) +print(result) +print(json.loads(r.content)['last_update_date']) \ No newline at end of file diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 62f9c6552..e84406bf5 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -69,6 +69,7 @@ jobs: echo "::group::Branch metadata" echo "secret_prefix=RHEL_${github_ref//.}" echo "::endgroup::" + github_ref="64" echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT @@ -108,26 +109,20 @@ jobs: echo "::endgroup::" echo "matrix_build=${MATRIX_BUILD}" >> $GITHUB_OUTPUT + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: install python packages + run: | + python -m pip install --upgrade pip + pip install markdown + - name: Update Red Hat project description (zabbix-${{ matrix.component }}) env: - DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README.html', env.DOCKERFILES_DIRECTORY, matrix.build) }} + DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README', env.DOCKERFILES_DIRECTORY, matrix.build) }} PROJECT_ID: ${{ secrets[format('{0}_{1}_PROJECT', steps.branch_info.outputs.secret_prefix, steps.var_format.outputs.matrix_build)] }} PYXIS_API_TOKEN: ${{ secrets.REDHAT_API_TOKEN }} API_URL: ${{ env.API_URL }} - run: | - import requests - import json - import os + run: python ./github/scripts/rhel_description.py - file = open(os.environ["DESCRIPTION_FILE"],mode='r') - repository_description = file.read() - file.close() - - data = dict() - data['container'] = dict() - data['container']['repository_description'] = repository_description[:32768] - - headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} - result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) - print(result) - print(json.loads(r.content)['last_update_date']) From 6951f6b840d6fd6823645a12ff28d90f8eeb4653 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:19:49 +0900 Subject: [PATCH 02/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index e84406bf5..2dde1e07a 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -124,5 +124,5 @@ jobs: PROJECT_ID: ${{ secrets[format('{0}_{1}_PROJECT', steps.branch_info.outputs.secret_prefix, steps.var_format.outputs.matrix_build)] }} PYXIS_API_TOKEN: ${{ secrets.REDHAT_API_TOKEN }} API_URL: ${{ env.API_URL }} - run: python ./github/scripts/rhel_description.py + run: python ./.github/scripts/rhel_description.py From e6bc802e1e406478a6e7720a4870b8f4ed1d06ff Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:30:31 +0900 Subject: [PATCH 03/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 2dde1e07a..4bc294d70 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -116,7 +116,7 @@ jobs: - name: install python packages run: | python -m pip install --upgrade pip - pip install markdown + pip install markdown requests - name: Update Red Hat project description (zabbix-${{ matrix.component }}) env: From 924691eb4806e6184e411404ab0b7671613b9314 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:32:42 +0900 Subject: [PATCH 04/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 4bc294d70..81291a03a 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -120,7 +120,7 @@ jobs: - name: Update Red Hat project description (zabbix-${{ matrix.component }}) env: - DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README', env.DOCKERFILES_DIRECTORY, matrix.build) }} + DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README', env.DOCKERFILES_DIRECTORY, matrix.component) }} PROJECT_ID: ${{ secrets[format('{0}_{1}_PROJECT', steps.branch_info.outputs.secret_prefix, steps.var_format.outputs.matrix_build)] }} PYXIS_API_TOKEN: ${{ secrets.REDHAT_API_TOKEN }} API_URL: ${{ env.API_URL }} From d70750efb653eb296f411d3bd220d8dfbffdee46 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:42:03 +0900 Subject: [PATCH 05/11] Added workflow to update Red Hat Container Catalog --- .github/scripts/rhel_description.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/scripts/rhel_description.py b/.github/scripts/rhel_description.py index 124b91343..6165d7efb 100644 --- a/.github/scripts/rhel_description.py +++ b/.github/scripts/rhel_description.py @@ -4,20 +4,32 @@ import json import markdown import os -repository_description = '' +repository_description = None if ("DESCRIPTION_FILE" not in os.environ): print("Description file environment variable is not specified") sys.exit(1) +if ("PYXIS_API_TOKEN" not in os.environ): + print("API token environment variable is not specified") + sys.exit(1) +if ("API_URL" not in os.environ): + print("API URL environment variable is not specified") + sys.exit(1) +if ("PROJECT_ID" not in os.environ): + print("RedHat project ID environment variable is not specified") + sys.exit(1) if (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.md')): - repository_description=markdown.markdownFromFile(input=os.environ["DESCRIPTION_FILE"] + '.md') + file = open(os.environ["DESCRIPTION_FILE"] + '.md', mode='r') + markdown_data = file.read() + file.close() + repository_description=markdown.markdown(markdown_data) elif (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.html')): file = open(os.environ["DESCRIPTION_FILE"] + '.html', mode='r') repository_description = file.read() file.close() -if (len(repository_description)) == 0: +if (repository_description is None or len(repository_description) == 0): print("No description") sys.exit(1) @@ -28,4 +40,4 @@ data['container']['repository_description'] = repository_description[:32768] headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) print(result) -print(json.loads(r.content)['last_update_date']) \ No newline at end of file +print(json.loads(r.content)['last_update_date']) From 130c2f1a3e8bf7d7f086e03f3dcb1f5400dcff83 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:43:05 +0900 Subject: [PATCH 06/11] Added workflow to update Red Hat Container Catalog --- .github/scripts/rhel_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/rhel_description.py b/.github/scripts/rhel_description.py index 6165d7efb..26c40b8a2 100644 --- a/.github/scripts/rhel_description.py +++ b/.github/scripts/rhel_description.py @@ -40,4 +40,4 @@ data['container']['repository_description'] = repository_description[:32768] headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) print(result) -print(json.loads(r.content)['last_update_date']) +print(json.loads(result.content)['last_update_date']) From 3dec5564210485c24d4c48b61377e078bd95a7c1 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:45:50 +0900 Subject: [PATCH 07/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 81291a03a..f3461f08e 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -69,9 +69,9 @@ jobs: echo "::group::Branch metadata" echo "secret_prefix=RHEL_${github_ref//.}" echo "::endgroup::" - github_ref="64" - echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT + #echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT + echo "secret_prefix=RHEL_64" >> $GITHUB_OUTPUT - name: Check ${{ env.MATRIX_FILE }} file id: build_exists From 7d3c32db6f33dc2e57ed6f21ea3379f151a215ab Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:49:04 +0900 Subject: [PATCH 08/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index f3461f08e..f17e5f482 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -70,8 +70,8 @@ jobs: echo "secret_prefix=RHEL_${github_ref//.}" echo "::endgroup::" - #echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT - echo "secret_prefix=RHEL_64" >> $GITHUB_OUTPUT + echo "zabbix_release=64" >> $GITHUB_OUTPUT + echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT - name: Check ${{ env.MATRIX_FILE }} file id: build_exists @@ -99,7 +99,7 @@ jobs: - name: Variables formating id: var_format env: - MATRIX_BUILD: ${{ matrix.build }} + MATRIX_BUILD: ${{ matrix.component }} run: | MATRIX_BUILD=${MATRIX_BUILD^^} MATRIX_BUILD=${MATRIX_BUILD//-/_} @@ -118,7 +118,7 @@ jobs: python -m pip install --upgrade pip pip install markdown requests - - name: Update Red Hat project description (zabbix-${{ matrix.component }}) + - name: Update Red Hat project description (${{ matrix.component }}-${{ steps.branch_info.outputs.zabbix_release }}) env: DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README', env.DOCKERFILES_DIRECTORY, matrix.component) }} PROJECT_ID: ${{ secrets[format('{0}_{1}_PROJECT', steps.branch_info.outputs.secret_prefix, steps.var_format.outputs.matrix_build)] }} From 85e5ea0c43662089eca647cd29bcff1e559acd81 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:51:54 +0900 Subject: [PATCH 09/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index f17e5f482..8305bdbf0 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -65,6 +65,7 @@ jobs: sha_short=$(git rev-parse --short HEAD) github_ref=${github_ref##*/} + github_ref="6.4" echo "::group::Branch metadata" echo "secret_prefix=RHEL_${github_ref//.}" From 33e3dfaf44f3dbcd60e8c3757b5e2d7c311736b0 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:58:59 +0900 Subject: [PATCH 10/11] Added workflow to update Red Hat Container Catalog --- .github/scripts/rhel_description.py | 19 ++++++++++++------- .../workflows/rhel_registry_description.yml | 3 +-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/scripts/rhel_description.py b/.github/scripts/rhel_description.py index 26c40b8a2..e16220020 100644 --- a/.github/scripts/rhel_description.py +++ b/.github/scripts/rhel_description.py @@ -6,16 +6,16 @@ import os repository_description = None -if ("DESCRIPTION_FILE" not in os.environ): +if ("DESCRIPTION_FILE" not in os.environ or len(os.environ["DESCRIPTION_FILE"]) == 0): print("Description file environment variable is not specified") sys.exit(1) -if ("PYXIS_API_TOKEN" not in os.environ): +if ("PYXIS_API_TOKEN" not in os.environ or len(os.environ["PYXIS_API_TOKEN"]) == 0): print("API token environment variable is not specified") sys.exit(1) -if ("API_URL" not in os.environ): +if ("API_URL" not in os.environ or len(os.environ["API_URL"]) == 0): print("API URL environment variable is not specified") sys.exit(1) -if ("PROJECT_ID" not in os.environ): +if ("PROJECT_ID" not in os.environ or len(os.environ["PROJECT_ID"]) == 0): print("RedHat project ID environment variable is not specified") sys.exit(1) @@ -38,6 +38,11 @@ data['container'] = dict() data['container']['repository_description'] = repository_description[:32768] headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} -result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) -print(result) -print(json.loads(result.content)['last_update_date']) +result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], + headers = headers, + data = json.dumps(data)) + +print("::group::Result") +print("Response code: " + result) +print("Last update date: " + json.loads(result.content)['last_update_date']) +print("::endgroup::") diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 8305bdbf0..5ece50a38 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -65,13 +65,12 @@ jobs: sha_short=$(git rev-parse --short HEAD) github_ref=${github_ref##*/} - github_ref="6.4" echo "::group::Branch metadata" echo "secret_prefix=RHEL_${github_ref//.}" echo "::endgroup::" - echo "zabbix_release=64" >> $GITHUB_OUTPUT + echo "zabbix_release=${github_ref//.}" >> $GITHUB_OUTPUT echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT - name: Check ${{ env.MATRIX_FILE }} file From 6fe3e4c6d85a44c0efe9bba28f85421d63e9d28e Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 01:00:38 +0900 Subject: [PATCH 11/11] Added workflow to update Red Hat Container Catalog --- .github/workflows/rhel_registry_description.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rhel_registry_description.yml b/.github/workflows/rhel_registry_description.yml index 5ece50a38..6fe0af902 100644 --- a/.github/workflows/rhel_registry_description.yml +++ b/.github/workflows/rhel_registry_description.yml @@ -3,9 +3,10 @@ name: Red Hat Catalog Description on: push: branches: - - 'trunk' + - '[0-9]+.[0-9]+' paths: - 'Dockerfiles/*/*/README.html' + - 'Dockerfiles/*/*/README.md' - '.github/workflows/rhel_registry_description.yml' workflow_dispatch: