This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
# Build output
|
||||||
|
dist/
|
||||||
|
|
||||||
# Build artifacts
|
# Build artifacts
|
||||||
*.tar
|
*.tar
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
|||||||
+6
-8
@@ -1,16 +1,14 @@
|
|||||||
FROM docker.io/library/nginx:alpine
|
FROM docker.io/library/nginx:alpine
|
||||||
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
RUN rm /etc/nginx/conf.d/default.conf && \
|
||||||
|
apk add --no-cache coreutils
|
||||||
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
COPY src/index.html /usr/share/nginx/html/
|
COPY src/ /src/
|
||||||
COPY src/style.css /usr/share/nginx/html/
|
COPY build.sh /build.sh
|
||||||
COPY src/script.js /usr/share/nginx/html/
|
RUN chmod +x /build.sh && SRC=/src DIST=/dist /bin/sh /build.sh && cp -r /dist/* /usr/share/nginx/html/ && rm -rf /src /build.sh /dist
|
||||||
COPY src/profile.jpeg /usr/share/nginx/html/
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD wget -qO- http://localhost:8080/ || exit 1
|
||||||
|
|
||||||
CMD wget -qO- http://localhost:8080/ || exit 1
|
|
||||||
@@ -13,7 +13,7 @@ podman build -t homepage:latest .
|
|||||||
### Run the container
|
### Run the container
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
podman run --rm -p 8080:8080 -v ./src:/usr/share/nginx/html:z homepage:latest
|
podman run --rm -p 0.0.0.0:8080:8080 -v ./src:/usr/share/nginx/html:z homepage:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
Visit `http://localhost:8080` in your browser.
|
Visit `http://localhost:8080` in your browser.
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SRC="${SRC:-src}"
|
||||||
|
DIST="${DIST:-dist}"
|
||||||
|
|
||||||
|
# Clean and create dist
|
||||||
|
rm -rf "$DIST"
|
||||||
|
mkdir -p "$DIST"
|
||||||
|
|
||||||
|
# Copy index.html
|
||||||
|
cp "$SRC/index.html" "$DIST/index.html"
|
||||||
|
|
||||||
|
# Cache-bust assets by appending a content hash to filenames
|
||||||
|
for ext in css js jpeg png svg; do
|
||||||
|
for file in "$SRC"/*."$ext"; do
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
name=$(basename "$file" | sed "s/\.$ext$//")
|
||||||
|
hash=$(md5sum "$file" | cut -d' ' -f1)
|
||||||
|
newname="${name}.${hash}.${ext}"
|
||||||
|
|
||||||
|
cp "$file" "$DIST/$newname"
|
||||||
|
|
||||||
|
# Update references in HTML
|
||||||
|
case "$ext" in
|
||||||
|
css)
|
||||||
|
sed -i "s|href=\"${name}.${ext}\"|href=\"${newname}\"|g" "$DIST/index.html"
|
||||||
|
;;
|
||||||
|
js)
|
||||||
|
sed -i "s|src=\"${name}.${ext}\"|src=\"${newname}\"|g" "$DIST/index.html"
|
||||||
|
;;
|
||||||
|
jpeg|png|svg)
|
||||||
|
sed -i "s|\"${name}.${ext}\"|\"${newname}\"|g" "$DIST/index.html"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Build complete: $DIST/"
|
||||||
|
echo "Assets with cache-busting hashes:"
|
||||||
|
ls -1 "$DIST"
|
||||||
+14
@@ -17,6 +17,20 @@ server {
|
|||||||
gzip_min_length 256;
|
gzip_min_length 256;
|
||||||
gzip_vary on;
|
gzip_vary on;
|
||||||
|
|
||||||
|
# Never cache index.html so the latest HTML is always served
|
||||||
|
location = /index.html {
|
||||||
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
|
add_header Pragma "no-cache";
|
||||||
|
add_header Expires "0";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cache hashed assets forever (filename contains content hash)
|
||||||
|
location ~* \.(css|js|jpeg|jpg|png|gif|ico|svg|woff2?)$ {
|
||||||
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user