Skip to content

Commit e2a96be

Browse files
committed
Merge remote-tracking branch 'origin/expert-mode' into expert-mode
2 parents 9715128 + 690b517 commit e2a96be

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
lines changed

.config/make/docker.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ docker-lint: docker-lint-automation docker-lint-console-ui docker-lint-console-a
1111
docker-lint-automation: ## Lint automation Dockerfile
1212
@echo "Lint automation container Dockerfile"
1313
docker run --rm -i -v $(PWD)/automation/Dockerfile:/Dockerfile \
14-
hadolint/hadolint hadolint --ignore DL3002 --ignore DL3008 --ignore DL3059 /Dockerfile
14+
hadolint/hadolint hadolint --ignore DL3002 --ignore DL3008 --ignore DL3013 --ignore DL3059 /Dockerfile
1515

1616
docker-lint-console-ui: ## Lint console ui Dockerfile
1717
@echo "Lint console ui container Dockerfile"

automation/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ COPY automation /autobase/automation
1313
RUN apt-get clean && rm -rf /var/lib/apt/lists/partial \
1414
&& apt-get update -o Acquire::CompressionTypes::Order::=gz \
1515
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
16-
ca-certificates gnupg keychain debian-archive-keyring apt-transport-https \
17-
git python3 python3-dev python3-pip ssh-client sshpass gcc g++ cmake make libssl-dev curl lsb-release \
16+
ca-certificates gnupg keychain debian-archive-keyring apt-transport-https \
17+
git python3 python3-dev python3-pip ssh-client sshpass gcc g++ cmake make libssl-dev curl lsb-release \
18+
# fresh pip/setuptools/wheel (fewer builds from source)
19+
&& python3 -m pip install --break-system-packages --no-cache-dir --upgrade pip setuptools wheel \
1820
# repo and key for Azure CLI
1921
&& curl -sLS https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null \
2022
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
2123
&& apt-get update \
2224
# requirements
23-
&& pip3 install --break-system-packages --no-cache-dir -r /autobase/automation/requirements.txt \
25+
&& pip3 install --break-system-packages --no-cache-dir --retries 3 --timeout 60 \
26+
-r /autobase/automation/requirements.txt \
2427
&& ansible-galaxy install --force -r /autobase/automation/requirements.yml \
2528
&& ansible-galaxy collection list \
26-
&& pip3 install --break-system-packages --no-cache-dir -r \
27-
/root/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt \
29+
&& pip3 install --break-system-packages --no-cache-dir --retries 3 --timeout 60 \
30+
-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt \
2831
# azure-cli
2932
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y azure-cli \
3033
# cleanup
@@ -34,8 +37,8 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/partial \
3437
&& chmod +x /autobase/automation/entrypoint.sh
3538

3639
# Link collection source for Ansible runtime
37-
RUN mkdir -p /root/.ansible/collections/ansible_collections/vitabaks && \
38-
ln -sfn /autobase/automation /root/.ansible/collections/ansible_collections/vitabaks/autobase
40+
RUN mkdir -p /root/.ansible/collections/ansible_collections/vitabaks \
41+
&& ln -sfn /autobase/automation /root/.ansible/collections/ansible_collections/vitabaks/autobase
3942

4043
# Set environment variables
4144
ENV ANSIBLE_COLLECTIONS_PATH=/root/.ansible/collections/ansible_collections:/usr/local/lib/python3.11/dist-packages/ansible_collections

automation/roles/authorized_keys/tasks/main.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,17 @@
99
- name: "Add public keys to ~{{ system_user.stdout | default('') }}/.ssh/authorized_keys"
1010
ansible.posix.authorized_key:
1111
user: "{{ system_user.stdout }}"
12-
key: "{{ item }}"
12+
key: "{{ item | replace(\"'\", '') | replace('\"', '') | trim }}"
1313
state: present
14-
loop: '{{ ssh_public_keys_list }}'
15-
vars:
16-
ssh_public_keys_list: >-
17-
{{
18-
(
19-
ssh_public_keys
20-
| replace('[', '')
21-
| replace(']', '')
22-
| replace("'", '')
23-
| replace('"', '')
24-
| split(',')
25-
| map('trim')
26-
| reject('equalto', '')
27-
| list
28-
if ssh_public_keys is string
29-
else ssh_public_keys
30-
)
31-
}}
14+
loop: >-
15+
{{
16+
(ssh_public_keys
17+
| replace('\n', ',')
18+
| split(',')
19+
| reject('equalto', '')
20+
| list)
21+
if ssh_public_keys is string else ssh_public_keys
22+
}}
3223
when:
3324
- ssh_public_keys is defined
3425
- ssh_public_keys | length > 0

automation/roles/pgbouncer/templates/pgbouncer.ini.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[databases]
22
{% for pool in pgbouncer_pools %}
3-
{{ pool.name }} = host={{ postgresql_unix_socket_dir }} port={{ postgresql_port }} dbname={{ pool.dbname }} {{ pool.pool_parameters }}
3+
{{ pool.name }} = host={{ postgresql_unix_socket_dir }} port={{ postgresql_port }} dbname={{ pool.dbname }} {% if pool.pool_parameters is string %}{{ pool.pool_parameters }}{% elif pool.pool_parameters is mapping %}{% for k, v in pool.pool_parameters.items() %}{{ k }}={{ v }} {% endfor %}{% endif %}
44
{% endfor %}
55

66
* = host={{ postgresql_unix_socket_dir }} port={{ postgresql_port }}

automation/roles/pre_checks/tasks/pgbouncer.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616
# The calculated pool size is then added to the total 'pgbouncer_pool_size'.
1717
- name: PgBouncer | Calculate pool_size
1818
ansible.builtin.set_fact:
19-
pgbouncer_pool_size: "{{
20-
(pgbouncer_pool_size | default(0) | int)
21-
+
22-
(pool_item.pool_parameters
23-
| regex_search('pool_size=(\\d+)', multiline=False)
24-
| regex_replace('[^0-9]', '')
25-
| default(pgbouncer_default_pool_size | default(0), true)
26-
| int)
27-
}}"
19+
pgbouncer_pool_size: >-
20+
{{
21+
(pgbouncer_pool_size | default(0) | int)
22+
+
23+
(
24+
(
25+
pool_item.pool_parameters.pool_size
26+
if pool_item.pool_parameters is mapping
27+
else (
28+
pool_item.pool_parameters
29+
| regex_search('pool_size\s*=?\s*(\d+)', multiline=False)
30+
)
31+
)
32+
| default(pgbouncer_default_pool_size | default(0), true)
33+
| int
34+
)
35+
}}
2836
loop: "{{ pgbouncer_pools | default([]) }}"
2937
loop_control:
3038
loop_var: pool_item

console/service/api/swagger.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ definitions:
11451145
items:
11461146
type: string
11471147
extra_vars:
1148-
type: string
1148+
type: object
1149+
description: "Ansible extra vars (arbitrary JSON object)"
1150+
additionalProperties: true
11491151
existing_cluster:
11501152
type: boolean
11511153
default: false

console/service/internal/controllers/cluster/post_cluster.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ func (h *postClusterHandler) Handle(param cluster.PostClustersParams) middleware
7777
ansibleLogEnv := h.getAnsibleLogEnv(param.Body.Name)
7878
localLog.Trace().Strs("file_log", ansibleLogEnv).Msg("got file log name")
7979

80-
// Parse ExtraVars JSON string from request
8180
extraVars := map[string]interface{}{}
82-
if param.Body.ExtraVars != "" {
83-
if err := json.Unmarshal([]byte(param.Body.ExtraVars), &extraVars); err != nil {
84-
localLog.Warn().Str("extra_vars_raw", param.Body.ExtraVars).Err(err).Msg("failed to parse extra_vars JSON; using empty object")
81+
82+
if param.Body.ExtraVars != nil {
83+
if m, ok := param.Body.ExtraVars.(map[string]interface{}); ok {
84+
extraVars = m
85+
} else {
86+
localLog.Warn().Interface("extra_vars_raw", param.Body.ExtraVars).Msg("unexpected type for extra_vars, expected map[string]interface{}")
8587
}
8688
}
8789

@@ -150,21 +152,20 @@ func (h *postClusterHandler) Handle(param cluster.PostClustersParams) middleware
150152
status = "ready"
151153
}
152154

153-
// Marshal updated extraVars to JSON string for DB / Docker
155+
// extraVars
154156
extraVarsBytes, mErr := json.Marshal(extraVars)
155157
if mErr != nil {
156158
localLog.Error().Err(mErr).Msg("failed to marshal extra_vars; falling back to {}")
157159
extraVarsBytes = []byte("{}")
158160
}
159-
extraVarsJSON := string(extraVarsBytes)
160161

161162
createdCluster, err := h.db.CreateCluster(param.HTTPRequest.Context(), &storage.CreateClusterReq{
162163
ProjectID: param.Body.ProjectID,
163164
EnvironmentID: param.Body.EnvironmentID,
164165
Name: param.Body.Name,
165166
Description: param.Body.Description,
166167
SecretID: secretID,
167-
ExtraVars: extraVarsJSON,
168+
ExtraVars: extraVarsBytes,
168169
Location: getValFromExtraVars(extraVars, LocationExtraVar),
169170
ServerCount: serverCount,
170171
PostgreSqlVersion: getIntValFromExtraVars(extraVars, PostgreSqlVersionExtraVar),
@@ -259,7 +260,7 @@ func (h *postClusterHandler) Handle(param cluster.PostClustersParams) middleware
259260
var dockerId xdocker.InstanceID
260261
dockerId, err = h.dockerManager.ManageCluster(param.HTTPRequest.Context(), &xdocker.ManageClusterConfig{
261262
Envs: param.Body.Envs,
262-
ExtraVars: extraVarsJSON,
263+
ExtraVars: string(extraVarsBytes),
263264
Mounts: []xdocker.Mount{
264265
{
265266
DockerPath: ansibleLogDir,

console/service/internal/storage/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ type CreateClusterReq struct {
207207
Name string
208208
Description string
209209
SecretID *int64
210-
ExtraVars string // JSON string
210+
ExtraVars []byte
211211
Location string
212212
ServerCount int
213213
PostgreSqlVersion int

0 commit comments

Comments
 (0)