mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
241 lines
8.5 KiB
YAML
241 lines
8.5 KiB
YAML
---
|
|
- hosts: dkr
|
|
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.18'
|
|
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: "master"
|
|
cgrates_distribution: "nightly"
|
|
docker_tag: "latest"
|
|
registry_site: "dkr.cgrates.org" # the web site
|
|
registry_name: "registry" # the name of the registry container
|
|
users_filename: "" # the file containing the htpasswd users
|
|
registry_port: 5000
|
|
|
|
dependencies:
|
|
- build-essential
|
|
- git
|
|
- devscripts
|
|
- apt-transport-https
|
|
- ca-certificates
|
|
- gnupg2
|
|
- software-properties-common
|
|
- nginx
|
|
- python3
|
|
- python3-pip
|
|
- virtualenv
|
|
- python3-setuptools
|
|
- apache2-utils
|
|
|
|
build_execs:
|
|
- cgr-engine
|
|
- cgr-console
|
|
- cgr-loader
|
|
- cgr-migrator
|
|
- cgr-tester
|
|
|
|
rootUser : root
|
|
|
|
remote_user: '{{ user }}'
|
|
tasks:
|
|
- name: set cgrates distribution
|
|
set_fact:
|
|
cgrates_distribution: "{{ cgrates_branch }}"
|
|
when: cgrates_branch != "master" or cgrates_branch != "1.0"
|
|
###########################################################################################################################
|
|
###########################################################################################################################
|
|
# install dependencies
|
|
- name: Install dependencies
|
|
become: yes
|
|
apt: name={{ dependencies }} state=present
|
|
###########################################################################################################################
|
|
###########################################################################################################################
|
|
# Prepare for configuration
|
|
- name: Check if NGINX needs to be configured
|
|
become: true
|
|
shell: "ls /etc/nginx/sites-enabled | grep '{{ registry_site }}.vhost'"
|
|
ignore_errors: true
|
|
register: nginxConfig
|
|
|
|
- name: Configure NGINX server
|
|
include: nginx.yaml
|
|
when: nginxConfig.stdout_lines|length < 1 or users_filename|length > 0
|
|
|
|
- name: Enable and start nginx
|
|
systemd:
|
|
name: nginx
|
|
state: started
|
|
masked: no
|
|
enabled: yes
|
|
|
|
- name: Configure docker
|
|
include: docker.yaml
|
|
|
|
###########################################################################################################################
|
|
###########################################################################################################################
|
|
# Install Golang
|
|
- name: install unarchive dependencies (zypper)
|
|
become: yes
|
|
zypper:
|
|
name:
|
|
- gzip
|
|
- tar
|
|
state: present
|
|
when: ansible_pkg_mgr == 'zypper'
|
|
|
|
- name: Install golang
|
|
include: go.yaml
|
|
|
|
###########################################################################################################################
|
|
###########################################################################################################################
|
|
# Install CGRateS
|
|
- name: create cgrates directory
|
|
become: yes
|
|
file:
|
|
state: absent
|
|
dest: '{{ cgrates_dir }}'
|
|
become_user: "{{ user }}"
|
|
|
|
- name: create cgrates directory
|
|
become: yes
|
|
file:
|
|
state: directory
|
|
mode: 'u=rwx,go=rx'
|
|
owner: "{{ user }}"
|
|
group: "{{ user }}"
|
|
dest: '{{ cgrates_dir }}'
|
|
become_user: "{{ user }}"
|
|
|
|
- name: git clone cgrates
|
|
git:
|
|
repo: https://github.com/cgrates/cgrates.git
|
|
dest: '{{ cgrates_dir }}'
|
|
update: yes
|
|
force: yes
|
|
version: "{{ cgrates_branch }}"
|
|
become: yes
|
|
become_user: "{{ user }}"
|
|
|
|
- name: clean go cache
|
|
become: yes
|
|
shell: "go clean --cache"
|
|
environment:
|
|
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
|
|
|
- name: clean go modcache
|
|
become: yes
|
|
shell: "go clean --modcache"
|
|
environment:
|
|
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
|
|
|
- name: build cgrates for docker
|
|
shell: "sh {{ cgrates_dir }}/data/docker/scratch/build.sh"
|
|
environment:
|
|
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
|
args:
|
|
chdir: '{{ cgrates_dir }}/data/docker/scratch'
|
|
|
|
- name: clean go cache after build
|
|
become: yes
|
|
shell: "go clean --cache"
|
|
environment:
|
|
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
|
|
|
- name: clean go modcache after build
|
|
become: yes
|
|
shell: "go clean --modcache"
|
|
environment:
|
|
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
|
|
|
- name: copy certificate authority
|
|
copy:
|
|
remote_src: yes
|
|
src: "/etc/ssl/certs/ca-certificates.crt"
|
|
dest: "{{ cgrates_dir }}/data/docker/scratch/ca-certificates.crt"
|
|
|
|
- name: get git tag
|
|
shell: "git tag -l --points-at HEAD"
|
|
args:
|
|
chdir: '{{ cgrates_dir }}'
|
|
register: gitTagVar
|
|
|
|
- name: get commit
|
|
shell: git log -n1 --format=format:%h
|
|
args:
|
|
chdir: '{{ cgrates_dir }}'
|
|
register: gitCommit
|
|
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
|
|
|
|
- name: get commit
|
|
shell: date +%Y%m%d%H%M%S --date="@$(git log -n1 --format=format:%ct)"
|
|
args:
|
|
chdir: '{{ cgrates_dir }}'
|
|
register: gitDate
|
|
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
|
|
|
|
- name: set cgrates docker_tag
|
|
set_fact:
|
|
docker_tag: "{{ gitDate.stdout }}{{ gitCommit.stdout }}"
|
|
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
|
|
|
|
- name: build Docker image
|
|
become: yes
|
|
shell:
|
|
docker build -t 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} -f="{{ item }}.doker" {{ cgrates_dir }}/data/docker/scratch/;
|
|
args:
|
|
chdir: '{{ cgrates_dir }}/data/docker/scratch'
|
|
with_items: "{{ build_execs }}"
|
|
|
|
- name: push docker image to repo
|
|
become: yes
|
|
shell:
|
|
docker image push 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }};
|
|
with_items: "{{ build_execs }}"
|
|
|
|
- name: tag docker master image
|
|
become: yes
|
|
shell:
|
|
docker tag 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:latest;
|
|
when: cgrates_branch == "master" or cgrates_branch == "1.0"
|
|
with_items: "{{ build_execs }}"
|
|
|
|
- name: push docker master image to repo
|
|
become: yes
|
|
shell:
|
|
docker image push 127.0.0.1:{{ registry_port }}/{{ cgrates_distribution }}/{{ item }}:latest;
|
|
when: cgrates_branch == "master" or cgrates_branch == "1.0"
|
|
with_items: "{{ build_execs }}"
|
|
|
|
- name: clean binar files
|
|
file:
|
|
path: "{{ cgrates_dir }}/data/docker/scratch/{{ item }}"
|
|
state: absent
|
|
with_items: "{{ build_execs }}"
|
|
|
|
- name: remove local docker images
|
|
become: yes
|
|
shell:
|
|
docker image prune -af
|
|
|
|
- name: docker_tag is
|
|
debug:
|
|
msg: "{{ docker_tag }}"
|
|
when: docker_tag != "" |