generated from ssec-jhu/base-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_push.sh
executable file
·58 lines (47 loc) · 2.13 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
#!/bin/bash
# Check if a tag is provided
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 <username> <password> <image tag>"
exit 1
fi
# Assign the tag and image name to a variable
USER=$1
PASS=$2
TAG=$3
IMAGE_NAME="containers.repo.sciserver.org/ssec-snaptron/snapmine"
# Log in to Docker Hub
echo "-----------------------------------------------------------------------------------"
echo " Logging in to Docker containers.repo.sciserver.org ..."
echo "-----------------------------------------------------------------------------------"
echo "docker login -u $USER -p $PASS containers.repo.sciserver.org"
docker login -u $USER -p $PASS containers.repo.sciserver.org
# Check if the login was successful
if [ $? -ne 0 ]; then
echo "-------------------------- Docker login failed -------------------------------"
exit 1
fi
# Build the Docker image
echo "-----------------------------------------------------------------------------------"
echo " Building Docker image with tag for linux/amd64: $TAG "
echo "-----------------------------------------------------------------------------------"
echo build --no-cache --platform=linux/amd64 -t $IMAGE_NAME:$TAG .
docker build --no-cache --platform=linux/amd64 -t $IMAGE_NAME:$TAG .
# Check if the build was successful
if [ $? -ne 0 ]; then
echo "-------------------------- Docker build failed -------------------------------"
exit 1
fi
# Push the Docker image to the repository
echo "-----------------------------------------------------------------------------------"
echo " Pushing Docker image to repository with tag: $TAG "
echo "-----------------------------------------------------------------------------------"
echo docker push $IMAGE_NAME:$TAG
docker push $IMAGE_NAME:$TAG
# Check if the push was successful
if [ $? -ne 0 ]; then
echo "-------------------------- Docker push failed -------------------------------"
exit 1
fi
echo "-----------------------------------------------------------------------------------"
echo " $IMAGE_NAME:$TAG built and pushed successfully"
echo "-----------------------------------------------------------------------------------"