This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_containers.sh
executable file
·110 lines (83 loc) · 3.18 KB
/
build_containers.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# © Copyright 2020-2020 UCAR
# This software is licensed under the terms of the Apache Licence Version 2.0 which can be obtained at
# http://www.apache.org/licenses/LICENSE-2.0.
#------------------------------------------------------------------------
function get_ans {
ans=''
while [[ $ans != y ]] && [[ $ans != n ]]; do
echo $1
read ans < /dev/stdin
if [[ $ans != y ]] && [[ $ans != n ]]; then echo "You must enter y or n"; fi
done
}
#------------------------------------------------------------------------
# This script creates new Singularity and Charliecloud containers from the
# existing Docker containers we use for CI.
if [ $# -lt 1 ]; then
echo "Usage: "
echo "./build_containers.sh <container-name> <tag>"
exit 1
fi
# Stop if anything goes wrong
set -e
# may need to use sudo unless you're running as root
export USE_SUDO=${USE_SUDO:-"y"}
[[ $USE_SUDO =~ [yYtT] ]] && export SUDO="sudo" || unset SUDO
export CNAME=${1:-"gnu-openmpi-dev"}
export TAG=${2:-"beta"}
KEY=$HOME/.ssh/id_rsa
if [[ $(echo ${CNAME} | cut -d- -f1) =~ "intel" ]]; then
echo "=============================================================="
echo " Building Docker Image" ${CNAME}
echo "=============================================================="
mkdir -p context
export DOCKER_BUILDKIT=1
docker build --no-cache --ssh github_ssh_key=${KEY} --progress=plain -f Dockerfile.${CNAME} -t jedi-${CNAME}:${TAG} context 2>&1 | tee build.log
fi
echo "=============================================================="
echo " Building Charliecloud Image" ${CNAME}_${TAG}
echo "=============================================================="
if [[ $(echo ${CNAME} | cut -d- -f1) =~ "tutorial" ]]; then
ans=n # Charliecloud and docker not available for tutorial container
else
get_ans "Build Charliecloud image? (y/n)"
fi
if [[ $ans == y ]] ; then
if [[ $(echo ${CNAME} | cut -d- -f1) =~ "intel" ]]; then
DNAME=jedi-${CNAME}
else
echo "Building Docker image"
DNAME=ch-jedi-${CNAME}
mkdir -p context
$SUDO docker image build --no-cache --pull -t ${DNAME}:${TAG} -f Dockerfile.${CNAME} context
fi
echo "Building Charliecloud image"
mkdir -p containers
$SUDO ch-builder2tar ${DNAME}:${TAG} containers
# rename file if intel
[[ $(echo ${CNAME} | cut -d- -f1) =~ "intel" ]] && \
mv containers/jedi-${CNAME}\:${TAG}.tar.gz containers/ch-${CNAME}\:${TAG}.tar.gz
else
echo "Not building Charliecloud image"
fi
echo "=============================================================="
echo " Building Singularity Image" ${CNAME}_${TAG}
echo "=============================================================="
get_ans "Build Singularity image? (y/n)"
if [[ $ans == y ]] ; then
mkdir -p containers
echo "Building Singularity image"
if [[ ${TAG} == "latest" ]]; then
SNAME=${CNAME}
else
SNAME=${CNAME}_${TAG}
fi
if [[ $(echo ${CNAME} | cut -d- -f1) =~ "intel" ]]; then
$SUDO singularity build containers/jedi-${SNAME}.sif docker-daemon:jedi-${CNAME}:${TAG}
else
$SUDO singularity build containers/jedi-${SNAME}.sif Singularity.${CNAME}
fi
singularity sign containers/jedi-${SNAME}.sif
fi
exit 0