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 pathpush_containers.sh
executable file
·149 lines (123 loc) · 5.67 KB
/
push_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/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 pushes Singularity and Charliecloud containers to Sylabs cloud
# or AWS S3, optionally making a backup.
#
# For intel containers, it will also push the Docker image to a private area
# on AWS S3
if [ $# -lt 1 ]; then
echo "Usage: "
echo "./push_containers.sh <container-name> <tag>"
exit 1
fi
# 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"}
if [[ $(echo ${CNAME} | cut -d- -f1) =~ "intel" ]]; then
echo "=============================================================="
echo " Pushing Docker Container" ${CNAME}-${TAG}
echo "=============================================================="
get_ans 'Push Docker container to S3 and replace latest? (y/n)'
if [[ $ans == y ]] ; then
mkdir -p containers
sudo docker save jedi-${CNAME}:${TAG} | gzip > containers/docker-${CNAME}-${TAG}.tar.gz
echo "Sending to Amazon S3"
if [[ ${TAG} == "beta" ]]; then
aws s3api head-object --bucket privatecontainers --key docker-jedi-${CNAME}.tar.gz && file_exists=true || file_exists=false
if [ ${file_exists} ]; then
echo "Saving previous container as revert"
aws s3 mv s3://privatecontainers/docker-jedi-${CNAME}.tar.gz s3://privatecontainers/docker-jedi-${CNAME}-revert.tar.gz
fi
aws s3 cp containers/docker-${CNAME}-${TAG}.tar.gz s3://privatecontainers/docker-jedi-${CNAME}.tar.gz
else
aws s3 cp containers/docker-${CNAME}-${TAG}.tar.gz s3://privatecontainers/docker-jedi-${CNAME}-${TAG}.tar.gz
fi
fi
fi
echo "=============================================================="
echo " Pushing Charliecloud Container" ${CNAME}-${TAG}
echo "=============================================================="
get_ans 'Push Charliecloud container? (y/n)'
if [[ $ans == y ]] ; then
if [[ $(echo $CNAME| cut -d- -f1) == "intel" ]]; then
echo "Pushing Charliecloud container to Amazon S3 (private)"
if [[ ${TAG} == "beta" ]]; then
aws s3api head-object --bucket privatecontainers --key ch-jedi-${CNAME}.tar.gz && file_exists=true
if [ ${file_exists} ]; then
echo "Saving previous container as revert"
aws s3 mv s3://privatecontainers/ch-jedi-${CNAME}.tar.gz s3://privatecontainers/ch-jedi-${CNAME}-revert.tar.gz
fi
echo "Pushing to AWS S3"
aws s3 cp containers/ch-jedi-${CNAME}\:${TAG}.tar.gz s3://privatecontainers/ch-jedi-${CNAME}.tar.gz
else
echo "Pushing to AWS S3"
aws s3 cp containers/ch-jedi-${CNAME}\:${TAG}.tar.gz s3://privatecontainers/ch-jedi-${CNAME}-${TAG}.tar.gz
fi
else
echo "Pushing Charliecloud container to Amazon S3"
if [[ ${TAG} == "beta" ]]; then
aws s3api head-object --bucket data.jcsda.org --key containers/ch-jedi-${CNAME}.tar.gz && file_exists=true || file_exists=false
if [ ${file_exists} ]; then
echo "Saving previous container as revert"
aws s3 mv s3://data.jcsda.org/containers/ch-jedi-${CNAME}.tar.gz s3://data.jcsda.org/containers/ch-jedi-${CNAME}-revert.tar.gz
fi
aws s3 cp containers/ch-jedi-${CNAME}\:${TAG}.tar.gz s3://data.jcsda.org/containers/ch-jedi-${CNAME}.tar.gz
else
aws s3 cp containers/ch-jedi-${CNAME}\:${TAG}.tar.gz s3://data.jcsda.org/containers/ch-jedi-${CNAME}-${TAG}.tar.gz
fi
fi
else
echo "Not pushing Charliecloud container"
fi
echo "=============================================================="
echo " Pushing Singularity Container" ${CNAME}_${TAG}
echo "=============================================================="
get_ans "Push Singularity container? (y/n)"
if [[ $ans == y ]] ; then
if [[ $(echo $CNAME| cut -d- -f1) == "intel" ]]; then
if [[ ${TAG} == "beta" ]]; then
aws s3api head-object --bucket privatecontainers --key jedi-${CNAME}.sif && file_exists=true
if [ ${file_exists} ]; then
echo "Saving previous container as revert"
aws s3 mv s3://privatecontainers/jedi-${CNAME}.sif s3://privatecontainers/jedi-${CNAME}-revert.sif
fi
echo "Pushing to AWS S3 (private)"
aws s3 cp containers/jedi-${CNAME}_${TAG}.sif s3://privatecontainers/jedi-${CNAME}.sif
else
echo "Pushing to AWS S3 (private)"
aws s3 cp containers/jedi-${CNAME}_${TAG}.sif s3://privatecontainers/jedi-${CNAME}_${TAG}.sif
fi
else # push gnu and clang containers to sylabs cloud
echo "Pushing to sylabs cloud"
if [[ ${TAG} == "beta" ]]; then
get_ans "Make backup image on sylabs cloud?"
if [[ $ans == y ]] ; then
echo "Creating backup image"
singularity pull --force library://jcsda/public/jedi-${CNAME}:latest
singularity push jedi-${CNAME}_latest.sif library://jcsda/public/jedi-${CNAME}:revert
rm jedi-${CNAME}_latest.sif
else
echo "Not making backup image on sylabs cloud"
fi
singularity push containers/jedi-${CNAME}_${TAG}.sif library://jcsda/public/jedi-${CNAME}:latest
else
singularity push containers/jedi-${CNAME}_${TAG}.sif library://jcsda/public/jedi-${CNAME}:${TAG}
fi
fi
else
echo "Not pushing Singularity container"
fi