-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave
More file actions
executable file
·39 lines (32 loc) · 1.74 KB
/
save
File metadata and controls
executable file
·39 lines (32 loc) · 1.74 KB
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
#!/bin/bash
source ./bits/bootstrap/logging
export DOCKER_ASSETS_DIR=${DOCKER_ASSETS_DIR-./assets/dockerimages}
IMAGE_NAME=${IMAGE_NAME-$NAME:$VERSION}
DOCKER_IMAGE_FILE=$DOCKER_ASSETS_DIR/${NAME}.${VERSION}.tar
LATEST_IMAGE_FILE=$DOCKER_ASSETS_DIR/${NAME}.latest.tar
SAVE_OUTPUT=${LAUNCHER_DIR}/docker_save.log
BUILD_OUTPUT=${LAUNCHER_DIR}/docker_build.log
OWNER=${OWNER-$USER}
if [[ -e $BUILD_OUTPUT ]] && [[ ! -z `tail -n 4 $BUILD_OUTPUT | grep "Using cache"` ]] && [[ -e $DOCKER_IMAGE_FILE.gz ]]; then
notify " -- No changes to $IMAGE_NAME, not overwriting $DOCKER_IMAGE_FILE.gz"
elif [[ "$DOCKER_ASSETS_SERVER" != "local" ]]; then
DOCKER_ASSETS_DIR=/tmp OWNER=$OWNER LAUNCHER_DIR=$LAUNCHER_DIR NAME=$NAME VERSION=$VERSION ./bits/docker/save
[ $? -ne 0 ] && exit 1
notify " -- Uploading /tmp/${NAME}.${VERSION}.tar.gz to $DOCKER_ASSETS_DIR/${NAME}.${VERSION}.tar"
scp /tmp/${NAME}.${VERSION}.tar.gz $DOCKER_ASSETS_DIR/${NAME}.${VERSION}.tar.gz
else
OWNER=$OWNER ./bits/bootstrap/mkdir DOCKER_ASSETS_DIR
[ $? -ne 0 ] && exit 1
notify " -- Saving $IMAGE_NAME to $DOCKER_IMAGE_FILE.gz"
debug " -- Creating $DOCKER_IMAGE_FILE"
SCRIPT_OUTPUT=$(docker save -o $DOCKER_IMAGE_FILE $IMAGE_NAME > $SAVE_OUTPUT 2>&1)
ERROR="Unable to save $IMAGE_NAME to $DOCKER_IMAGE_FILE due to ..." ./bits/bootstrap/failonerrors $? $SAVE_OUTPUT
[ $? -ne 0 ] && exit 1
debug " -- Compressing to $DOCKER_IMAGE_FILE.gz"
rm -f $DOCKER_IMAGE_FILE.gz
SCRIPT_OUTPUT=$(gzip $DOCKER_IMAGE_FILE > $SAVE_OUTPUT 2>&1)
ERROR="Unable to gzip $DOCKER_IMAGE_FILE due to ..." ./bits/bootstrap/failonerrors $? $SAVE_OUTPUT
[ $? -ne 0 ] && exit 1
OWNER=$OWNER ./bits/bootstrap/touch $DOCKER_IMAGE_FILE.gz
debug " -- DONE, Saving $IMAGE_NAME to $DOCKER_IMAGE_FILE.gz"
fi