Simple automation to build Alpine packages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.1 KiB

  1. ---
  2. - name: create an Alpine build container
  3. hosts: localhost
  4. gather_facts: false
  5. collections:
  6. - containers.podman
  7. vars:
  8. alpine_version: 3.11.3
  9. tasks:
  10. - name: check container
  11. podman_container_info:
  12. name: alpine-builder
  13. register: container_info
  14. - name: create container
  15. block:
  16. - name: ensure image is present and fresh
  17. podman_image:
  18. name: docker.io/library/alpine
  19. tag: "{{ alpine_version }}"
  20. force: yes
  21. - podman_container:
  22. name: alpine-builder
  23. image: "alpine:{{ alpine_version }}"
  24. tty: yes
  25. interactive: yes
  26. register: container
  27. when: "'no such container' in container_info.stderr"
  28. - name: register container
  29. add_host:
  30. name: alpine-builder
  31. ansible_connection: podman
  32. changed_when: false
  33. - name: install Python
  34. block:
  35. - raw: apk update
  36. - raw: apk add python3
  37. delegate_to: alpine-builder
  38. when: container is changed
  39. - name: configure a build environment
  40. hosts: alpine-builder
  41. become_method: su
  42. become_user: "{{ user.handle }}"
  43. vars:
  44. user:
  45. name: GERCZEI, Tamas
  46. email: tamas@gerczei.eu
  47. handle: tgerczei
  48. build_config:
  49. - PACKAGER="{{ user.name }} <{{ user.email }}>"
  50. - MAINTAINER="$PACKAGER"
  51. tasks:
  52. - name: update system
  53. apk:
  54. update_cache: yes
  55. upgrade: yes
  56. - name: install Alpine SDK
  57. package:
  58. name: alpine-sdk
  59. - name: configure build system
  60. lineinfile:
  61. path: /etc/abuild.conf
  62. line: "{{ config_line }}"
  63. insertafter: "^#{{ config_line.split('=')[0] }}.*"
  64. loop: "{{ build_config }}"
  65. loop_control:
  66. loop_var: config_line
  67. label: "{{ config_line.split('=')[0] }}"
  68. - name: ensure user exists
  69. user:
  70. name: "{{ user.handle }}"
  71. shell: /bin/sh
  72. groups:
  73. - wheel
  74. - abuild
  75. append: yes
  76. - name: obtain aports tree
  77. block:
  78. - name: configure git
  79. git_config:
  80. name: "{{ item.name }}"
  81. value: "{{ item.value }}"
  82. scope: global
  83. loop: "{{ git_settings }}"
  84. vars:
  85. git_settings:
  86. - name: user.email
  87. value: "{{ user.email }}"
  88. - name: user.name
  89. value: "{{ user.name }}"
  90. - name: clone aports repository
  91. git:
  92. repo: git://git.alpinelinux.org/aports
  93. dest: "/home/{{ user.handle }}/aports"
  94. update: no
  95. register: repo
  96. - name: generate cryptographic key for the build system
  97. command: abuild-keygen -qai
  98. args:
  99. creates: "/home/{{ user.handle }}/.abuild"
  100. become: yes
  101. - name: build a package
  102. hosts: alpine-builder
  103. become_method: su
  104. become_user: "{{ user.handle }}"
  105. vars:
  106. package:
  107. name: community/gitea
  108. version: 1.11.3-r0
  109. user:
  110. name: GERCZEI, Tamas
  111. email: tamas@gerczei.eu
  112. handle: tgerczei
  113. tasks:
  114. - name: build and fetch package
  115. block:
  116. - name: modify APKBUILD
  117. copy:
  118. src: "/home/{{ user.handle }}/alpine-{{ package.name | basename }}/APKBUILD_{{ package.version }}"
  119. dest: "/home/{{ user.handle }}/aports/{{ package.name }}/APKBUILD"
  120. register: apkbuild
  121. when: repo is changed
  122. - command: abuild -q checksum
  123. args:
  124. chdir: "/home/{{ user.handle }}/aports/{{ package.name }}"
  125. when: apkbuild is changed
  126. - name: build package
  127. command: abuild -qrc
  128. args:
  129. chdir: "/home/{{ user.handle }}/aports/{{ package.name }}"
  130. creates: "/home/{{ user.handle }}/packages/{{ package.name | dirname }}/x86_64"
  131. - name: obtain package
  132. fetch:
  133. src: "/home/{{ user.handle }}/packages/{{ package.name | dirname }}/x86_64/{{ package.name | basename }}-{{ package.version }}.apk"
  134. dest: "/home/{{ user.handle }}/alpine-{{ package.name | basename }}/packages/"
  135. flat: yes
  136. become: yes