Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions grafana/non-prod/docker/build_push_to_ecr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ dirname=$(dirname "$0")
DOCKERFILE_DIR=$(realpath "$dirname")
echo "DOCKERFILE_DIR: $DOCKERFILE_DIR"

# if parameter not passed, prompt for the environment.
# if parameter not passed, prompt for the environment.
# Do not accept response if it is not one of the following: prod, int, ref, internal-dev
# loop until valid response is received
if [ -z "$1" ]; then
while true; do
read -p "Enter the environment (prod, int, ref, internal-dev): " ENVIRONMENT
case $ENVIRONMENT in
case "$ENVIRONMENT" in
prod|int|ref|internal-dev)
break
;;
Expand All @@ -22,7 +22,7 @@ if [ -z "$1" ]; then
esac
done
else
ENVIRONMENT=$1
ENVIRONMENT="$1"
fi
# Check if the environment is valid
if [[ ! "$ENVIRONMENT" =~ ^(prod|int|ref|internal-dev)$ ]]; then
Expand All @@ -46,49 +46,47 @@ TAGS='[
LIFECYCLE_POLICY_FILE="lifecycle-policy.json"

# Change to the directory containing the Dockerfile
cd $DOCKERFILE_DIR
if ! cd "$DOCKERFILE_DIR"; then
echo "DOCKERFILE_DIR not found."
exit 1
fi

# Check if Dockerfile exists
if [ ! -f Dockerfile ]; then
echo "Dockerfile not found in the current directory."
echo "Dockerfile not found in DOCKERFILE_DIR."
exit 1
fi

# Create ECR repository if it does not exist
aws ecr describe-repositories --repository-names $REPOSITORY_NAME --region $AWS_REGION > /dev/null 2>&1

if [ $? -ne 0 ]; then
if ! aws ecr describe-repositories --repository-names "$REPOSITORY_NAME" --region "$AWS_REGION" > /dev/null 2>&1; then
echo "Creating ECR repository: $REPOSITORY_NAME"
aws ecr create-repository --repository-name $REPOSITORY_NAME --region $AWS_REGION
aws ecr create-repository --repository-name "$REPOSITORY_NAME" --region "$AWS_REGION"
# Add tags to the repository
aws ecr tag-resource --resource-arn arn:aws:ecr:$AWS_REGION:$ACCOUNT_ID:repository/$REPOSITORY_NAME --tags $TAGS
aws ecr tag-resource --resource-arn "arn:aws:ecr:$AWS_REGION:$ACCOUNT_ID:repository/$REPOSITORY_NAME" --tags "$TAGS"
fi

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

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

printf "Building Docker image...\n"
# Remove existing Docker image if it exists
docker rmi $IMAGE_NAME --force
docker rmi "$IMAGE_NAME" --force

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

# Build Docker image for linux/amd64 architecture and push to ECR
docker buildx create --use
docker buildx build --platform linux/amd64 -t $IMAGE_NAME --push .

# Check if the build was successful
if [ $? -ne 0 ]; then
if ! docker buildx build --platform linux/amd64 -t "$IMAGE_NAME" --push .; then
echo "Docker build failed."
exit 1
fi

# Inspect the built image
echo "Image: $LOCAL_IMAGE_NAME"

echo "Docker image built and pushed to ECR successfully."
echo "Docker image built and pushed to ECR successfully."
8 changes: 3 additions & 5 deletions grafana/non-prod/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ if [ ! -f /etc/grafana/grafana.ini ]; then
exit 1
fi

GF_UPDATE_CHECK=false

# Start Grafana in the foreground
echo "Starting Grafana server..."
exec $GF_PATHS_HOME/bin/grafana-server \
--homepath=$GF_PATHS_HOME \
exec "$GF_PATHS_HOME/bin/grafana-server" \
--homepath="$GF_PATHS_HOME" \
--config=/etc/grafana/grafana.ini \
--packaging=docker \
cfg:default.paths.data=/var/lib/grafana \
cfg:default.paths.logs=/var/log/grafana \
cfg:default.paths.plugins=/var/lib/grafana/plugins \
cfg:default.paths.provisioning=/etc/grafana/provisioning
cfg:default.paths.provisioning=/etc/grafana/provisioning