Skip to content

Commit

Permalink
Merge pull request #744 from SquirrelCorporation/bug-prometheus-direc…
Browse files Browse the repository at this point in the history
…tory-perm

[BUG] Set up proper permissions and user context for Prometheus
  • Loading branch information
SquirrelDeveloper authored Feb 14, 2025
2 parents eb49ade + 88db063 commit 05e1c51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 2 additions & 4 deletions prometheus/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Use the official Prometheus base image
FROM prom/prometheus:latest

# Copy your base Prometheus configuration file to the image
COPY prometheus.base.yml /etc/prometheus/prometheus.base.yml

# Copy your custom entrypoint script
COPY entrypoint.sh /entrypoint.sh

USER root
# Ensure the entrypoint script is executable
# Make the entrypoint executable
RUN chmod +x /entrypoint.sh
USER nobody

# Override the default CMD with the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]
7 changes: 6 additions & 1 deletion prometheus/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
BASE_CONFIG="/etc/prometheus/prometheus.base.yml"
DYNAMIC_CONFIG="/etc/prometheus/prometheus.yml"

# Set up the data directory with correct permissions
mkdir -p /prometheus/data
chmod -R 755 /prometheus
chown -R nobody:nobody /prometheus

# Check if values for authentication are provided through environment variables
if [ -n "$PROMETHEUS_USERNAME" ] && [ -n "$PROMETHEUS_PASSWORD" ]; then
echo "Configuring Prometheus with authentication..."
Expand All @@ -15,4 +20,4 @@ else
fi

# Start Prometheus
/bin/prometheus --config.file="$DYNAMIC_CONFIG"
exec su -s /bin/sh nobody -c "/bin/prometheus --config.file=\"$DYNAMIC_CONFIG\""

0 comments on commit 05e1c51

Please sign in to comment.