Path: blob/master/buildenv/ansible/roles/openj9-build-environment/tasks/main.yml
13608 views
###############################################################################1# Copyright (c) 2018, 2018 Pavel Samolysov2#3# This program and the accompanying materials are made available under4# the terms of the Eclipse Public License 2.0 which accompanies this5# distribution and is available at https://www.eclipse.org/legal/epl-2.0/6# or the Apache License, Version 2.0 which accompanies this distribution and7# is available at https://www.apache.org/licenses/LICENSE-2.0.8#9# This Source Code may also be made available under the following10# Secondary Licenses when the conditions for such availability set11# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12# General Public License, version 2 with the GNU Classpath13# Exception [1] and GNU General Public License, version 2 with the14# OpenJDK Assembly Exception [2].15#16# [1] https://www.gnu.org/software/classpath/license.html17# [2] http://openjdk.java.net/legal/assembly-exception.html18#19# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20###############################################################################21# Copyright (c) 2020, 2021 IBM Corp. and others22###############################################################################23---24- name: Create a build folder25file:26dest: "{{ build_dir }}"27mode: 075528state: directory29tags:30- buildenv31- name: Get script to build docker image32get_url:33dest: "{{ build_dir }}/mkdocker.sh"34url: "https://raw.githubusercontent.com/eclipse-openj9/openj9/master/buildenv/docker/mkdocker.sh"35mode: 064436validate_certs: no37tags:38- buildenv39- name: Build the docker image for the building environment40command: bash mkdocker.sh --tag=openj9-{{ version }}-build --dist=ubuntu --version=16.04 --build41tags:42- buildenv43- name: Create a build result folder44file:45dest: "{{ host_dir }}"46mode: 075547state: directory48tags:49- buildenv50- name: Start the building environment as a docker container51docker_container:52name: "openj9-{{ version }}-build"53image: "openj9-{{ version }}-build:latest"54state: started55restart: yes # without restart, the container wouldn't be able to touch any file in the host_dir folder56interactive: yes # without interactive, the container would be stopped just after it has been started57volumes: "{{ host_dir }}:/root/hostdir"58tags:59- buildenv60- name: Get the ansible user61command: whoami62register: ansible_user63tags:64- buildenv65- build66- name: Get the ansible uid67shell: "id {{ ansible_user.stdout }} | awk -F'uid=' '{printf \"%d\", $2}'"68register: ansible_uid69tags:70- buildenv71- name: Get the ansible group72shell: "groups {{ ansible_user.stdout }} | awk -F' ' '{printf \"%s\", $3}'"73register: ansible_group74tags:75- buildenv76- build77- name: Get the ansible gid78shell: "id {{ ansible_user.stdout }} | awk -F'gid=' '{printf \"%d\", $2}'"79register: ansible_gid80tags:81- buildenv82- name: Add the container to inventory83add_host:84name: "openj9-{{ version }}-build"85ansible_connection: docker86ansible_user: root87changed_when: false88tags:89- buildenv90- build91- name: Install python to the container if there is no one92raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)93delegate_to: "openj9-{{ version }}-build"94tags:95- buildenv96- name: Add group "{{ target.group }}"97group:98name: "{{ target.group }}"99gid: "{{ target.groupid }}"100delegate_to: "openj9-{{ version }}-build"101tags:102- buildenv103- name: Add user "{{ target.user }}"104user:105name: "{{ target.user }}"106uid: "{{ target.userid }}"107group: "{{ target.group }}"108createhome: no109shell: /sbin/nologin110delegate_to: "openj9-{{ version }}-build"111tags:112- buildenv113- name: Add group "{{ ansible_group.stdout }}"114group:115name: "{{ ansible_group.stdout }}"116gid: "{{ ansible_gid.stdout }}"117delegate_to: "openj9-{{ version }}-build"118tags:119- buildenv120- name: Add user "{{ ansible_user.stdout }}"121user:122name: "{{ ansible_user.stdout }}"123uid: "{{ ansible_uid.stdout }}"124group: "{{ ansible_group.stdout }}"125createhome: no126shell: /sbin/nologin127delegate_to: "openj9-{{ version }}-build"128tags:129- buildenv130131132