-
Notifications
You must be signed in to change notification settings - Fork 1
/
updatebase.sh
35 lines (27 loc) · 1.07 KB
/
updatebase.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
#!/bin/bash
OVERLAYDIR=/mnt/disk01/docker/overlay2
SOURCETAG=$1
TARGETTAG=$2
#安装jq
#yum install -y jq
TMPDIR=$OVERLAYDIR/tmp/BASE-$TARGETTAG/diff
mkdir -p $TMPDIR
cd $TMPDIR/../..
#如果tmp/baseimg.properties文件存在,从中读取基础镜像最上层目录base.dir和原版本号,否则从源基础镜像中获取
if [ -f "baseimg.properties" ]; then
UpperDir=`grep "base.dir" baseimg.properties | cut -d'=' -f2 | sed 's/\r//'`
BaseVer=`grep "base.ver" baseimg.properties | cut -d'=' -f2 | sed 's/\r//'`
else
UpperDir=`docker inspect $SOURCEIMG:$SOURCETAG |jq .[0].GraphDriver.Data.UpperDir |sed 's/\"//g'`
BaseVer=$SOURCETAG
echo "base.dir=$UpperDir" > baseimg.properties
echo "base.ver=$SOURCETAG" >> baseimg.properties
fi
#备份源最上层目录
mkdir -p $TMPDIR/../../backup/$BaseVer
\cp -af $UpperDir/* $TMPDIR/../../backup/$BaseVer/
#解压变更文件包再覆盖基础镜像目录/diff
cd $TMPDIR/../..
tar -xvzf BASE-$TARGETTAG-diff.tar.gz -C $TMPDIR/../
\cp -af $TMPDIR/* $UpperDir/
sed -i "s#^base.ver=.*#base.ver=$TARGETTAG#g" $TMPDIR/../../baseimg.properties