mirror of
https://github.com/dokku/buildpack-nginx.git
synced 2026-04-30 11:37:35 +00:00
fix: version-aware nginx binary caching and prebuilt downloads
Cached nginx binaries were reused regardless of NGINX_VERSION changes, and prebuilt releases always fetched the latest asset regardless of the configured version. Add a .nginx-version marker file to the cache and version the release asset filename so mismatched versions trigger a rebuild.
This commit is contained in:
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -62,7 +62,7 @@ jobs:
|
|||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
source "$GITHUB_WORKSPACE/conf/nginx-configure-flags"
|
source "$GITHUB_WORKSPACE/conf/nginx-configure-flags"
|
||||||
cp /tmp/nginx-${NGINX_VERSION}/objs/nginx /tmp/nginx-linux-amd64
|
cp /tmp/nginx-${NGINX_VERSION}/objs/nginx "/tmp/nginx-${NGINX_VERSION}-linux-amd64"
|
||||||
chmod +x /tmp/nginx-linux-amd64
|
chmod +x "/tmp/nginx-${NGINX_VERSION}-linux-amd64"
|
||||||
gh release upload "${{ github.event.release.tag_name }}" \
|
gh release upload "${{ github.event.release.tag_name }}" \
|
||||||
/tmp/nginx-linux-amd64
|
"/tmp/nginx-${NGINX_VERSION}-linux-amd64"
|
||||||
|
|||||||
18
bin/compile
18
bin/compile
@ -60,18 +60,29 @@ if [[ ! -f "$BUILD_DIR/sigil/sigil" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Invalidate cache if version doesn't match
|
||||||
|
if [[ -f "${CACHE_DIR}/bin/nginx" ]] && [[ ! -f "${CACHE_DIR}/bin/.nginx-version" ]]; then
|
||||||
|
echo "-----> Cached nginx binary has no version marker, rebuilding"
|
||||||
|
rm -rf "${CACHE_DIR:?}/bin"
|
||||||
|
elif [[ -f "${CACHE_DIR}/bin/nginx" ]] && [[ -f "${CACHE_DIR}/bin/.nginx-version" ]] && [[ "$(cat "${CACHE_DIR}/bin/.nginx-version")" != "$NGINX_VERSION" ]]; then
|
||||||
|
CACHED_VERSION="$(cat "${CACHE_DIR}/bin/.nginx-version")"
|
||||||
|
echo "-----> Cached nginx ${CACHED_VERSION} does not match required ${NGINX_VERSION}, rebuilding"
|
||||||
|
rm -rf "${CACHE_DIR:?}/bin"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -f "${CACHE_DIR}/bin/nginx" ]]; then
|
if [[ -f "${CACHE_DIR}/bin/nginx" ]]; then
|
||||||
echo "-----> Reusing nginx binary from cache"
|
echo "-----> Reusing nginx ${NGINX_VERSION} binary from cache"
|
||||||
mkdir -p "$BUILD_DIR/nginx"
|
mkdir -p "$BUILD_DIR/nginx"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
cp -r $CACHE_DIR/bin/* "$BUILD_DIR/nginx/"
|
cp -r $CACHE_DIR/bin/* "$BUILD_DIR/nginx/"
|
||||||
|
|
||||||
elif curl -fsSL "https://github.com/${BUILDPACK_REPO}/releases/latest/download/nginx-linux-amd64" -o /tmp/nginx-linux-amd64 2>/dev/null; then
|
elif curl -fsSL "https://github.com/${BUILDPACK_REPO}/releases/latest/download/nginx-${NGINX_VERSION}-linux-amd64" -o /tmp/nginx-linux-amd64 2>/dev/null; then
|
||||||
echo "-----> Using precompiled nginx binary"
|
echo "-----> Using precompiled nginx ${NGINX_VERSION} binary"
|
||||||
mkdir -p "$BUILD_DIR/nginx" "${CACHE_DIR}/bin"
|
mkdir -p "$BUILD_DIR/nginx" "${CACHE_DIR}/bin"
|
||||||
chmod +x /tmp/nginx-linux-amd64
|
chmod +x /tmp/nginx-linux-amd64
|
||||||
cp /tmp/nginx-linux-amd64 "$BUILD_DIR/nginx/nginx"
|
cp /tmp/nginx-linux-amd64 "$BUILD_DIR/nginx/nginx"
|
||||||
cp /tmp/nginx-linux-amd64 "${CACHE_DIR}/bin/nginx"
|
cp /tmp/nginx-linux-amd64 "${CACHE_DIR}/bin/nginx"
|
||||||
|
echo "$NGINX_VERSION" >"${CACHE_DIR}/bin/.nginx-version"
|
||||||
rm -f /tmp/nginx-linux-amd64
|
rm -f /tmp/nginx-linux-amd64
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -109,6 +120,7 @@ else
|
|||||||
rm -rf "${CACHE_DIR:?}/bin" && mkdir -p "$CACHE_DIR/bin/"
|
rm -rf "${CACHE_DIR:?}/bin" && mkdir -p "$CACHE_DIR/bin/"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
cp -r $BUILD_DIR/nginx/* "$CACHE_DIR/bin/"
|
cp -r $BUILD_DIR/nginx/* "$CACHE_DIR/bin/"
|
||||||
|
echo "$NGINX_VERSION" >"${CACHE_DIR}/bin/.nginx-version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update the PATH
|
# Update the PATH
|
||||||
|
|||||||
Reference in New Issue
Block a user