-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_push.sh
executable file
·91 lines (64 loc) · 2.24 KB
/
build_and_push.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
#!/bin/bash
# Build and push Dockerfile from current directory PWD
# Title
echo -e "=============== Re-Installing BuildX ======================\n"
# Re Install BuildX
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
# Title
echo -e "=============== Create new Dockerfile ======================\n"
# Docker Credentials taken from parent script (executing this script)
# Settings
export DOCKER_CLI_EXPERIMENTAL=enabled
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# Inform about current buildx
echo -e "Currently active builder with supported platforms:\n"
# List builder abilities
docker buildx inspect --bootstrap
echo -e "\nTo start build\n>>> Press ENTER"
read
# Check if NO Dockerfile exists
if [ ! -f Dockerfile ]; then echo -e "No Dockerfile found!\nDONE!"; read; exit; fi
# Inform that Dockerfile was found
echo -e "Dockerfile found\n"
# Get name of current directory
nam=${PWD##*/}
# Convert to only lowercase String
nam=${nam,,}
# Get additional Tags
echo -e "What additional tags shall be applied?\n(Comma-separated list)\n"
read -e -p "Tags:" -i $DOCKER_TAGS atags
name=${atags:-experimental}
# Get target platforms
echo -e "\nWhat target platforms?\n(Comma-separated list)\n"
read -e -p "Platforms:" -i $DOCKER_PLATFORMS aplat
echo -e "\n\nDetected tags: $atags\n"
echo -e "Detected platforms: $aplat\n"
echo -e "\nTo start build\n>>> Press ENTER"
# Inform about Container name
echo -e "\n================================================="
echo -e "Container names will be:\n"
# Loop through all builds (one build for one tag)
for i in ${atags//,/ }
do
# Tag generated
tag=$DOCKER_USR/$nam:$i
echo -e "$tag"
done
echo -e "\nBuilt image will be immediately pushed to Docker Hub\n\n>>> Press ENTER\n"
read
# Loop through all builds (one build for one tag)
for i in ${atags//,/ }
do
# Tag generated
tag=$DOCKER_USR/$nam:$i
# Inform about Build
echo -e "Starting BUILDX: =============================\n\n"
# Multi Arch build
docker buildx build --platform ${aplat} -t ${tag} --push .
done
# Done
echo -e "DONE!\n>>> Press ENTER"
read