Files
cgrates/data/ansible/deb_packages/main.yaml
2025-02-21 13:22:04 +01:00

374 lines
13 KiB
YAML

---
- hosts: apt
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.24'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'
# Base installation directory the Go language SDK distribution
golang_install_dir: '/usr/local/go'
# Directory to store files downloaded for Go language SDK installation
golang_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"
# Location for GOPATH environment variable
golang_gopath: "/home/{{ user }}/go"
# Filename of Go language SDK redistributable package
golang_redis_filename: 'go{{ golang_version }}.linux-amd64.tar.gz'
###############################################################
# CGRateS vars
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
cgrates_branch: "1.0"
cgrates_distribution: "nightly"
###############################################################
######################## GPG Vars #############################
###############################################################
gpg_home: "/root"
gpg_realname: "CGRateS"
gpg_useremail: "cgrates@itsyscom.com"
gpg_pubkeyfileexport: "apt.cgrates.org.gpg.key"
gpg_keylength: 2048
gpg_subkeylength: 2048
gpg_expire: 360
rootUser : root
customPath: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
dependencies:
- build-essential
- cowbuilder
- debhelper
- devscripts
- dh-golang
- distro-info
- dpkg-dev
- git
- pbuilder
- reprepro
- nginx
distributions:
- codename: bookworm
version: 12
- codename: bullseye
version: 11
remote_user: "{{ user }}"
tasks:
- name: set cgrates cgrates_distribution
set_fact:
cgrates_distribution: "{{ cgrates_distribution }}"
###########################################################################################################################
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
###########################################################################################################################
###########################################################################################################################
# Prepare for configuration
- name: Config reprepro
include: reprepro.yaml
- name: Generate GPG Key
include: gpg.yaml
- name: Check if NGINX needs to be configured
become: true
shell: "ls /etc/nginx/sites-enabled | grep 'apt.cgrates.org.vhost'"
ignore_errors: true
register: nginxConfig
- name: Configure NGINX server
include: nginx.yaml
when: nginxConfig.stdout_lines|length < 1
- name: Enable and start nginx
systemd:
name: nginx
state: started
masked: no
enabled: yes
###########################################################################################################################
###########################################################################################################################
# Install Golang
- name: install unarchive dependencies (zypper)
become: yes
zypper:
name:
- gzip
- tar
state: present
when: ansible_pkg_mgr == 'zypper'
- name: Create chroots
become: yes
command: "cowbuilder --create --distribution {{ item.codename }} --architecture amd64 --basepath /var/cache/pbuilder/base-{{ item.codename }}+go.cow --mirror http://deb.debian.org/debian --components main"
args:
creates: "/var/cache/pbuilder/base-{{ item.codename }}+go.cow"
with_items: "{{ distributions }}"
- name: Check Go tarball
stat:
path: "/usr/local/src/{{ go_tarball }}"
register: downloaded_go_tarball
- name: Download Go tarball
become: yes
get_url:
url: "{{ go_download_url }}"
dest: "/usr/local/src/{{ go_tarball }}"
checksum: "sha256:{{ go_checksum }}"
when: not downloaded_go_tarball.stat.exists
- name: Install Go in chroots
become: yes
unarchive:
src: "/usr/local/src/{{ go_tarball }}"
dest: "/var/cache/pbuilder/base-{{ item.codename }}+go.cow/usr/local"
copy: no
creates: "/var/cache/pbuilder/base-{{ item.codename }}+go.cow/usr/local/go"
with_items: "{{ distributions }}"
- name: Customize .bashrc in chroots
become: true
template:
src: bashrc.j2
dest: "/var/cache/pbuilder/base-{{ item.codename }}+go.cow/root/.bashrc"
mode: "0644"
owner: "root"
group: "root"
with_items: "{{ distributions }}"
- name: Customize .pbuilderrc
template:
src: pbuilderrc.j2
dest: "/home/{{ user }}/.pbuilderrc"
mode: "0644"
- name: Check update timestamp
stat:
path: "/var/cache/pbuilder/update-timestamp"
register: update_timestamp
- name: Update chroots
become: yes
command: "cowbuilder --update --basepath /var/cache/pbuilder/base-{{ item.codename }}+go.cow"
with_items: "{{ distributions }}"
when: not update_timestamp.stat.exists or update_timestamp.stat.mtime <= (ansible_date_time.epoch | int - 86400)
register: update_chroots
- name: Update timestamp
become: yes
file:
path: "/var/cache/pbuilder/update-timestamp"
state: touch
when: update_chroots.changed
###########################################################################################################################
###########################################################################################################################
# Install CGRateS
- name: create cgrates directory
file:
state: directory
mode: 'u=rwx,go=rx'
owner: "{{ user }}"
group: "{{ user }}"
dest: "{{ cgrates_dir }}"
- name: git clone cgrates
git:
repo: https://github.com/cgrates/cgrates.git
dest: '{{ cgrates_dir }}'
update: yes
force: yes
version: "{{ cgrates_branch }}"
- name: clean go cache
shell: "go clean --cache"
environment:
PATH: "{{ customPath }}"
- name: clean go modcache
shell: "go clean --modcache"
environment:
PATH: "{{ customPath }}"
- name: sync the go mod with vendor
shell: "go mod vendor"
environment:
PATH: "{{ customPath }}"
args:
chdir: '{{ cgrates_dir }}'
- name: build cgrates
shell: "sh {{ cgrates_dir }}/build.sh"
environment:
PATH: "{{ customPath }}"
args:
chdir: '{{ cgrates_dir }}'
- name: symbol link
become: yes
file:
src: "{{ cgrates_dir }}/data"
dest: "/usr/share/cgrates"
state: link
- name: get git tag
shell: "git tag -l --points-at HEAD"
args:
chdir: '{{ cgrates_dir }}'
register: gitTagVar
###########################################################################################################################
###########################################################################################################################
# Generate package
- name: Generate packages
command: 'env "DISTRIBUTION={{ item.codename }}" make -C packages deb'
args:
chdir: "{{ cgrates_dir }}"
with_items: "{{ distributions }}"
- name: Check if the packages were generated
shell: "ls /home/{{ user }}/go/src/github.com/cgrates | grep -E 'cgrates(-dbgsym)?_'"
ignore_errors: true
register: packagesVar
- name: Move the files to /var/packages/debian/incoming
become: yes
command: mv {{item}} /var/packages/debian/incoming/
args:
chdir: "/home/{{ user }}/go/src/github.com/cgrates"
when: packagesVar.stdout_lines|length > 0
with_items: "{{ packagesVar.stdout_lines }}"
- name: Get the name of the deb files
shell: "ls /var/packages/debian/incoming/ | grep -E '.(build|buildinfo|changes|deb|debian.tar.*|dsc|orig.*.tar.*)$'"
register: packageFileNames
- name: Include the packages with reprepro
become: yes
shell: reprepro -Vb . --ignore=wrongdistribution include {{ cgrates_branch }}-{{ item.codename }} /var/packages/debian/incoming/*~deb{{ item.version }}u1_amd64.changes
args:
chdir: /var/packages/debian
with_items: "{{ distributions }}"
when: cgrates_branch == "master" or gitTagVar.stdout_lines|length > 0
# Include the package with reprepro
- name : Include the package with reprepro
become: yes
command: sudo reprepro -A amd64 -Vb . include {{ cgrates_distribution }} /var/packages/debian/incoming/{{ item }}
ignore_errors: true
args :
chdir: /var/packages/debian
with_items: '{{ changesFileNames.stdout_lines }}'
when : cgrates_branch == "master" or gitTagVar.stdout_lines|length > 0
# Move the file to PKG server
- name: Copy the file to PKG server
shell: 'scp /var/packages/debian/incoming/{{ item }} {{ pkgAddr }}:/tmp/'
args:
chdir: /var/packages/debian/incoming/
with_items: "{{ packageFileNames.stdout_lines }}"
# Clean the incoming folder
- name: Clean the incoming folder
become: yes
shell: "rm /var/packages/debian/incoming/*"
args:
chdir: /var/packages/debian
- hosts: pkg
vars:
nginx_user: "www-data"
cgrates_branch: "master"
distributions:
- codename: bookworm
version: 12
- codename: bullseye
version: 11
tasks:
- name: set cgrates cgrates_distribution
set_fact:
cgrates_distribution: "{{ hostvars['apt']['cgrates_distribution'] }}"
- name: Create directory
become: yes
file:
path: /var/packages/deb/{{ cgrates_branch }}/{{ item.codename }}
state: directory
mode: "0775"
owner: "{{ nginx_user }}"
group: "{{ nginx_user }}"
with_items: "{{ distributions }}"
- name: Remove symlink from current deb package
become: yes
file:
path: /var/packages/deb/{{ cgrates_branch }}/{{ item.codename }}/cgrates_current_amd64.deb
state: absent
with_items: "{{ distributions }}"
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- name: Move the new .orig.tar.gz to /var/packages/deb
become: yes
shell: "mv /tmp/cgrates*.orig*.tar.* /var/packages/deb/{{ cgrates_branch }}/"
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- name: Move the new package to /var/packages/deb
become: yes
shell: "mv /tmp/cgrates*~deb{{ item.version }}u1* /var/packages/deb/{{ cgrates_branch }}/{{ item.codename }}/"
with_items: "{{ distributions }}"
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- name: Find all package files
become: yes
find:
path: "/var/packages/deb/{{ cgrates_branch }}/"
patterns: "*.deb"
recurse: yes
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
register: package_files
- name: Set ownership and permissions for moved files
become: yes
file:
path: "{{ item.path }}"
owner: "{{ nginx_user }}"
group: "{{ nginx_user }}"
mode: "0644"
loop: "{{ package_files.files }}"
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- name: Find package files per distribution
become: yes
find:
path: "/var/packages/deb/{{ cgrates_branch }}/{{ item.codename }}/"
patterns: "cgrates_*_amd64.deb"
with_items: "{{ distributions }}"
register: distribution_package_files
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- set_fact:
latest_file: "{{ item.files | sort(attribute='mtime', reverse=true) | first }}"
with_items: "{{ distribution_package_files.results }}"
register: latest_files
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
- name: Create the new symlink cgrates_current_amd64.deb
become: yes
file:
src: "{{ item.ansible_facts.latest_file.path }}"
dest: /var/packages/deb/{{ cgrates_branch }}/{{ item.item.item.codename }}/cgrates_current_amd64.deb
state: link
with_items: "{{ latest_files.results }}"
when: cgrates_branch == "master" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0