aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/workspace/tasks/project.yml
blob: 89fea0ae70773684f0643776c82031552d23b9be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
- name: Set project URL
  ansible.builtin.set_fact:
    project_url: '{{ item.url | default(item) }}'

- name: Set project name
  ansible.builtin.set_fact:
    project_name: "{{ item.name | default(project_url | urlsplit('path') | basename | regex_replace('\\.git$', '')) }}"

- name: Set project directory
  ansible.builtin.set_fact:
    project_dir: '{{ workspace_dir }}/{{ project_name }}'

- name: 'Update repository: {{ project_name }}'
  ansible.builtin.git:
    accept_hostkey: true
    dest: '{{ project_dir }}'
    repo: '{{ project_url }}'

- name: Check for Makefile
  ansible.builtin.file:
    path: '{{ project_dir }}/Makefile'
    state: file
  register: makefile_check

- name: This project uses make
  become: true
  when: makefile_check is succeeded
  block:
    - name: Run make
      ansible.builtin.command: make
      args:
        chdir: '{{ project_dir }}'
      register: make_output
      when: makefile_check is succeeded
    
    - name: Show make output
      ansible.builtin.debug:
        var: make_output

- name: Check for docker-compose.yml
  ansible.builtin.file:
    path: '{{ project_dir }}/docker-compose.yml'
    state: file
  register: docker_compose_check

- name: This project uses docker-compose
  become: true
  when: makefile_check is not succeeded and docker_compose_check is succeeded
  block:
    - name: docker-compose pull
      ansible.builtin.command: docker-compose pull
      args:
        chdir: '{{ project_dir }}'

    - name: docker-compose build
      ansible.builtin.command: docker-compose build --force-rm --pull -q
      args:
        chdir: '{{ project_dir }}'

    - name: docker-compose up
      ansible.builtin.command: docker-compose up --remove-orphans -d
      args:
        chdir: '{{ project_dir }}'