Skip to content

Commit ac2682c

Browse files
anfimovdmbklvsky
andauthored
Add Alpine support (#166)
* AL-5888: add ansible playbooks for Alpine systems * Fixes after testing * Enabling --allow-untrusted flag for apk commands --------- Co-authored-by: bklvsky <alexandrakachanova@gmail.com>
1 parent d52f211 commit ac2682c

File tree

7 files changed

+96
-3
lines changed

7 files changed

+96
-3
lines changed

alts/shared/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import IntEnum
22

33
__all__ = [
4+
'ALPINE_FLAVORS',
45
'API_VERSION',
56
'ARCHITECTURES',
67
'ALLOWED_CHANNELS',
@@ -39,13 +40,14 @@
3940
'ppc64le',
4041
]
4142
SUPPORTED_ARCHITECTURES = X32_ARCHITECTURES + X64_ARCHITECTURES + ['s390x']
42-
SUPPORTED_DISTRIBUTIONS = ['almalinux', 'centos', 'ubuntu', 'debian']
43+
SUPPORTED_DISTRIBUTIONS = ['almalinux', 'centos', 'ubuntu', 'debian', 'alpine']
4344
RHEL_FLAVORS = [
4445
'rhel',
4546
'fedora',
4647
'centos',
4748
'almalinux',
4849
]
50+
ALPINE_FLAVORS = ['alpine']
4951
DEBIAN_FLAVORS = ['debian', 'ubuntu', 'raspbian']
5052
ALLOWED_CHANNELS = ['stable', 'beta']
5153

alts/shared/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def __init__(self, **data):
290290
# Supported architectures and distributions
291291
supported_architectures: List[str] = constants.SUPPORTED_ARCHITECTURES
292292
rhel_flavors: List[str] = constants.RHEL_FLAVORS
293+
alpine_flavors: List[str] = constants.ALPINE_FLAVORS
293294
debian_flavors: List[str] = constants.DEBIAN_FLAVORS
294295
supported_runners: Union[List[str], str] = 'all'
295296
allowed_channel_names: List[str] = constants.ALLOWED_CHANNELS
@@ -356,7 +357,7 @@ def broker_url(self) -> str:
356357
@computed_field(return_type=Set[str])
357358
@property
358359
def supported_distributions(self):
359-
return set(self.rhel_flavors + self.debian_flavors)
360+
return set(self.rhel_flavors + self.debian_flavors + self.alpine_flavors)
360361

361362
def get_celery_config_dict(self) -> Dict[str, Any]:
362363
config_dict = {

alts/worker/runners/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ def pkg_manager(self):
311311
return 'yum'
312312
if self._dist_name in CONFIG.debian_flavors:
313313
return 'apt-get'
314+
if self._dist_name in CONFIG.alpine_flavors:
315+
return 'apk'
314316
raise ValueError(f'Unknown distribution: {self._dist_name}')
315317

316318
@property
@@ -786,6 +788,9 @@ def get_system_info_commands_list(self) -> Dict[str, tuple]:
786788
'find', '/etc/yum.repos.d/', '-type', 'f',
787789
'-exec', 'cat', '{}', '+'
788790
)
791+
elif self._dist_name in CONFIG.alpine_flavors:
792+
basic_commands['Installed packages'] = ('apk', '--allow-untrusted', 'info', '-vv')
793+
basic_commands['Repositories list'] = ('cat', '/etc/apk/repositories')
789794
else:
790795
basic_commands['Installed packages'] = ('dpkg', '-l')
791796
basic_commands['Repositories list'] = ('apt-cache', 'policy')
@@ -1175,6 +1180,8 @@ def check_package_existence(
11751180
elif self.dist_name in CONFIG.debian_flavors:
11761181
cmd = ('dpkg-query', '-Wf', r'${db:Status-Status} ${Package}\n',
11771182
package_name)
1183+
elif self.dist_name in CONFIG.alpine_flavors:
1184+
cmd = ('apk', '--allow-untrusted', 'info', '-e', package_name)
11781185
else:
11791186
raise ValueError(f'Unknown distribution: {self.dist_name}')
11801187
exit_code, stdout, stderr = self.exec_command(*cmd)

alts/worker/runners/docker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def initial_provision(self, verbose=False):
259259
'find', '/etc/yum.repos.d', '-type', 'f', '-exec',
260260
'rm', '-f', '{}', '+',
261261
)
262+
if self.dist_name in CONFIG.alpine_flavors:
263+
self._logger.info('Installing python3 apk package for alpine...')
264+
self.exec_command('apk', '--allow-untrusted', 'add', 'python3')
262265
return super().initial_provision(verbose=verbose)
263266

264267
@command_decorator(

resources/roles/install_uninstall/tasks/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
---
22

3+
- set_fact:
4+
short_apk_pkg_name: "{{ pkg_name.split('=')[0] }}"
5+
when: ansible_facts['os_family'] == 'Alpine'
6+
tags:
7+
- uninstall_package
8+
39
- set_fact:
410
short_deb_pkg_name: "{{ pkg_name.split('=')[0] }}"
511
when: ansible_distribution_file_variety == 'Debian'
@@ -83,3 +89,25 @@
8389
when: ansible_distribution_file_variety == 'Debian' and deb_installed.rc == 0
8490
tags:
8591
- uninstall_package
92+
93+
- name: Install APK package
94+
shell:
95+
cmd: "apk --allow-untrusted add {{ pkg_name }}"
96+
when: ansible_facts['os_family'] == 'Alpine'
97+
tags:
98+
- install_package
99+
100+
- name: Check APK package is installed
101+
shell: "apk --allow-untrusted info -e {{ short_apk_pkg_name }}"
102+
register: apk_installed
103+
failed_when: apk_installed.rc not in [0, 1]
104+
when: ansible_facts['os_family'] == 'Alpine'
105+
tags:
106+
- uninstall_package
107+
108+
- name: Uninstall APK package
109+
shell:
110+
cmd: "apk --allow-untrusted del {{ pkg_name }}"
111+
when: ansible_facts['os_family'] == 'Alpine' and apk_installed.rc == 0
112+
tags:
113+
- uninstall_package
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Update Alpine packages
3+
command: apk --allow-untrusted update && apk --allow-untrusted upgrade
4+
5+
- name: Add custom APK repository to /etc/apk/repositories
6+
lineinfile:
7+
path: /etc/apk/repositories
8+
line: "{{ item.url }}"
9+
state: present
10+
with_items: "{{ repositories }}"
11+
when: repositories is defined and repositories | length > 0
12+
13+
- name: Update APK index cache
14+
command: apk --allow-untrusted update
15+
16+
- name: Install required packages on Alpine
17+
command: apk --allow-untrusted add ansible bats python3 py3-pip ca-certificates procps file iproute2
18+
19+
- name: Install test tools in virtualenv (Alpine)
20+
pip:
21+
name:
22+
- pytest
23+
- pytest-testinfra
24+
- pytest-check
25+
- pytest-tap
26+
virtualenv: /opt/testenv
27+
virtualenv_command: python3 -m venv
28+
when: ansible_facts.os_family == 'Alpine' and pytest_is_needed | bool
29+
tags:
30+
- initial_provision

resources/roles/preparation/tasks/main.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
tags:
1515
- initial_provision
1616

17+
- name: Initial provision for Alpine distributions
18+
include_tasks:
19+
file: alpine.yml
20+
when: ansible_facts.os_family == 'Alpine'
21+
tags:
22+
- initial_provision
23+
1724
- name: Copy tests to test environment
1825
copy:
1926
src: "{{ integrity_tests_dir }}"
@@ -29,7 +36,7 @@
2936
- pytest-testinfra
3037
- pytest-check
3138
- pytest-tap
32-
when: pytest_is_needed | bool
39+
when: ansible_facts.os_family != 'Alpine' and pytest_is_needed | bool
3340
tags:
3441
- initial_provision
3542

@@ -44,10 +51,25 @@
4451
with_items:
4552
- "/usr/lib64/firefox"
4653
- "/usr/lib64/thunderbird"
54+
when: ansible_facts['distribution'] != 'Alpine'
4755
tags:
4856
- initial_provision
4957

5058
- name: Reload ldconfig
5159
shell: ldconfig
5260
tags:
5361
- initial_provision
62+
when: ansible_facts['distribution'] != 'Alpine'
63+
64+
65+
- name: Add custom LD_LIBRARY_PATH for Alpine
66+
copy:
67+
dest: /etc/profile.d/custom-libs.sh
68+
content: |
69+
export LD_LIBRARY_PATH=/usr/lib/firefox:/usr/lib/thunderbird:$LD_LIBRARY_PATH
70+
owner: root
71+
group: root
72+
mode: 0644
73+
when: ansible_facts['distribution'] == 'Alpine'
74+
tags:
75+
- initial_provision

0 commit comments

Comments
 (0)