Skip to content

Commit 5f82a05

Browse files
committed
Wip
1 parent ce4d796 commit 5f82a05

25 files changed

+10804
-357
lines changed

grafana/non-prod/docker/Dockerfile

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
# Use the official Nginx image from the Docker Hub
2-
FROM nginx:alpine
1+
# Use the official Grafana image
2+
FROM grafana/grafana:latest
33

4-
# Copy the HTML file into the Nginx web root
5-
COPY index.html /usr/share/nginx/html/index.html
4+
# Install Python
5+
USER root
6+
RUN echo "Installing Python..." \
7+
&& apk add --no-cache python3 py3-pip \
8+
&& echo "Python installed successfully."
69

7-
# Expose port 80 to the outside world
8-
EXPOSE 80
10+
# Copy provisioning and dashboards
11+
RUN echo "Copying provisioning files..."
12+
COPY ./provisioning /etc/grafana/provisioning
13+
RUN echo "Provisioning files copied."
914

10-
# No need to specify CMD as the base image already has the default command to run Nginx
15+
RUN echo "Copying dashboard files..."
16+
COPY ./dashboards /var/lib/grafana/dashboards
17+
RUN echo "Dashboard files copied."
18+
19+
# Create run.sh
20+
RUN echo '#!/bin/sh\nexec grafana-server' > /run.sh
21+
RUN chmod +x /run.sh
22+
23+
# Expose Grafana port
24+
EXPOSE 3000
25+
26+
# Switch to the non-root user provided by the base image
27+
USER grafana
28+
29+
CMD ["grafana-server", "--homepath=/usr/share/grafana"]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# docker/build_push_to_ecr.sh
2+
3+
#!/bin/bash
4+
5+
# Set variables
6+
7+
dirname=$(dirname "$0")
8+
DOCKERFILE_DIR=$(realpath "$dirname")
9+
echo "DOCKERFILE_DIR: $DOCKERFILE_DIR"
10+
11+
AWS_REGION="eu-west-2"
12+
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
13+
REPOSITORY_NAME="imms-fhir-api-grafana"
14+
IMAGE_TAG="11.0.0-22.04_stable"
15+
TAGS="Key=Environment,Value=non-prod Key=Project,Value=immunisation-fhir-api-grafana"
16+
LIFECYCLE_POLICY_FILE="lifecycle-policy.json"
17+
18+
# Change to the directory containing the Dockerfile
19+
cd $DOCKERFILE_DIR
20+
21+
# Check if Dockerfile exists
22+
if [ ! -f Dockerfile ]; then
23+
echo "Dockerfile not found in the current directory."
24+
exit 1
25+
fi
26+
27+
# Create ECR repository if it does not exist
28+
aws ecr describe-repositories --repository-names $REPOSITORY_NAME --region $AWS_REGION > /dev/null 2>&1
29+
30+
if [ $? -ne 0 ]; then
31+
echo "Creating ECR repository: $REPOSITORY_NAME"
32+
aws ecr create-repository --repository-name $REPOSITORY_NAME --region $AWS_REGION
33+
# Add tags to the repository
34+
aws ecr tag-resource --resource-arn arn:aws:ecr:$AWS_REGION:$ACCOUNT_ID:repository/$REPOSITORY_NAME --tags $TAGS
35+
fi
36+
37+
# Apply lifecycle policy to the ECR repository
38+
aws ecr put-lifecycle-policy --repository-name $REPOSITORY_NAME --lifecycle-policy-text file://$LIFECYCLE_POLICY_FILE --region $AWS_REGION
39+
40+
printf "Building and pushing Docker image to ECR...\n"
41+
# Authenticate Docker to ECR
42+
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
43+
44+
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
48+
# Remove existing Docker image if it exists
49+
docker rmi $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPOSITORY_NAME:$IMAGE_TAG --force
50+
docker pull --platform linux/amd64 grafana/grafana:latest
51+
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+
54+
# Check if the build was successful
55+
if [ $? -ne 0 ]; then
56+
echo "Docker build failed."
57+
exit 1
58+
fi
59+
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
79+
80+
echo "Docker image built and pushed to ECR successfully."

0 commit comments

Comments
 (0)