forked from braughtg/VncNoVncContainerBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bash
More file actions
executable file
·85 lines (75 loc) · 2.24 KB
/
build.bash
File metadata and controls
executable file
·85 lines (75 loc) · 2.24 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
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
# Build and push the multi-architectrue images.
# Modify the following variables as appropraite when building new base inmages.
DOCKER_HUB_USER="farmdata2"
IMAGE="fd2-vnc-novnc-base"
TAG="1.3.0"
PLATFORMS=linux/amd64,linux/arm64
LOCAL_BUILD=0
PUSH=0
while getopts ":dp:" opt
do
case $opt in
d) LOCAL_BUILD=1;;
p) PUSH=1;;
*) echo "Invalid option: -$opt";;
esac
done
# Only check the login and make the builder if we are pushing the images.
if [ "$LOCAL_BUILD" = "0" ] && [ "$PUSH" = "1" ];
then
# Check that the DockerHub user identified above is logged in.
if [ "$(which docker-credential-desktop)" != "" ];
then
LOGGED_IN=$(docker-credential-desktop list | grep "$DOCKER_HUB_USER" | wc -l | cut -f 8 -d ' ')
else
LOGGED_IN=$(docker system info | grep -E 'Username|Registry' | grep "$DOCKER_HUB_USER" | wc -l | cut -f 8 -d ' ')
fi
if [ "$LOGGED_IN" == "0" ];
then
echo "Please log into Docker Hub as $DOCKER_HUB_USER before building images."
echo " Use: docker login"
echo "This allows multi architecture images to be pushed."
exit 255
fi
fi
# Create a builder for this image if it doesn't exist.
BUILDER_NAME=vncbuilder
BUILDER=$(docker buildx ls | grep "$BUILDER_NAME" | wc -l | cut -f 8 -d ' ')
if [ "$BUILDER" == "0" ];
then
echo "Making new builder for $BUILDER_NAME images."
docker buildx create --name "$BUILDER_NAME" --driver docker-container --bootstrap
fi
# Switch to use the builder for this image.
docker buildx use "$BUILDER_NAME"
# Print some info on the images
FULL_IMAGE_NAME="$DOCKER_HUB_USER"/"$IMAGE:$TAG"
echo
echo "Buiding image: $IMAGE"
echo " With tag: $TAG"
if [ "$LOCAL_BUILD" = "1" ];
then
echo "Using Builder: building locally"
else
echo "For platforms: $PLATFORMS"
echo "Using builder: $BUILDER_NAME"
fi
if [ "$PUSH" = "1" ];
then
echo " Pushing to: $DOCKER_HUB_USER"
else
echo " Pushing to: Not pushing image(s)."
fi
echo " Full name: $FULL_IMAGE_NAME"
echo
if [ "$LOCAL_BUILD" = "1" ];
then
docker build -t $FULL_IMAGE_NAME .
elif [ "$PUSH" = "0" ];
then
# Build the image but don't push
docker buildx build --platform "$PLATFORMS" -t $FULL_IMAGE_NAME .
else
# Build and push the images.
docker buildx build --platform "$PLATFORMS" -t $FULL_IMAGE_NAME --push .
fi