Skip to content

Commit d0d8154

Browse files
author
Yuriy Bezsonov
committed
change build
1 parent 9334299 commit d0d8154

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

infrastructure/scripts/deploy/build-and-push.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
77
# Use a single variable for app name, repository, service, and cluster
88
APP_NAME="workshop-app"
99

10+
# Check if a Dockerfile path was provided as an argument
11+
DOCKERFILE_PATH="$1"
12+
if [ -z "$DOCKERFILE_PATH" ]; then
13+
# No path provided, use default Dockerfile in script directory
14+
DOCKERFILE_PATH="$SCRIPT_DIR/Dockerfile"
15+
BUILD_CONTEXT="$SCRIPT_DIR"
16+
echo "Using default Dockerfile at $DOCKERFILE_PATH"
17+
else
18+
# Use the provided Dockerfile path
19+
if [ ! -f "$DOCKERFILE_PATH" ]; then
20+
echo "Error: Dockerfile not found at $DOCKERFILE_PATH"
21+
exit 1
22+
fi
23+
# Use the directory of the provided Dockerfile as build context
24+
BUILD_CONTEXT="$(dirname "$DOCKERFILE_PATH")"
25+
echo "Using Dockerfile at $DOCKERFILE_PATH"
26+
fi
27+
1028
echo "Building and pushing Docker image to ECR in region $AWS_REGION"
1129

1230
# Login to ECR
1331
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
1432

15-
# Change to the script directory where Dockerfile is located
16-
cd "$SCRIPT_DIR"
17-
1833
# Build the Docker image
19-
docker build -t $APP_NAME -f Dockerfile .
34+
docker build -t $APP_NAME -f "$DOCKERFILE_PATH" "$BUILD_CONTEXT"
2035

2136
# Tag the image
2237
docker tag $APP_NAME:latest $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$APP_NAME:latest

0 commit comments

Comments
 (0)