Skip to content

Commit 06e21fa

Browse files
committed
Image entrypoint script
1 parent 5f82a05 commit 06e21fa

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

grafana/non-prod/docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ RUN echo "Copying dashboard files..."
1616
COPY ./dashboards /var/lib/grafana/dashboards
1717
RUN echo "Dashboard files copied."
1818

19-
# Create run.sh
20-
RUN echo '#!/bin/sh\nexec grafana-server' > /run.sh
19+
COPY run.sh /run.sh
2120
RUN chmod +x /run.sh
2221

2322
# Expose Grafana port
@@ -26,4 +25,5 @@ EXPOSE 3000
2625
# Switch to the non-root user provided by the base image
2726
USER grafana
2827

29-
CMD ["grafana-server", "--homepath=/usr/share/grafana"]
28+
ENTRYPOINT ["/run.sh"]
29+
# CMD ["grafana-server", "--homepath=/usr/share/grafana"]

grafana/non-prod/docker/build_push_to_ecr.sh

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# docker/build_push_to_ecr.sh
2-
31
#!/bin/bash
42

53
# Set variables
@@ -12,6 +10,8 @@ AWS_REGION="eu-west-2"
1210
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
1311
REPOSITORY_NAME="imms-fhir-api-grafana"
1412
IMAGE_TAG="11.0.0-22.04_stable"
13+
LOCAL_IMAGE_NAME="$REPOSITORY_NAME:$IMAGE_TAG"
14+
IMAGE_NAME="$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$LOCAL_IMAGE_NAME"
1515
TAGS="Key=Environment,Value=non-prod Key=Project,Value=immunisation-fhir-api-grafana"
1616
LIFECYCLE_POLICY_FILE="lifecycle-policy.json"
1717

@@ -42,39 +42,23 @@ printf "Building and pushing Docker image to ECR...\n"
4242
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
4343

4444
printf "Building Docker image...\n"
45-
# Build Docker image
46-
# docker build -t $REPOSITORY_NAME:$IMAGE_TAG .
47-
# Build Docker image for linux/amd64 architecture
4845
# Remove existing Docker image if it exists
49-
docker rmi $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:$IMAGE_TAG --force
46+
docker rmi $IMAGE_NAME --force
47+
48+
# Pull the base image for linux/amd64 architecture
5049
docker pull --platform linux/amd64 grafana/grafana:latest
50+
51+
# Build Docker image for linux/amd64 architecture and push to ECR
5152
docker buildx create --use
52-
docker buildx build --platform linux/amd64 -t $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:$IMAGE_TAG --push .
53+
docker buildx build --platform linux/amd64 -t $IMAGE_NAME --push .
5354

5455
# Check if the build was successful
5556
if [ $? -ne 0 ]; then
5657
echo "Docker build failed."
5758
exit 1
5859
fi
5960

60-
printf "Tagging Docker image...\n"
61-
# Tag Docker image
62-
docker tag $REPOSITORY_NAME:$IMAGE_TAG $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:$IMAGE_TAG
63-
64-
# Check if the tag was successful
65-
if [ $? -ne 0 ]; then
66-
echo "Docker tag failed."
67-
exit 1
68-
fi
69-
70-
printf "Pushing Docker image to ECR...\n"
71-
# Push Docker image to ECR
72-
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:$IMAGE_TAG
73-
74-
# Check if the push was successful
75-
if [ $? -ne 0 ]; then
76-
echo "Docker push failed."
77-
exit 1
78-
fi
61+
# Inspect the built image
62+
echo "Image: $LOCAL_IMAGE_NAME"
7963

8064
echo "Docker image built and pushed to ECR successfully."

grafana/non-prod/docker/run.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
echo "Grafana Docker container startup..."
3+
4+
GRAFANA_SERVER_PATH=$(which grafana-server)
5+
if [ -z "$GRAFANA_SERVER_PATH" ]; then
6+
echo "grafana-server not found. Exiting."
7+
exit 1
8+
else
9+
echo "grafana-server found at $GRAFANA_SERVER_PATH"
10+
fi
11+
12+
echo "Starting Grafana with environment variables:"
13+
env | grep GF_
14+
15+
# Check if Grafana configuration exists
16+
if [ ! -f /etc/grafana/grafana.ini ]; then
17+
echo "Grafana configuration not found. Exiting."
18+
exit 1
19+
fi
20+
21+
which grafana-server
22+
23+
# Start Grafana in the foreground
24+
echo "Starting Grafana server..."
25+
exec $GF_PATHS_HOME/bin/grafana-server \
26+
--homepath=$GF_PATHS_HOME \
27+
--config=/etc/grafana/grafana.ini \
28+
--packaging=docker \
29+
cfg:default.paths.data=/var/lib/grafana \
30+
cfg:default.paths.logs=/var/log/grafana \
31+
cfg:default.paths.plugins=/var/lib/grafana/plugins \
32+
cfg:default.paths.provisioning=/etc/grafana/provisioning

0 commit comments

Comments
 (0)