-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove pagespeed module from our nginx container (#1150)
* refactor: use standard nginx container * introduce shellspec testing * add shellspec tests job BREAKING CHANGES: The [pagespeed module](https://www.modpagespeed.com) of NGINX has been removed without replacement.
- Loading branch information
Showing
17 changed files
with
206 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
FROM ubuntu:focal as buildstep | ||
RUN apt-get update | ||
RUN apt-get install -y curl build-essential zlib1g-dev libpcre3-dev unzip wget uuid-dev sudo openssl libssl-dev | ||
RUN curl -kfL -sS https://ngxpagespeed.com/install > install.sh | ||
RUN bash install.sh --ngx-pagespeed-version v1.13.35.2-stable --nginx-version 1.21.6 --additional-nginx-configure-arguments '--with-http_ssl_module --with-http_stub_status_module' | ||
|
||
FROM scratch as configstep | ||
COPY --from=nginx:mainline /etc/nginx /etc/nginx | ||
COPY nginx.conf /etc/nginx/ | ||
FROM nginx:1.20 | ||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends --no-install-suggests -y apache2-utils | ||
COPY nginx.conf /etc/nginx/nginx.conf | ||
COPY features /etc/nginx/features/ | ||
COPY templates /etc/nginx/templates/ | ||
COPY entrypoint.sh *.yaml / | ||
COPY docker-entrypoint.d/*.sh /docker-entrypoint.d/ | ||
COPY *.yaml / | ||
COPY 50x.html /usr/share/nginx/html/ | ||
ADD https://github.com/hairyhenderson/gomplate/releases/download/v3.8.0/gomplate_linux-amd64-slim /gomplate | ||
|
||
FROM ubuntu:focal | ||
RUN apt-get update && \ | ||
apt-get install -y gettext-base libssl1.1 apache2-utils && \ | ||
apt-get -y autoremove && \ | ||
apt-get clean && \ | ||
rm -r /var/cache/apt /var/lib/apt/lists | ||
COPY --from=buildstep /usr/local/nginx /usr/local/nginx | ||
COPY --from=nginx/nginx-prometheus-exporter:0.9.0 /usr/bin/nginx-prometheus-exporter /nginx-prometheus-exporter | ||
COPY --from=configstep / / | ||
RUN chmod 777 /gomplate | ||
ENV NPSC_ENABLE_FILTERS=in_place_optimize_for_browser,prioritize_critical_css,inline_preview_images,lazyload_images,rewrite_images,rewrite_css,remove_comments,move_css_to_head,move_css_above_scripts,collapse_whitespace,combine_javascript,extend_cache | ||
ENV NPSC_JsPreserveURLs=off | ||
ENV NPSC_ImagePreserveURLs=on | ||
ENV NPSC_ForceCaching=off | ||
RUN chmod 700 /gomplate | ||
COPY --from=nginx/nginx-prometheus-exporter:0.10.0 /usr/bin/nginx-prometheus-exporter /nginx-prometheus-exporter | ||
ENV CACHE=on | ||
ENV COMPRESSION=on | ||
ENV PAGESPEED=on | ||
ENV DEVICE_DETECTION=on | ||
ENV SSR=on | ||
ENV CACHE_DURATION_NGINX_OK=10m | ||
ENV CACHE_DURATION_NGINX_NF=60m | ||
ENV LOGFORMAT=main | ||
|
||
EXPOSE 80 443 9113 | ||
|
||
ENTRYPOINT [ "sh", "entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--require spec_helper | ||
|
||
## Default kcov (coverage) options | ||
# --kcov-options "--include-path=. --path-strip-level=1" | ||
# --kcov-options "--include-pattern=.sh" | ||
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" | ||
|
||
## Example: Include script "myprog" with no extension | ||
# --kcov-options "--include-pattern=.sh,myprog" | ||
|
||
## Example: Only specified files/directories | ||
# --kcov-options "--include-pattern=myprog,/lib/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
if [ -f "/etc/nginx/conf.d/default.conf" ] | ||
then | ||
rm /etc/nginx/conf.d/default.conf | ||
fi | ||
|
||
if [ -z "$UPSTREAM_PWA" ] | ||
then | ||
echo "UPSTREAM_PWA is not set" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$ICM_BASE_URL" ] | ||
then | ||
echo "ICM_BASE_URL is not set. Cannot use sitemap proxy feature." | ||
fi | ||
|
||
if [ -z "$OVERRIDE_IDENTITY_PROVIDERS" ] | ||
then | ||
echo "OVERRIDE_IDENTITY_PROVIDERS is not set. Cannot use override identity provider feature." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
find /etc/nginx/features/*.conf -print0 | xargs -0 -I{} echo {} | sed -e "s%.*\/\(\w*\).conf%\1%" | grep -E '^\w+$' | while read feature; do echo "# $feature" ; env | grep -iqE "^$feature=(on|1|true|yes)$" && echo "include /etc/nginx/features/${feature}.conf;" || echo "include /etc/nginx/features/${feature}-off[.]conf;" ; done >/etc/nginx/conf.d/features.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
if [ -z "$MULTI_CHANNEL_SOURCE" ] | ||
then | ||
if [ -z "$MULTI_CHANNEL" ] | ||
then | ||
MULTI_CHANNEL_SOURCE="./multi-channel.yaml" | ||
else | ||
MULTI_CHANNEL_SOURCE="env:///MULTI_CHANNEL?type=application/yaml" | ||
fi | ||
fi | ||
|
||
if [ -z "$OVERRIDE_IDENTITY_PROVIDERS_SOURCE" ] | ||
then | ||
if [ -n "$OVERRIDE_IDENTITY_PROVIDERS" ] | ||
then | ||
OVERRIDE_IDENTITY_PROVIDERS_SOURCE="env:///OVERRIDE_IDENTITY_PROVIDERS?type=application/yaml" | ||
fi | ||
fi | ||
|
||
if [ -z "$CACHING_IGNORE_PARAMS_SOURCE" ] | ||
then | ||
if [ -z "$CACHING_IGNORE_PARAMS" ] | ||
then | ||
CACHING_IGNORE_PARAMS_SOURCE="./caching-ignore-params.yaml" | ||
else | ||
CACHING_IGNORE_PARAMS_SOURCE="env:///CACHING_IGNORE_PARAMS?type=application/yaml" | ||
fi | ||
fi | ||
|
||
/gomplate -d "domains=$MULTI_CHANNEL_SOURCE" -d "overrideIdentityProviders=$OVERRIDE_IDENTITY_PROVIDERS_SOURCE" -d "cachingIgnoreParams=$CACHING_IGNORE_PARAMS_SOURCE" -d 'ipwhitelist=env:///BASIC_AUTH_IP_WHITELIST?type=application/yaml' --input-dir="/etc/nginx/templates" --output-map='/etc/nginx/conf.d/{{ .in | strings.ReplaceAll ".conf.tmpl" ".conf" }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
# set -x | ||
|
||
if [ -n "$BASIC_AUTH" ] | ||
then | ||
htpasswd -bc /etc/nginx/.htpasswd $(echo "$BASIC_AUTH" | sed 's/:/ /') | ||
fi | ||
|
||
if env | grep -iqE "^DEBUG=(on|1|true|yes)$" | ||
then | ||
find /etc/nginx -name '*.conf' -print -exec cat '{}' \; | ||
nginx -V | ||
fi | ||
|
||
if env | grep -iqE "^PROMETHEUS=(on|1|true|yes)$" | ||
then | ||
(sleep 5 && /nginx-prometheus-exporter)& | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Describe "envcheck behavior" | ||
Describe 'Mandatory parameters' | ||
It 'Should exit with error if value is missing' | ||
When run script 00-envcheck.sh | ||
The status should be failure | ||
The output should eq 'UPSTREAM_PWA is not set' | ||
|
||
End | ||
|
||
It 'Should not exit with error if value is provided' | ||
BeforeRun "export UPSTREAM_PWA=sdf" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The output should not eq 'UPSTREAM_PWA is not set' | ||
End | ||
End | ||
|
||
Describe "OVERRIDE_IDENTITY_PROVIDERS" | ||
It 'Should issue a warning message if value is missing' | ||
BeforeRun "export UPSTREAM_PWA=a ICM_BASE_URL=b" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The output should eq 'OVERRIDE_IDENTITY_PROVIDERS is not set. Cannot use override identity provider feature.' | ||
End | ||
|
||
It 'Should continue with success without messages if value is set' | ||
BeforeRun "export UPSTREAM_PWA=a ICM_BASE_URL=b OVERRIDE_IDENTITY_PROVIDERS=c" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The output should not eq 'OVERRIDE_IDENTITY_PROVIDERS is not set. Cannot use override identity provider feature.' | ||
End | ||
End | ||
|
||
Describe "ICM_BASE_URL" | ||
It 'Should issue a warning message if value is missing' | ||
BeforeRun "export UPSTREAM_PWA=a OVERRIDE_IDENTITY_PROVIDERS=b" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The output should eq 'ICM_BASE_URL is not set. Cannot use sitemap proxy feature.' | ||
End | ||
|
||
It 'Should continue with success without messages if value is set' | ||
BeforeRun "export UPSTREAM_PWA=a ICM_BASE_URL=b OVERRIDE_IDENTITY_PROVIDERS=c" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The output should not eq 'OVERRIDE_IDENTITY_PROVIDERS is not set. Cannot use override identity provider feature.' | ||
End | ||
End | ||
|
||
Describe "Default NGinx Config File" | ||
It 'Should be removed if existing to prevent defaults being applied' | ||
BeforeRun "mkdir -p /etc/nginx/conf.d && touch /etc/nginx/conf.d/default.conf && export UPSTREAM_PWA=a ICM_BASE_URL=b OVERRIDE_IDENTITY_PROVIDERS=c" | ||
When run script 00-envcheck.sh | ||
The status should be success | ||
The path '/etc/nginx/conf.d/default.conf' should not be exist | ||
End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# shellcheck shell=sh | ||
|
||
# Defining variables and functions here will affect all specfiles. | ||
# Change shell options inside a function may cause different behavior, | ||
# so it is better to set them here. | ||
# set -eu | ||
|
||
# This callback function will be invoked only once before loading specfiles. | ||
spec_helper_precheck() { | ||
# Available functions: info, warn, error, abort, setenv, unsetenv | ||
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION | ||
: minimum_version "0.28.1" | ||
} | ||
|
||
# This callback function will be invoked after a specfile has been loaded. | ||
spec_helper_loaded() { | ||
: | ||
} | ||
|
||
# This callback function will be invoked after core modules has been loaded. | ||
spec_helper_configure() { | ||
# Available functions: import, before_each, after_each, before_all, after_all | ||
: import 'support/custom_matcher' | ||
} |
Oops, something went wrong.