-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_build.sh
More file actions
33 lines (24 loc) · 857 Bytes
/
docker_build.sh
File metadata and controls
33 lines (24 loc) · 857 Bytes
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
#!/usr/bin/env bash
# Default values
DOCKER_TAG="avirupdas55/jax:v2"
DOCKER_ID="avirupdas55"
# Check if user provided tag name as argument
if [ -n "$1" ]; then
DOCKER_TAG="$DOCKER_ID/$1"
fi
# Check if user provided Docker Hub ID as argument
if [ -n "$2" ]; then
DOCKER_ID="$2"
fi
echo "Building Docker image with tag: $DOCKER_TAG"
DOCKER_BUILDKIT=1 docker build --platform linux/amd64 -t $DOCKER_TAG .
# Check if the user is already logged in to Docker Hub
if ! docker info --format '{{.RegistryConfig.IndexConfigs}}' | grep -q "$DOCKER_ID"; then
echo "Logging in to Docker Hub as $DOCKER_ID"
docker login
fi
# Tag the Docker image
docker tag $DOCKER_TAG $DOCKER_ID/$DOCKER_TAG
# Push the Docker image to Docker Hub
docker push $DOCKER_ID/$DOCKER_TAG
echo "Docker image has been built and pushed to Docker Hub with tag: $DOCKER_TAG"