22317: Define GOPATH for Singularity build
[arvados.git] / tools / compute-images / ansible / roles / compute_singularity / tasks / main.yml
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 - name: Install Singularity dependencies
6   ansible.builtin.apt:
7     name:
8       - build-essential
9       - git
10       - libglib2.0-dev
11       - libseccomp-dev
12       - squashfs-tools
13
14 - name: Create Singularity build directory
15   become: no
16   ansible.builtin.tempfile:
17     state: directory
18     path: "{{ workdir }}"
19     prefix: singularity-build-
20   register: singularity_build
21
22 - name: Clone Singularity
23   become: no
24   ansible.builtin.git:
25     repo: "{{ compute_singularity_url }}"
26     dest: "{{ singularity_build.path }}"
27     version: "v{{ compute_singularity_version }}"
28
29 - name: Create Singularity VERSION file
30   become: no
31   ansible.builtin.copy:
32     content: |
33       {{ compute_singularity_version }}
34     dest: "{{ singularity_build.path }}/VERSION"
35     mode: 0644
36
37 - name: Install Go
38   become: no
39   ansible.builtin.unarchive:
40     src: "https://storage.googleapis.com/golang/go{{ compute_go_version }}.linux-amd64.tar.gz"
41     dest: "{{ singularity_build.path }}"
42     remote_src: yes
43
44 - name: Build Singularity
45   become: no
46   ansible.builtin.command:
47     cmd: "{{ item }}"
48     chdir: "{{ singularity_build.path }}"
49   environment:
50     GOPATH: "{{ singularity_build.path }}/GOPATH"
51     PATH: "{{ singularity_build.path }}/go/bin:{{ ansible_env.PATH }}"
52   loop:
53     - ./mconfig --prefix=/opt/singularity
54     - env -C builddir make
55
56 - name: Install Singularity
57   ansible.builtin.command:
58     cmd: make install
59     chdir: "{{ singularity_build.path }}/builddir"
60   
61 - name: Clean Singularity build directory
62   ansible.builtin.file:
63     path: "{{ singularity_build.path }}"
64     state: absent
65
66 - name: Add Singularity commands to PATH
67   ansible.builtin.file:
68     state: link
69     src: "/opt/singularity/bin/{{ item }}"
70     dest: "/usr/local/bin/{{ item }}"
71   loop:
72     - run-singularity
73     - singularity
74
75 - name: Configure Singularity mksquashfs mem
76   ansible.builtin.lineinfile:
77     create: true
78     path: /opt/singularity/etc/singularity/singularity.conf
79     regexp: "^ *mksquashfs +mem *="
80     line: "mksquashfs mem = {{ compute_mksquashfs_mem }}"
81   when: compute_mksquashfs_mem is defined