Skip to content

Commit d5893e5

Browse files
committed
Resolve shellcheck errors.
1 parent 921d068 commit d5893e5

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

grafana/non-prod/docker/build_push_to_ecr.sh

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ dirname=$(dirname "$0")
66
DOCKERFILE_DIR=$(realpath "$dirname")
77
echo "DOCKERFILE_DIR: $DOCKERFILE_DIR"
88

9-
# if parameter not passed, prompt for the environment.
9+
# if parameter not passed, prompt for the environment.
1010
# Do not accept response if it is not one of the following: prod, int, ref, internal-dev
1111
# loop until valid response is received
1212
if [ -z "$1" ]; then
1313
while true; do
1414
read -p "Enter the environment (prod, int, ref, internal-dev): " ENVIRONMENT
15-
case $ENVIRONMENT in
15+
case "$ENVIRONMENT" in
1616
prod|int|ref|internal-dev)
1717
break
1818
;;
@@ -22,7 +22,7 @@ if [ -z "$1" ]; then
2222
esac
2323
done
2424
else
25-
ENVIRONMENT=$1
25+
ENVIRONMENT="$1"
2626
fi
2727
# Check if the environment is valid
2828
if [[ ! "$ENVIRONMENT" =~ ^(prod|int|ref|internal-dev)$ ]]; then
@@ -46,49 +46,47 @@ TAGS='[
4646
LIFECYCLE_POLICY_FILE="lifecycle-policy.json"
4747

4848
# Change to the directory containing the Dockerfile
49-
cd $DOCKERFILE_DIR
49+
if ! cd "$DOCKERFILE_DIR"; then
50+
echo "DOCKERFILE_DIR not found."
51+
exit 1
52+
fi
5053

5154
# Check if Dockerfile exists
5255
if [ ! -f Dockerfile ]; then
53-
echo "Dockerfile not found in the current directory."
56+
echo "Dockerfile not found in DOCKERFILE_DIR."
5457
exit 1
5558
fi
5659

5760
# Create ECR repository if it does not exist
58-
aws ecr describe-repositories --repository-names $REPOSITORY_NAME --region $AWS_REGION > /dev/null 2>&1
59-
60-
if [ $? -ne 0 ]; then
61+
if ! aws ecr describe-repositories --repository-names "$REPOSITORY_NAME" --region "$AWS_REGION" > /dev/null 2>&1; then
6162
echo "Creating ECR repository: $REPOSITORY_NAME"
62-
aws ecr create-repository --repository-name $REPOSITORY_NAME --region $AWS_REGION
63+
aws ecr create-repository --repository-name "$REPOSITORY_NAME" --region "$AWS_REGION"
6364
# Add tags to the repository
64-
aws ecr tag-resource --resource-arn arn:aws:ecr:$AWS_REGION:$ACCOUNT_ID:repository/$REPOSITORY_NAME --tags $TAGS
65+
aws ecr tag-resource --resource-arn "arn:aws:ecr:$AWS_REGION:$ACCOUNT_ID:repository/$REPOSITORY_NAME" --tags "$TAGS"
6566
fi
6667

6768
# Apply lifecycle policy to the ECR repository
68-
aws ecr put-lifecycle-policy --repository-name $REPOSITORY_NAME --lifecycle-policy-text file://$LIFECYCLE_POLICY_FILE --region $AWS_REGION
69+
aws ecr put-lifecycle-policy --repository-name "$REPOSITORY_NAME" --lifecycle-policy-text "file://$LIFECYCLE_POLICY_FILE" --region "$AWS_REGION"
6970

7071
printf "Building and pushing Docker image to ECR...\n"
7172
# Authenticate Docker to ECR
72-
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
73+
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
7374

7475
printf "Building Docker image...\n"
7576
# Remove existing Docker image if it exists
76-
docker rmi $IMAGE_NAME --force
77+
docker rmi "$IMAGE_NAME" --force
7778

7879
# Pull the base image for linux/amd64 architecture
7980
docker pull --platform linux/amd64 grafana/grafana:latest
8081

8182
# Build Docker image for linux/amd64 architecture and push to ECR
8283
docker buildx create --use
83-
docker buildx build --platform linux/amd64 -t $IMAGE_NAME --push .
84-
85-
# Check if the build was successful
86-
if [ $? -ne 0 ]; then
84+
if ! docker buildx build --platform linux/amd64 -t "$IMAGE_NAME" --push .; then
8785
echo "Docker build failed."
8886
exit 1
8987
fi
9088

9189
# Inspect the built image
9290
echo "Image: $LOCAL_IMAGE_NAME"
9391

94-
echo "Docker image built and pushed to ECR successfully."
92+
echo "Docker image built and pushed to ECR successfully."

grafana/non-prod/docker/run.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ if [ ! -f /etc/grafana/grafana.ini ]; then
1818
exit 1
1919
fi
2020

21-
GF_UPDATE_CHECK=false
22-
2321
# Start Grafana in the foreground
2422
echo "Starting Grafana server..."
25-
exec $GF_PATHS_HOME/bin/grafana-server \
26-
--homepath=$GF_PATHS_HOME \
23+
exec "$GF_PATHS_HOME/bin/grafana-server" \
24+
--homepath="$GF_PATHS_HOME" \
2725
--config=/etc/grafana/grafana.ini \
2826
--packaging=docker \
2927
cfg:default.paths.data=/var/lib/grafana \
3028
cfg:default.paths.logs=/var/log/grafana \
3129
cfg:default.paths.plugins=/var/lib/grafana/plugins \
32-
cfg:default.paths.provisioning=/etc/grafana/provisioning
30+
cfg:default.paths.provisioning=/etc/grafana/provisioning

0 commit comments

Comments
 (0)