Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
run: |
# renovate: datasource=github-releases depName=terraform-docs/terraform-docs extractVersion=^v(?<version>.+)$
VERSION=0.20.0
curl -sSLo ./terraform-docs.tar.gz "https://terraform-docs.io/dl/v${VERSION}/terraform-docs-v${VERSION}-$(uname)-amd64.tar.gz"
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -sSLo ./terraform-docs.tar.gz "https://terraform-docs.io/dl/v${VERSION}/terraform-docs-v${VERSION}-$(uname)-${ARCH}.tar.gz"
tar -xzf terraform-docs.tar.gz terraform-docs
chmod +x terraform-docs
mv terraform-docs /usr/local/bin/terraform-docs
Expand Down
19 changes: 16 additions & 3 deletions ansible/bootstrap-ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ install_ansible_on_ubuntu() {
# Installing Ansible on Ubuntu
# https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-ubuntu
apt-get update
apt-get install --yes software-properties-common
add-apt-repository --yes --update ppa:ansible/ansible
apt-get install --yes --no-install-recommends ansible python3-pip

UBUNTU_CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")

Comment on lines +20 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Harden codename extraction for strict mode (set -u).

At Line 20, $VERSION_CODENAME is expanded without a default. If that key is absent in /etc/os-release, the script exits immediately under set -u.

Suggested fix
-  UBUNTU_CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
+  . /etc/os-release
+  UBUNTU_CODENAME="${VERSION_CODENAME:-${UBUNTU_CODENAME:-}}"
+  if [ -z "$UBUNTU_CODENAME" ]; then
+    echo "Unable to determine Ubuntu codename from /etc/os-release"
+    exit 1
+  fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UBUNTU_CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
. /etc/os-release
UBUNTU_CODENAME="${VERSION_CODENAME:-${UBUNTU_CODENAME:-}}"
if [ -z "$UBUNTU_CODENAME" ]; then
echo "Unable to determine Ubuntu codename from /etc/os-release"
exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ansible/bootstrap-ansible.sh` around lines 20 - 21, The UBUNTU_CODENAME
assignment uses VERSION_CODENAME without a default so the script will fail under
set -u if that key is missing; modify the command-substitution that sets
UBUNTU_CODENAME so it safely handles an unset VERSION_CODENAME (e.g., use
parameter expansion to supply an empty or safe default or fall back to another
retrieval method) so the script does not exit under strict mode; update the
expression that sets UBUNTU_CODENAME and keep references to VERSION_CODENAME and
the current command-substitution form so reviewers can find and verify the
change.

case "$UBUNTU_CODENAME" in
jammy|focal|bionic)
apt-get install --yes software-properties-common
add-apt-repository --yes --update ppa:ansible/ansible
apt-get install --yes --no-install-recommends ansible python3-pip
;;
*)
# Ubuntu 24.04+ (noble and newer) includes Ansible in the universe repository;
# the PPA is unnecessary and its "noble" distribution causes apt-get update to
# hang in Docker builds.
apt-get install --yes --no-install-recommends ansible python3-pip
;;
esac

# "--ignore-installed" is added to fix error "Cannot uninstall PyYAML 6.0.1 ... The package was installed by debian."
pip install passlib ansible-lint --ignore-installed --break-system-packages
Expand Down
2 changes: 1 addition & 1 deletion ansible/inventory/group_vars/debian/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ debian_base_install_crowdsec_bouncer: false

# https://github.com/go-task/task/releases
# renovate: datasource=github-releases depName=go-task/task
debian_base_go_task_version: "v3.44.1"
debian_base_go_task_version: "v3.50.0"

linuxbrew_use_installer: true
linuxbrew_init_shell: true
Expand Down
24 changes: 11 additions & 13 deletions ansible/roles/debian_base/tasks/60-go-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,29 @@
mode: "0755"
when: debian_base_task_version_check.rc != 0

- name: Set go-task architecture for arm
ansible.builtin.set_fact:
debian_base_task_arch: "arm"
when: ansible_architecture == "armv7l"
- name: Fail on unsupported architecture
ansible.builtin.fail:
msg: "Unsupported architecture: {{ ansible_facts['architecture'] }}"
when: ansible_facts['architecture'] not in ["x86_64", "aarch64", "armv7l", "armv6l"]

- name: Set go-task architecture for amd64
- name: Set go-task architecture
ansible.builtin.set_fact:
debian_base_task_arch: "amd64"
when: ansible_architecture == "x86_64"
debian_base_task_arch: "{{ {'x86_64': 'amd64', 'aarch64': 'arm64', 'armv7l': 'arm', 'armv6l': 'arm'}[ansible_facts['architecture']] }}"

- name: Set go-task architecture for arm64
- name: Set go-task version
ansible.builtin.set_fact:
debian_base_task_arch: "arm64"
when: ansible_architecture == "aarch64"
debian_base_go_task_version: "{{ debian_base_go_task_version | default('v3.50.0') }}"

- name: Download go-task .deb package
ansible.builtin.get_url:
url: "https://github.com/go-task/task/releases/download/{{ debian_base_go_task_version | default('v3.44.1') }}/task_linux_{{ debian_base_task_arch }}.deb"
dest: "/tmp/go-task/task_linux_{{ debian_base_task_arch }}.deb"
url: "https://github.com/go-task/task/releases/download/{{ debian_base_go_task_version }}/task_{{ debian_base_go_task_version | regex_replace('^v', '') }}_linux_{{ debian_base_task_arch }}.deb"
dest: "/tmp/go-task/task_{{ debian_base_go_task_version }}_linux_{{ debian_base_task_arch }}.deb"
Comment thread
bubacoder marked this conversation as resolved.
mode: "0644"
when: debian_base_task_version_check.rc != 0

- name: Install go-task from downloaded .deb package
ansible.builtin.apt:
deb: "/tmp/go-task/task_linux_{{ debian_base_task_arch }}.deb"
deb: "/tmp/go-task/task_{{ debian_base_go_task_version }}_linux_{{ debian_base_task_arch }}.deb"
state: present
when: debian_base_task_version_check.rc != 0
Comment thread
bubacoder marked this conversation as resolved.

Expand Down
24 changes: 19 additions & 5 deletions scripts/infra-mcp/tools/get_container_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import platform
import sys
from datetime import datetime
from email.utils import parsedate_to_datetime
Expand All @@ -16,6 +17,13 @@
REGISTRY_REQUEST_TIMEOUT = 30
MAX_TAGS_FETCH_LIMIT = 1000

_arch_map = {"x86_64": "amd64", "aarch64": "arm64", "armv7l": "arm"}


def _default_architecture() -> str:
arch = _arch_map.get(platform.machine(), platform.machine())
return f"linux/{arch}"


class ContainerTagFinder:
"""
Expand All @@ -39,8 +47,8 @@ def _parse_arch(self, arch: str) -> tuple[str, str]:
tuple: A tuple containing (os_part, arch_part)
"""
parts = arch.split("/")
os_part = parts[0] if parts else "linux"
arch_part = parts[1] if len(parts) > 1 else "amd64"
os_part = parts[0] if parts and parts[0] else "linux"
arch_part = parts[1] if len(parts) > 1 and parts[1] else _arch_map.get(platform.machine(), platform.machine())
return os_part, arch_part
Comment thread
coderabbitai[bot] marked this conversation as resolved.

def _parse_version(self, tag_name: str) -> tuple[int, ...] | None:
Expand Down Expand Up @@ -196,7 +204,7 @@ def _sort_tags(self, tag_data: list[dict[str, Any]], sort_by: str) -> None:
# else: sort_by == "default", keep original order

def get_docker_hub_tags(
self, image_name: str, limit: int = 10, architecture: str = "linux/amd64", sort_by: str = "version"
self, image_name: str, limit: int = 10, architecture: str | None = None, sort_by: str = "version"
) -> list[dict[str, Any]]:
"""Query Docker Hub for image tags with timestamp information.

Expand All @@ -209,6 +217,9 @@ def get_docker_hub_tags(
Returns:
list: List of tag dictionaries sorted according to sort_by parameter
"""
if architecture is None:
architecture = _default_architecture()

# Parse repository name
if "/" in image_name:
namespace, repo = image_name.split("/", 1)
Expand Down Expand Up @@ -299,7 +310,7 @@ def get_registry_tags(
registry_url: str,
image_name: str,
limit: int = 10,
architecture: str = "linux/amd64",
architecture: str | None = None,
sort_by: str = "version",
) -> list[dict[str, Any]]:
"""Query a registry API v2 for image tags and attempt to get creation time.
Expand All @@ -314,6 +325,9 @@ def get_registry_tags(
Returns:
list: List of tag dictionaries sorted according to sort_by parameter
"""
if architecture is None:
architecture = _default_architecture()

url: str = f"{registry_url}/v2/{image_name}/tags/list"
try:
response = requests.get(url, timeout=REGISTRY_REQUEST_TIMEOUT)
Expand Down Expand Up @@ -626,7 +640,7 @@ def get_most_specific_tag(self, args: argparse.Namespace) -> dict[str, Any] | No
def main() -> None:
parser = argparse.ArgumentParser(description="Operations on container image tags")
parser.add_argument("--registry", help="Registry URL (defaults to Docker Hub if not specified)")
parser.add_argument("--architecture", default="linux/amd64", help="Architecture to query for (default: linux/amd64)")
parser.add_argument("--architecture", default=_default_architecture(), help="Architecture to query for (default: auto-detected)")
parser.add_argument("--quiet", action="store_true", help="Only output final results, no status or progress messages")

subparsers = parser.add_subparsers(dest="command", help="Command to execute", required=True)
Expand Down
6 changes: 5 additions & 1 deletion scripts/infra-mcp/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This module centralizes magic numbers and configuration values used throughout the codebase.
"""

import platform as _platform

# HTTP Request Timeouts (in seconds)
DEFAULT_REQUEST_TIMEOUT = 10
REGISTRY_REQUEST_TIMEOUT = 30
Expand All @@ -13,7 +15,9 @@
DEFAULT_SAME_HASH_LIMIT = 100

# Container Architecture
DEFAULT_CONTAINER_ARCHITECTURE = "linux/amd64"

_arch_map = {"x86_64": "amd64", "aarch64": "arm64", "armv7l": "arm"}
DEFAULT_CONTAINER_ARCHITECTURE = f"linux/{_arch_map.get(_platform.machine(), _platform.machine())}"

# Task Execution
TASK_COMMAND_TIMEOUT = 600 # 10 minutes in seconds
12 changes: 10 additions & 2 deletions scripts/infra-mcp/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
This module contains dataclass definitions for shared data structures used throughout the codebase.
"""

from dataclasses import dataclass
import platform
from dataclasses import dataclass, field

_arch_map = {"x86_64": "amd64", "aarch64": "arm64", "armv7l": "arm"}


def _default_architecture() -> str:
arch = _arch_map.get(platform.machine(), platform.machine())
return f"linux/{arch}"


@dataclass
Expand All @@ -20,7 +28,7 @@ class ContainerTagFinderArgs:
"""

image: str
architecture: str = "linux/amd64"
architecture: str = field(default_factory=_default_architecture)
limit: int = 10
quiet: bool = True
registry: str | None = None
Expand Down
Loading