Skip to content

Commit 41c1ab1

Browse files
authored
Merge pull request #254 from trz42/configurable_upload_directory
make upload directory in S3 bucket configurable
2 parents b03baa1 + 8b09bec commit 41c1ab1

5 files changed

Lines changed: 267 additions & 25 deletions

File tree

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,20 @@ submit_command = /usr/bin/sbatch
404404
```
405405
`submit_command` is the full path to the Slurm job submission command used for submitting batch jobs. You may want to verify if `sbatch` is provided at that path or determine its actual location (using `which sbatch`).
406406

407+
```
408+
build_permission = GH_ACCOUNT_1 GH_ACCOUNT_2 ...
409+
```
410+
`build_permission` defines which GitHub accounts have the permission to trigger
411+
build jobs, i.e., for which accounts the bot acts on `bot: build ...` commands.
412+
If the value is left empty, everyone can trigger build jobs.
413+
414+
```
415+
no_build_permission_comment = The `bot: build ...` command has been used by user `{build_labeler}`, but this person does not have permission to trigger builds.
416+
```
417+
`no_build_permission_comment` defines a comment (template) that is used when
418+
the account trying to trigger build jobs has no permission to do so.
419+
420+
407421
#### `[bot_control]` section
408422

409423
The `[bot_control]` section contains settings for configuring the feature to
@@ -485,6 +499,43 @@ This defines a message that is added to the status table in a PR comment
485499
corresponding to a job whose tarball should have been uploaded (e.g., after
486500
setting the `bot:deploy` label).
487501

502+
503+
```
504+
metadata_prefix = LOCATION_WHERE_METADATA_FILE_GETS_DEPOSITED
505+
tarball_prefix = LOCATION_WHERE_TARBALL_GETS_DEPOSITED
506+
```
507+
508+
These two settings are used to define where (which directory) in the S3 bucket
509+
(see `bucket_name` above) the metadata file and the tarball will be stored. The
510+
value `LOCATION...` can be a string value to always use the same 'prefix'
511+
regardless of the target CVMFS repository, or can be a mapping of a target
512+
repository id (see also `repo_target_map` below) to a prefix.
513+
514+
The prefix itself can use some (environment) variables that are set within
515+
the upload script (see `tarball_upload_script` above). Currently those are:
516+
* `'${github_repository}'` (which would be expanded to the full name of the GitHub
517+
repository, e.g., `EESSI/software-layer`),
518+
* `'${legacy_aws_path}'` (which expands to the legacy/old prefix being used for
519+
storing tarballs/metadata files, the old prefix is
520+
`EESSI_VERSION/TARBALL_TYPE/OS_TYPE/CPU_ARCHITECTURE/TIMESTAMP/`), _and_
521+
* `'${pull_request_number}'` (which would be expanded to the number of the pull
522+
request from which the tarball originates).
523+
Note, it's important to single-quote (`'`) the variables as shown above, because
524+
they may likely not be defined when the bot calls the upload script.
525+
526+
The list of supported variables can be shown by running
527+
`scripts/eessi-upload-to-staging --list-variables`.
528+
529+
**Examples:**
530+
```
531+
metadata_prefix = {"eessi.io-2023.06": "new/${github_repository}/${pull_request_number}"}
532+
tarball_prefix = {
533+
"eessi-pilot-2023.06": "",
534+
"eessi.io-2023.06": "new/${github_repository}/${pull_request_number}"
535+
}
536+
```
537+
If left empty, the old/legacy prefix is being used.
538+
488539
#### `[architecturetargets]` section
489540

490541
The section `[architecturetargets]` defines for which targets (OS/SUBDIR), (for example `linux/x86_64/amd/zen2`) the EESSI bot should submit jobs, and which additional `sbatch` parameters will be used for requesting a compute node with the CPU microarchitecture needed to build the software stack.
@@ -657,6 +708,53 @@ job_test_unknown_fmt = <details><summary>:shrug: UNKNOWN _(click triangle for de
657708
`job_test_unknown_fmt` is used in case no test file (produced by `bot/check-test.sh`
658709
provided by target repository) was found.
659710

711+
712+
#### `[download_pr_comments]` section
713+
714+
The `[download_pr_comments]` section sets templates for messages related to
715+
downloading the contents of a pull request.
716+
```
717+
git_clone_failure = Unable to clone the target repository.
718+
```
719+
`git_clone_failure` is shown when `git clone` failed.
720+
721+
```
722+
git_clone_tip = _Tip: This could be a connection failure. Try again and if the issue remains check if the address is correct_.
723+
```
724+
`git_clone_tip` should contain some hint on how to deal with the issue. It is shown when `git clone` failed.
725+
726+
```
727+
git_checkout_failure = Unable to checkout to the correct branch.
728+
```
729+
`git_checkout_failure` is shown when `git checkout` failed.
730+
731+
```
732+
git_checkout_tip = _Tip: Ensure that the branch name is correct and the target branch is available._
733+
```
734+
`git_checkout_tip` should contain some hint on how to deal with the failure. It
735+
is shown when `git checkout` failed.
736+
737+
```
738+
curl_failure = Unable to download the `.diff` file.
739+
```
740+
`curl_failure` is shown when downloading the `PR_NUMBER.diff`
741+
```
742+
curl_tip = _Tip: This could be a connection failure. Try again and if the issue remains check if the address is correct_
743+
```
744+
`curl_tip` should help in how to deal with failing downloads of the `.diff` file.
745+
746+
```
747+
git_apply_failure = Unable to download or merge changes between the source branch and the destination branch.
748+
```
749+
`git_apply_failure` is shown when applying the `.diff` file with `git apply`
750+
failed.
751+
752+
```
753+
git_apply_tip = _Tip: This can usually be resolved by syncing your branch and resolving any merge conflicts._
754+
```
755+
`git_apply_tip` should guide the contributor/maintainer about resolving the cause
756+
of `git apply` failing.
757+
660758
# Instructions to run the bot components
661759

662760
The bot consists of three components:

app.cfg.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ deploy_permission =
147147
# template for comment when user who set a label has no permission to trigger deploying tarballs
148148
no_deploy_permission_comment = Label `bot:deploy` has been set by user `{deploy_labeler}`, but this person does not have permission to trigger deployments
149149

150+
# settings for where (directory) in the S3 bucket to store the metadata file and
151+
# the tarball
152+
# - Can be a string value to always use the same 'prefix' regardless of the target
153+
# CVMFS repository, or can be a mapping of a target repository id (see also
154+
# repo_target_map) to a prefix.
155+
# - The prefix itself can use some (environment) variables that are set within
156+
# the script. Currently those are:
157+
# * 'github_repository' (which would be expanded to the full name of the GitHub
158+
# repository, e.g., 'EESSI/software-layer'),
159+
# * 'legacy_aws_path' (which expands to the legacy/old prefix being used for
160+
# storing tarballs/metadata files) and
161+
# * 'pull_request_number' (which would be expanded to the number of the pull
162+
# request from which the tarball originates).
163+
# - The list of supported variables can be shown by running
164+
# `scripts/eessi-upload-to-staging --list-variables`.
165+
# - Examples:
166+
# metadata_prefix = {"eessi.io-2023.06": "new/${github_repository}/${pull_request_number}"}
167+
# tarball_prefix = {"eessi-pilot-2023.06": "", "eessi.io-2023.06": "new/${github_repository}/${pull_request_number}"}
168+
# If left empty, the old/legacy prefix is being used.
169+
metadata_prefix =
170+
tarball_prefix =
171+
150172

151173
[architecturetargets]
152174
# defines both for which architectures the bot will build

scripts/eessi-upload-to-staging

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function create_metadata_file
4141
_tarball=$1
4242
_url=$2
4343
_repository=$3
44-
_pull_request=$4
44+
_pull_request_number=$4
4545
_pull_request_comment_id=$5
4646

4747
_tmpfile=$(mktemp)
@@ -56,31 +56,43 @@ function create_metadata_file
5656
--arg sha256 "$(sha256sum "${_tarball}" | awk '{print $1}')" \
5757
--arg url "${_url}" \
5858
--arg repo "${_repository}" \
59-
--arg pr "${_pull_request}" \
59+
--arg pr "${_pull_request_number}" \
6060
--arg pr_comment_id "${_pull_request_comment_id}" \
6161
'{
6262
uploader: {username: $un, ip: $ip, hostname: $hn},
6363
payload: {filename: $fn, size: $sz, ctime: $ct, sha256sum: $sha256, url: $url},
64-
link2pr: {repo: $repo, pr: $pr, pr_comment_id: $pr_commend_id},
64+
link2pr: {repo: $repo, pr: $pr, pr_comment_id: $pr_comment_id},
6565
}' > "${_tmpfile}"
6666

6767
echo "${_tmpfile}"
6868
}
6969

7070
function display_help
7171
{
72-
echo "Usage: $0 [OPTIONS] <filenames>" >&2
73-
echo " -e | --endpoint-url URL - endpoint url (needed for non AWS S3)" >&2
74-
echo " -h | --help - display this usage information" >&2
75-
echo " -i | --pr-comment-id - identifier of a PR comment; may be" >&2
76-
echo " used to efficiently determine the PR" >&2
77-
echo " comment to be updated during the" >&2
78-
echo " ingestion procedure" >&2
79-
echo " -n | --bucket-name BUCKET - bucket name (same as BUCKET above)" >&2
80-
echo " -p | --pull-request NUMBER - a pull request NUMBER; used to" >&2
81-
echo " link the upload to a PR" >&2
82-
echo " -r | --repository FULL_NAME - a repository name ACCOUNT/REPONAME;" >&2
83-
echo " used to link the upload to a PR" >&2
72+
echo "Usage: $0 [OPTIONS] <filenames>" >&2
73+
echo " -e | --endpoint-url URL - endpoint url (needed for non AWS S3)" >&2
74+
echo " -h | --help - display this usage information" >&2
75+
echo " -i | --pr-comment-id - identifier of a PR comment; may be" >&2
76+
echo " used to efficiently determine the PR" >&2
77+
echo " comment to be updated during the" >&2
78+
echo " ingestion procedure" >&2
79+
echo " -l | --list-variables - list variables that are available" >&2
80+
echo " for expansion" >&2
81+
echo " -m | --metadata-prefix PREFIX - a directory to which the metadata" >&2
82+
echo " file shall be uploaded; BASH variable" >&2
83+
echo " expansion will be applied; arg '-l'" >&2
84+
echo " lists variables that are defined at" >&2
85+
echo " the time of expansion" >&2
86+
echo " -n | --bucket-name BUCKET - bucket name (same as BUCKET above)" >&2
87+
echo " -p | --pull-request-number INT - a pull request number (INT); used to" >&2
88+
echo " link the upload to a PR" >&2
89+
echo " -r | --repository FULL_NAME - a repository name ACCOUNT/REPONAME;" >&2
90+
echo " used to link the upload to a PR" >&2
91+
echo " -t | --tarball-prefix PREFIX - a directory to which the tarball" >&2
92+
echo " shall be uploaded; BASH variable" >&2
93+
echo " expansion will be applied; arg '-l'" >&2
94+
echo " lists variables that are defined at" >&2
95+
echo " the time of expansion" >&2
8496
}
8597

8698
if [[ $# -lt 1 ]]; then
@@ -106,8 +118,16 @@ endpoint_url=
106118

107119
# provided via command line arguments
108120
pr_comment_id="none"
109-
pull_request="none"
110-
repository="EESSI/software-layer"
121+
pull_request_number="none"
122+
github_repository="EESSI/software-layer"
123+
124+
# provided via options in the bot's config file app.cfg and/or command line argument
125+
metadata_prefix=
126+
tarball_prefix=
127+
128+
# other variables
129+
legacy_aws_path=
130+
variables="github_repository legacy_aws_path pull_request_number"
111131

112132
while [[ $# -gt 0 ]]; do
113133
case $1 in
@@ -119,20 +139,36 @@ while [[ $# -gt 0 ]]; do
119139
display_help
120140
exit 0
121141
;;
142+
-l|--list-variables)
143+
echo "variables that will be expanded: name (default value)"
144+
for var in ${variables}
145+
do
146+
echo " ${var} (${!var:-unset})"
147+
done
148+
exit 0
149+
;;
122150
-i|--pr-comment-id)
123151
pr_comment_id="$2"
124152
shift 2
125153
;;
154+
-m|--metadata-prefix)
155+
metadata_prefix="$2"
156+
shift 2
157+
;;
126158
-n|--bucket-name)
127159
bucket_name="$2"
128160
shift 2
129161
;;
130-
-p|--pull-request)
131-
pull_request="$2"
162+
-p|--pull-request-number)
163+
pull_request_number="$2"
132164
shift 2
133165
;;
134166
-r|--repository)
135-
repository="$2"
167+
github_repository="$2"
168+
shift 2
169+
;;
170+
-t|--tarball-prefix)
171+
tarball_prefix="$2"
136172
shift 2
137173
;;
138174
-*|--*)
@@ -168,23 +204,50 @@ for file in "$*"; do
168204
basefile=$( basename ${file} )
169205
if check_file_name ${basefile}; then
170206
if tar tf "${file}" | head -n1 > /dev/null; then
171-
aws_path=$(basename ${file} | tr -s '-' '/' \
207+
# 'legacy_aws_path' might be used in tarball_prefix or metadata_prefix
208+
# its purpose is to support the old/legacy method to derive the location
209+
# where to store the tarball and metadata file
210+
export legacy_aws_path=$(basename ${file} | tr -s '-' '/' \
172211
| perl -pe 's/^eessi.//;' | perl -pe 's/\.tar\.gz$//;' )
212+
if [ -z ${tarball_prefix} ]; then
213+
aws_path=${legacy_aws_path}
214+
else
215+
export pull_request_number
216+
export github_repository
217+
aws_path=$(envsubst <<< "${tarball_prefix}")
218+
fi
173219
aws_file=$(basename ${file})
174220
echo "Creating metadata file"
175221
url="${bucket_base}/${aws_path}/${aws_file}"
176-
metadata_file=$(create_metadata_file "${file}" "${url}" \
177-
"${repository}" "${pull_request}" \
222+
echo "create_metadata_file file=${file} \
223+
url=${url} \
224+
github_repository=${github_repository} \
225+
pull_request_number=${pull_request_number} \
226+
pr_comment_id=${pr_comment_id}"
227+
metadata_file=$(create_metadata_file "${file}" \
228+
"${url}" \
229+
"${github_repository}" \
230+
"${pull_request_number}" \
178231
"${pr_comment_id}")
179232
echo "metadata:"
180233
cat ${metadata_file}
181234

182235
echo Uploading to "${url}"
236+
echo " store tarball at ${aws_path}/${aws_file}"
183237
upload_to_staging_bucket \
184238
"${file}" \
185239
"${bucket_name}" \
186240
"${aws_path}/${aws_file}" \
187241
"${endpoint_url}"
242+
243+
if [ -z ${metadata_prefix} ]; then
244+
aws_path=${legacy_aws_path}
245+
else
246+
export pull_request_number
247+
export github_repository
248+
aws_path=$(envsubst <<< "${metadata_prefix}")
249+
fi
250+
echo " store metadata file at ${aws_path}/${aws_file}.meta.txt"
188251
upload_to_staging_bucket \
189252
"${metadata_file}" \
190253
"${bucket_name}" \

tasks/build.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
ERROR_GIT_APPLY = "git apply"
5050
ERROR_GIT_CHECKOUT = "git checkout"
5151
ERROR_GIT_CLONE = "curl"
52+
ERROR_NONE = "none"
5253
GITHUB = "github"
5354
GIT_CLONE_FAILURE = "git_clone_failure"
5455
GIT_CLONE_TIP = "git_clone_tip"
@@ -399,6 +400,9 @@ def download_pr(repo_name, branch_name, pr, arch_job_dir):
399400
error_stage = ERROR_GIT_APPLY
400401
return git_apply_output, git_apply_error, git_apply_exit_code, error_stage
401402

403+
# need to return four items also in case everything went fine
404+
return 'downloading PR succeeded', 'no error while downloading PR', 0, ERROR_NONE
405+
402406

403407
def comment_download_pr(base_repo_name, pr, download_pr_exit_code, download_pr_error, error_stage):
404408
"""
@@ -862,6 +866,8 @@ def request_bot_build_issue_comments(repo_name, pr_number):
862866
status_table (dict): dictionary with 'arch', 'date', 'status', 'url' and 'result'
863867
for all the finished builds;
864868
"""
869+
fn = sys._getframe().f_code.co_name
870+
865871
status_table = {'arch': [], 'date': [], 'status': [], 'url': [], 'result': []}
866872
cfg = config.read_config()
867873

@@ -882,9 +888,12 @@ def request_bot_build_issue_comments(repo_name, pr_number):
882888
first_line = comment['body'].split('\n')[0]
883889
arch_map = get_architecture_targets(cfg)
884890
for arch in arch_map.keys():
885-
target_arch = '/'.join(arch.split('/')[-1])
891+
# drop the first element in arch (which names the OS type) and join the remaining items with '-'
892+
target_arch = '-'.join(arch.split('/')[1:])
886893
if target_arch in first_line:
887894
status_table['arch'].append(target_arch)
895+
else:
896+
log(f"{fn}(): target_arch '{target_arch}' not found in first line '{first_line}'")
888897

889898
# get date, status, url and result from the markdown table
890899
comment_table = comment['body'][comment['body'].find('|'):comment['body'].rfind('|')+1]

0 commit comments

Comments
 (0)