summaryrefslogtreecommitdiffstats
path: root/xci/scripts/vm/build-dib-os.sh
blob: 7688ee6e5303f7cc64779b79d248d20052ef122d (plain)
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
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2017 SUSE LINUX GmbH.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

ONE_DISTRO=${1:-}

docker_cmd="sudo docker"
# See if we can run docker as regular user.
docker ps &> /dev/null && docker_cmd="docker"
docker_name="docker_xci_builder_${ONE_DISTRO:-all}"

# Destroy previous containers
if eval $docker_cmd ps -a | grep -q ${docker_name} &>/dev/null; then
	echo "Destroying previous container..."
	eval $docker_cmd rm -f ${docker_name}
fi

# Prepare new working directory
dib_workdir="${XCI_CACHE_DIR:-${HOME}/.cache/opnfv_xci_deploy}/clean_vm/images"
[[ ! -d $dib_workdir ]] && mkdir -p $dib_workdir

# Record our information
uid=$(id -u)
gid=$(id -g)

sudo chmod 777 -R $dib_workdir
sudo chown $uid:$gid -R $dib_workdir

echo "Getting the latest docker image..."
eval $docker_cmd pull hwoarang/docker-dib-xci:latest

# Get rid of stale files
rm -rf $dib_workdir/${ONE_DISTRO}.qcow2 \
	$dib_workdir/${ONE_DISTRO}.sha256.txt \
	$dib_workdir/${ONE_DISTRO}.d
echo "Initiating dib build..."
eval $docker_cmd run --name ${docker_name} \
	--rm --privileged=true -e ONE_DISTRO=${ONE_DISTRO} \
	-t -v $dib_workdir:$dib_workdir -w $dib_workdir \
	hwoarang/docker-dib-xci '/usr/bin/do-build.sh'
sudo chown $uid:$gid $dib_workdir/${ONE_DISTRO}.qcow2