-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-docker.sh
executable file
·43 lines (35 loc) · 1016 Bytes
/
build-docker.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
#!/bin/bash
# Name of the builder
BUILDER_NAME=custom-builder
IMAGE_NAME=darts-wled
PLATFORMS=linux/amd64,linux/arm64
# Parse named arguments
while getopts v:u: flag
do
case "${flag}" in
v) DWLED_VERSION=${OPTARG};;
u) DOCKER_USER=${OPTARG};;
esac
done
# Check if version is set
if [ -z "$DWLED_VERSION" ]; then
echo "Error: Version is required"
exit 1
fi
# Check if version is set
if [ -z "$DOCKER_USER" ]; then
echo "Error: Docker Hub user is required"
exit 1
fi
#Prefix image name with user
IMAGE_NAME=$DOCKER_USER/$IMAGE_NAME
# Check if a builder with the given name exists
docker buildx inspect $BUILDER_NAME > /dev/null 2>&1
if [ $? -ne 0 ]; then
# If the builder does not exist, create it
docker buildx create --name $BUILDER_NAME
fi
# Use the builder
docker buildx use $BUILDER_NAME
# Build and push the image
docker buildx build --platform $PLATFORMS --build-arg="REF=${DWLED_VERSION}" -t $IMAGE_NAME:latest -t $IMAGE_NAME:$DWLED_VERSION --push .