Update build script and README for nginx-cache-proxy: improved error messaging and added quick start instructions.
This commit is contained in:
13
README.md
13
README.md
@@ -2,6 +2,19 @@
|
||||
|
||||
An nginx proxy server that caches requests only when explicitly requested via the `X-Cache: 1` header.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Build and run with docker-compose
|
||||
docker-compose up --build
|
||||
|
||||
# Or build with the build script
|
||||
./build.sh
|
||||
|
||||
# Then run the built image
|
||||
docker run -p 3000:3000 docker.site.quack-lab.dev/nginx-cache-proxy:latest
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The nginx configuration implements an inverted caching logic:
|
||||
|
||||
33
build.sh
33
build.sh
@@ -1,19 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURATION - Modify these for your project
|
||||
# ============================================================================
|
||||
|
||||
|
||||
# Docker registry and image name
|
||||
DOCKER_REPO="docker.site.quack-lab.dev"
|
||||
IMAGE_NAME="nginx-cache-proxy"
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# VALIDATE CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
echo "Validating nginx configuration..."
|
||||
nginx -t -c /dev/stdin <<< "$(cat nginx.conf)"
|
||||
docker run --rm -v "$(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro" nginx:alpine nginx -t
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error validating nginx configuration"
|
||||
@@ -23,22 +23,22 @@ fi
|
||||
# ============================================================================
|
||||
# DOCKER BUILD AND TAG
|
||||
# ============================================================================
|
||||
|
||||
|
||||
COMMIT_SHA=$(git rev-parse --short HEAD)
|
||||
IMAGE_BASE="${DOCKER_REPO}/${IMAGE_NAME}"
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Building Docker image..."
|
||||
docker build -t "${IMAGE_BASE}:${COMMIT_SHA}" .
|
||||
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error building agx Docker image"
|
||||
echo "Error building nginx-cache-proxy Docker image"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "Tagging as latest..."
|
||||
docker tag "${IMAGE_BASE}:${COMMIT_SHA}" "${IMAGE_BASE}:latest"
|
||||
|
||||
|
||||
TAGS=$(git tag --points-at HEAD)
|
||||
if [ -n "$TAGS" ]; then
|
||||
echo "Found tags on current commit:"
|
||||
@@ -49,16 +49,16 @@ if [ -n "$TAGS" ]; then
|
||||
fi
|
||||
done <<< "$TAGS"
|
||||
fi
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PUSH IMAGES
|
||||
# ============================================================================
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Pushing Docker images..."
|
||||
docker push "${IMAGE_BASE}:${COMMIT_SHA}"
|
||||
docker push "${IMAGE_BASE}:latest"
|
||||
|
||||
|
||||
if [ -n "$TAGS" ]; then
|
||||
while IFS= read -r tag; do
|
||||
if [ -n "$tag" ]; then
|
||||
@@ -66,11 +66,11 @@ if [ -n "$TAGS" ]; then
|
||||
fi
|
||||
done <<< "$TAGS"
|
||||
fi
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# SUMMARY
|
||||
# ============================================================================
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Build complete! Image pushed as:"
|
||||
echo " - ${IMAGE_BASE}:${COMMIT_SHA}"
|
||||
@@ -82,6 +82,3 @@ if [ -n "$TAGS" ]; then
|
||||
fi
|
||||
done <<< "$TAGS"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user