Skip to content

Commit 6996fcc

Browse files
Enmkzvonand
authored andcommitted
Merge pull request #693 from Altinity/24.8/cicd-fix/get_docker_from_secrets
24.8 Use credentials from secrets
1 parent 4f70a9c commit 6996fcc

File tree

10 files changed

+77
-37
lines changed

10 files changed

+77
-37
lines changed

.github/workflows/regression.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ name: Regression test workflow - Release
8888
env:
8989
# Force the stdout and stderr streams to be unbuffered
9090
PYTHONUNBUFFERED: 1
91-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_REPORT_KEY_ID }}
92-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_REPORT_SECRET_ACCESS_KEY }}
93-
AWS_DEFAULT_REGION: ${{ secrets.AWS_REPORT_REGION }}
91+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
92+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
93+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
9494
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
9595
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
9696
args: --test-to-end

.github/workflows/release_branches.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ env:
77
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
88
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
99
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
10+
CLICKHOUSE_TEST_STAT_LOGIN: ${{ secrets.CLICKHOUSE_TEST_STAT_LOGIN }}
11+
CLICKHOUSE_TEST_STAT_PASSWORD: ${{ secrets.CLICKHOUSE_TEST_STAT_PASSWORD }}
12+
CLICKHOUSE_TEST_STAT_URL: ${{ secrets.CLICKHOUSE_TEST_STAT_URL }}
13+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
14+
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
1015

1116
on: # yamllint disable-line rule:truthy
1217
pull_request:
@@ -16,7 +21,7 @@ on: # yamllint disable-line rule:truthy
1621
- opened
1722
branches:
1823
# Anything/24.3 (e.g customizations/24.3.x)
19-
- '**/24.3*'
24+
- '**24.3*'
2025
release:
2126
types:
2227
- published

.github/workflows/reusable_build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ env:
88
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
99
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
1010
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11+
CLICKHOUSE_TEST_STAT_LOGIN: ${{ secrets.CLICKHOUSE_TEST_STAT_LOGIN }}
12+
CLICKHOUSE_TEST_STAT_PASSWORD: ${{ secrets.CLICKHOUSE_TEST_STAT_PASSWORD }}
13+
CLICKHOUSE_TEST_STAT_URL: ${{ secrets.CLICKHOUSE_TEST_STAT_URL }}
14+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
15+
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
1116

1217
name: Build ClickHouse
1318
'on':

.github/workflows/reusable_sign.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
### For the pure soul wishes to move it to another place
2-
# https://github.com/orgs/community/discussions/9050
3-
4-
name: Testing workflow
1+
name: Sigining workflow
52
'on':
63
workflow_call:
74
inputs:
@@ -63,6 +60,11 @@ env:
6360
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
6461
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
6562
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
63+
CLICKHOUSE_TEST_STAT_LOGIN: ${{ secrets.CLICKHOUSE_TEST_STAT_LOGIN }}
64+
CLICKHOUSE_TEST_STAT_PASSWORD: ${{ secrets.CLICKHOUSE_TEST_STAT_PASSWORD }}
65+
CLICKHOUSE_TEST_STAT_URL: ${{ secrets.CLICKHOUSE_TEST_STAT_URL }}
66+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
67+
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
6668

6769
jobs:
6870
runner_labels_setup:

.github/workflows/reusable_test.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,25 @@ name: Testing workflow
4444
description: if given, it's passed to the environments
4545
required: false
4646
AWS_SECRET_ACCESS_KEY:
47-
description: the access key to the aws param store.
47+
description: the access key to the aws s3 bucket.
4848
required: true
4949
AWS_ACCESS_KEY_ID:
50-
description: the access key id to the aws param store.
50+
description: the access key id to the aws s3 bucket.
51+
required: true
52+
CLICKHOUSE_TEST_STAT_LOGIN:
53+
description: username for ci db.
54+
required: true
55+
CLICKHOUSE_TEST_STAT_PASSWORD:
56+
description: password for ci db.
57+
required: true
58+
CLICKHOUSE_TEST_STAT_URL:
59+
description: url for ci db.
60+
required: true
61+
DOCKER_PASSWORD:
62+
description: token to upload docker images.
63+
required: true
64+
ROBOT_TOKEN:
65+
description: token to update ci status.
5166
required: true
5267

5368
env:
@@ -57,6 +72,11 @@ env:
5772
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
5873
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
5974
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
75+
CLICKHOUSE_TEST_STAT_LOGIN: ${{ secrets.CLICKHOUSE_TEST_STAT_LOGIN }}
76+
CLICKHOUSE_TEST_STAT_PASSWORD: ${{ secrets.CLICKHOUSE_TEST_STAT_PASSWORD }}
77+
CLICKHOUSE_TEST_STAT_URL: ${{ secrets.CLICKHOUSE_TEST_STAT_URL }}
78+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
79+
ROBOT_TOKEN: ${{ secrets.ROBOT_TOKEN }}
6080

6181
jobs:
6282
runner_labels_setup:

docker/packager/packager

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import os
66
import subprocess
77
import sys
88
from pathlib import Path
9-
from typing import List, Optional
9+
from typing import Dict, List, Optional
1010

1111
SCRIPT_PATH = Path(__file__).absolute()
1212
IMAGE_TYPE = "binary-builder"
1313
IMAGE_NAME = f"altinityinfra/{IMAGE_TYPE}"
14-
14+
DEFAULT_TMP_PATH = SCRIPT_PATH.parent.absolute() / 'tmp'
15+
TEMP_PATH = Path(os.getenv("TEMP_PATH", DEFAULT_TMP_PATH))
1516

1617
class BuildException(Exception):
1718
pass
@@ -82,9 +83,22 @@ def run_docker_image_with_env(
8283
ch_root: Path,
8384
cargo_cache_dir: Path,
8485
ccache_dir: Optional[Path],
86+
aws_secrets : Optional[Dict[str,str]]
8587
) -> None:
8688
output_dir.mkdir(parents=True, exist_ok=True)
8789
cargo_cache_dir.mkdir(parents=True, exist_ok=True)
90+
extra_parts = ""
91+
92+
if aws_secrets:
93+
# Pass AWS credentials via file rather than via env to avoid leaking secrets
94+
env_part = {"AWS_CONFIG_FILE": "/home/clickhouse/.aws/credentials"}
95+
host_aws_config_file_path = Path(TEMP_PATH) / 'aws_config'
96+
with open(host_aws_config_file_path, 'wt') as f:
97+
f.write("[default]")
98+
for key, value in aws_secrets.items():
99+
f.write(f"\n{key}={value}")
100+
101+
extra_parts = f"--volume={host_aws_config_file_path}:{env_part['AWS_CONFIG_FILE']}"
88102

89103
env_part = " -e ".join(env_variables)
90104
if env_part:
@@ -107,6 +121,7 @@ def run_docker_image_with_env(
107121
cmd = (
108122
f"docker run --network=host --user={user} --rm {ccache_mount} "
109123
f"--volume={output_dir}:/output --volume={ch_root}:/build {env_part} "
124+
f" {extra_parts} "
110125
f"--volume={cargo_cache_dir}:/rust/cargo/registry {interactive} {image_name}"
111126
)
112127

@@ -130,11 +145,9 @@ def parse_env_variables(
130145
sanitizer: str,
131146
package_type: str,
132147
cache: str,
133-
s3_access_key_id: str,
134148
s3_bucket: str,
135149
s3_directory: str,
136150
s3_rw_access: bool,
137-
s3_secret_access_key: str,
138151
clang_tidy: bool,
139152
version: str,
140153
official: bool,
@@ -319,10 +332,6 @@ def parse_env_variables(
319332
result.append(f"SCCACHE_S3_KEY_PREFIX={sccache_dir}")
320333
if not s3_rw_access:
321334
result.append("SCCACHE_S3_NO_CREDENTIALS=true")
322-
if s3_access_key_id:
323-
result.append(f"AWS_ACCESS_KEY_ID={s3_access_key_id}")
324-
if s3_secret_access_key:
325-
result.append(f"AWS_SECRET_ACCESS_KEY={s3_secret_access_key}")
326335

327336
if clang_tidy:
328337
# `CTCACHE_DIR` has the same purpose as the `CCACHE_DIR` above.
@@ -539,11 +548,9 @@ def main() -> None:
539548
args.sanitizer,
540549
args.package_type,
541550
args.cache,
542-
args.s3_access_key_id,
543551
args.s3_bucket,
544552
args.s3_directory,
545553
args.s3_rw_access,
546-
args.s3_secret_access_key,
547554
args.clang_tidy,
548555
args.version,
549556
args.official,
@@ -562,6 +569,10 @@ def main() -> None:
562569
ch_root,
563570
args.cargo_cache_dir,
564571
args.ccache_dir,
572+
{
573+
"aws_access_key_id" : args.s3_access_key_id,
574+
"aws_secret_access_key" : args.s3_secret_access_key
575+
}
565576
)
566577
logging.info("Output placed into %s", args.output_dir)
567578

tests/ci/clickhouse_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import requests
1010

11-
from env_helper import GITHUB_REPOSITORY
11+
from env_helper import GITHUB_REPOSITORY, CLICKHOUSE_TEST_STAT_URL, CLICKHOUSE_TEST_STAT_PASSWORD, CLICKHOUSE_TEST_STAT_LOGIN
1212
from get_robot_token import get_parameter_from_ssm
1313
from pr_info import PRInfo
1414
from report import TestResults
@@ -27,12 +27,12 @@ def __init__(
2727
self, url: Optional[str] = None, auth: Optional[Dict[str, str]] = None
2828
):
2929
if url is None:
30-
url = get_parameter_from_ssm("clickhouse-test-stat-url")
30+
url = CLICKHOUSE_TEST_STAT_URL
3131

3232
self.url = url
3333
self.auth = auth or {
34-
"X-ClickHouse-User": get_parameter_from_ssm("clickhouse-test-stat-login"),
35-
"X-ClickHouse-Key": get_parameter_from_ssm("clickhouse-test-stat-password"),
34+
"X-ClickHouse-User": CLICKHOUSE_TEST_STAT_LOGIN,
35+
"X-ClickHouse-Key": CLICKHOUSE_TEST_STAT_PASSWORD,
3636
}
3737

3838
@staticmethod

tests/ci/docker_images_helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Dict, List, Optional
99

10-
from env_helper import ROOT_DIR, DOCKER_TAG
11-
from get_robot_token import get_parameter_from_ssm
10+
from env_helper import ROOT_DIR, DOCKER_TAG, DOCKER_PASSWORD
1211

1312
IMAGES_FILE_PATH = Path("docker/images.json")
1413

@@ -28,7 +27,7 @@ def docker_login(relogin: bool = True) -> None:
2827
logging.info('Doing docker login')
2928
subprocess.check_output( # pylint: disable=unexpected-keyword-arg
3029
"docker login --username 'altinityinfra' --password-stdin",
31-
input=get_parameter_from_ssm("dockerhub-password"),
30+
input=DOCKER_PASSWORD,
3231
encoding="utf-8",
3332
shell=True,
3433
)

tests/ci/env_helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
"{pr_or_release}/{commit}/{build_name}/{artifact}"
3939
)
4040

41+
CLICKHOUSE_TEST_STAT_LOGIN = os.getenv("CLICKHOUSE_TEST_STAT_LOGIN")
42+
CLICKHOUSE_TEST_STAT_PASSWORD = os.getenv("CLICKHOUSE_TEST_STAT_PASSWORD")
43+
CLICKHOUSE_TEST_STAT_URL = os.getenv("CLICKHOUSE_TEST_STAT_URL")
44+
DOCKER_PASSWORD = os.getenv("DOCKER_PASSWORD")
45+
ROBOT_TOKEN = os.getenv("ROBOT_TOKEN")
46+
4147
# These parameters are set only on demand, and only once
4248
_GITHUB_JOB_ID = ""
4349
_GITHUB_JOB_URL = ""

tests/ci/get_robot_token.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from github.GithubException import BadCredentialsException
1010
from github.NamedUser import NamedUser
1111

12+
from env_helper import ROBOT_TOKEN
1213

1314
@dataclass
1415
class Token:
@@ -52,20 +53,11 @@ def get_parameters_from_ssm(
5253

5354
return results
5455

55-
56-
ROBOT_TOKEN = None # type: Optional[Token]
57-
5856
# NOTE(Arthur Passos): Original CI code uses the "_original" version of this method. Each robot token is rate limited
5957
# and the original implementation selects the "best one". To make it simpler and iterate faster,
6058
# we are using only one robot and keeping the method signature. In the future we might reconsider
6159
# having multiple robot tokens
62-
def get_best_robot_token(token_prefix_env_name="github_robot_token"):
63-
# Re-use already fetched token (same as in get_best_robot_token_original)
64-
# except here we assume it is always a string (since we use only one token and don't do token rotation)
65-
global ROBOT_TOKEN
66-
if ROBOT_TOKEN is not None:
67-
return ROBOT_TOKEN
68-
ROBOT_TOKEN = get_parameter_from_ssm(token_prefix_env_name)
60+
def get_best_robot_token():
6961
return ROBOT_TOKEN
7062

7163
def get_best_robot_token_original(tokens_path: str = "/github-tokens") -> str:

0 commit comments

Comments
 (0)