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.

153 lines
4.1 KiB

---
- name: create an Alpine build container
hosts: localhost
gather_facts: false
collections:
- containers.podman
vars:
alpine_version: 3.11.3
tasks:
- name: check container
podman_container_info:
name: alpine-builder
register: container_info
- name: create container
block:
- name: ensure image is present and fresh
podman_image:
name: docker.io/library/alpine
tag: "{{ alpine_version }}"
force: yes
- podman_container:
name: alpine-builder
image: "alpine:{{ alpine_version }}"
tty: yes
interactive: yes
register: container
when: "'no such container' in container_info.stderr"
- name: register container
add_host:
name: alpine-builder
ansible_connection: podman
changed_when: false
- name: install Python
block:
- raw: apk update
- raw: apk add python3
delegate_to: alpine-builder
when: container is changed
- name: configure a build environment
hosts: alpine-builder
become_method: su
become_user: "{{ user.handle }}"
vars:
user:
name: GERCZEI, Tamas
email: tamas@gerczei.eu
handle: tgerczei
build_config:
- PACKAGER="{{ user.name }} <{{ user.email }}>"
- MAINTAINER="$PACKAGER"
tasks:
- name: update system
apk:
update_cache: yes
upgrade: yes
- name: install Alpine SDK
package:
name: alpine-sdk
- name: configure build system
lineinfile:
path: /etc/abuild.conf
line: "{{ config_line }}"
insertafter: "^#{{ config_line.split('=')[0] }}.*"
loop: "{{ build_config }}"
loop_control:
loop_var: config_line
label: "{{ config_line.split('=')[0] }}"
- name: ensure user exists
user:
name: "{{ user.handle }}"
shell: /bin/sh
groups:
- wheel
- abuild
append: yes
- name: obtain aports tree
block:
- name: configure git
git_config:
name: "{{ item.name }}"
value: "{{ item.value }}"
scope: global
loop: "{{ git_settings }}"
vars:
git_settings:
- name: user.email
value: "{{ user.email }}"
- name: user.name
value: "{{ user.name }}"
- name: clone aports repository
git:
repo: git://git.alpinelinux.org/aports
dest: "/home/{{ user.handle }}/aports"
update: no
register: repo
- name: generate cryptographic key for the build system
command: abuild-keygen -qai
args:
creates: "/home/{{ user.handle }}/.abuild"
become: yes
- name: build a package
hosts: alpine-builder
become_method: su
become_user: "{{ user.handle }}"
vars:
package:
name: community/gitea
version: 1.11.3-r0
user:
name: GERCZEI, Tamas
email: tamas@gerczei.eu
handle: tgerczei
tasks:
- name: build and fetch package
block:
- name: modify APKBUILD
copy:
src: "/home/{{ user.handle }}/alpine-{{ package.name | basename }}/APKBUILD_{{ package.version }}"
dest: "/home/{{ user.handle }}/aports/{{ package.name }}/APKBUILD"
register: apkbuild
when: repo is changed
- command: abuild -q checksum
args:
chdir: "/home/{{ user.handle }}/aports/{{ package.name }}"
when: apkbuild is changed
- name: build package
command: abuild -qrc
args:
chdir: "/home/{{ user.handle }}/aports/{{ package.name }}"
creates: "/home/{{ user.handle }}/packages/{{ package.name | dirname }}/x86_64"
- name: obtain package
fetch:
src: "/home/{{ user.handle }}/packages/{{ package.name | dirname }}/x86_64/{{ package.name | basename }}-{{ package.version }}.apk"
dest: "/home/{{ user.handle }}/alpine-{{ package.name | basename }}/packages/"
flat: yes
become: yes