-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add frontend nginx container for logging and plausible proxying #3108
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
058caf9
Add nginx proxy for frontend
sarayourfriend a43f765
Forward plausible requests with Nginx, removing this responsibility f…
sarayourfriend a108fdc
Build and publish frontend_nginx from CI
sarayourfriend e3f26b6
Fix analytics playwright tracking
sarayourfriend 7ee3e6a
Fix iteration
sarayourfriend a647836
Fix docs build
sarayourfriend bd22c48
Update frontend/nginx.conf.template
sarayourfriend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ playwright_tests | |
storybook_tests | ||
miscellaneous | ||
healthcheck | ||
nginx | ||
``` |
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 @@ | ||
# Frontend reverse proxy | ||
|
||
The frontend service relies on an Nginx reverse proxy in live environments to | ||
facilitate per-request logging in a format that matches other services we run | ||
(namely, Django). It also acts as a [proxy for Plausible][plausible_proxy], | ||
removing the need for Nuxt to handle these requests, freeing it up to handle | ||
rendering SSR requests. | ||
|
||
[plausible_proxy]: https://plausible.io/docs/proxy/guides/nginx | ||
|
||
Additionally, the reverse proxy may be used in the future for the following: | ||
|
||
- Serving static Nuxt content, freeing Nuxt from serving these requests. This is | ||
considered relatively low value due to Cloudflare caching already handling 99% | ||
of the benefit this would bring for the vast majority of cases. | ||
|
||
## Testing | ||
|
||
To test the frontend reverse proxy locally, run `just frontend/up`. To test the | ||
integration with your local Plausible container, follow the existing | ||
instructions in [the frontend analytics documentation][analytics_docs]. | ||
Everything should "just work". | ||
|
||
[analytics_docs]: /frontend/guides/analytics.md#plausible-set-up-and-first-run |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Keeping this as a separate Dockerfile prevents the need to rely on additional | ||
# contexts required for the frontend build (namely, `repo_root`). These are | ||
# possible with compose as of https://github.com/docker/compose/pull/10369 | ||
# and do appear to work, but it increases the complexity and these features | ||
# are not yet all available in every containerd implementation or distribution | ||
# (Debian, for example, still distributes an older version of compose without | ||
# this new feature). For the sake of keeping the local setup simpler and not | ||
# requiring contributors to have bleeding-edge Docker and compose plugin versions, | ||
# we can simply use a separate file for the time being. Once/if we start to use | ||
# nginx to serve static files for the frontend, we will need to integrate this | ||
# target into the shared Dockerfile. | ||
######### | ||
# NGINX # | ||
######### | ||
|
||
FROM docker.io/nginx:1.25.2-alpine as nginx | ||
|
||
LABEL org.opencontainers.image.source = "https://github.com/WordPress/openverse" | ||
|
||
WORKDIR /app | ||
|
||
COPY nginx.conf.template /etc/nginx/templates/openverse-frontend.conf.template | ||
|
||
# Only environment variables with this prefix will be available in the template | ||
ENV NGINX_ENVSUBST_FILTER="OPENVERSE_NGINX_" | ||
ENV OPENVERSE_NGINX_ENVIRONMENT="local" | ||
# Add the release version to the docker container | ||
ARG SEMANTIC_VERSION | ||
ENV OPENVERSE_NGINX_GIT_REVISION=$SEMANTIC_VERSION |
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,84 @@ | ||
# The following variables are substituted into the environment using envsubst. | ||
# This occurs automatically as part of the nginx image startup. | ||
# See: https://github.com/nginxinc/docker-nginx/blob/456bf337ceb922a207651aa7c6077a316c3e368c/entrypoint/20-envsubst-on-templates.sh#L17 | ||
# - OPENVERSE_NGINX_UPSTREAM_URL | ||
# - OPENVERSE_NGINX_GIT_REVISION | ||
# - OPENVERSE_NGINX_ENVIRONMENT | ||
# - OPENVERSE_NGINX_PLAUSIBLE_EVENT_URL | ||
|
||
error_log /var/log/nginx/error.log; | ||
|
||
log_format json_combined escape=json | ||
'{' | ||
'"time_local":"$time_local",' | ||
'"remote_addr":"$remote_addr",' | ||
'"remote_user":"$remote_user",' | ||
'"request":"$request",' | ||
'"status": "$status",' | ||
'"host_header": "$host",' | ||
'"body_bytes_sent":$body_bytes_sent,' | ||
'"request_time":"$request_time",' | ||
'"http_referrer":"$http_referer",' | ||
'"http_user_agent":"$http_user_agent",' | ||
'"upstream_response_time":$upstream_response_time,' | ||
'"http_x_forwarded_for":"$http_x_forwarded_for"' | ||
'}'; | ||
|
||
access_log /var/log/nginx/access.log json_combined; | ||
|
||
tcp_nopush on; | ||
tcp_nodelay on; | ||
types_hash_max_size 2048; | ||
|
||
# Compress large responses to save bandwidth and improve latency | ||
gzip on; | ||
gzip_min_length 860; | ||
gzip_vary on; | ||
gzip_proxied expired private auth; | ||
gzip_types application/json text/plain application/javascript; | ||
gzip_disable "MSIE [1-6]\."; | ||
|
||
upstream ov_service { | ||
server $OPENVERSE_NGINX_UPSTREAM_URL; | ||
} | ||
|
||
server { | ||
sarayourfriend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
access_log /var/log/nginx/access.log json_combined; | ||
|
||
listen 8080; | ||
server_name _; | ||
charset utf-8; | ||
client_max_body_size 75M; | ||
error_page 500 /500.json; | ||
absolute_redirect off; | ||
|
||
location / { | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header Host $http_host; | ||
proxy_redirect off; | ||
proxy_pass http://ov_service; | ||
error_page 500 /500.json; | ||
} | ||
|
||
location /version { | ||
default_type "application/json"; | ||
return 200 '{"release": "$OPENVERSE_NGINX_GIT_REVISION", "environment": "$OPENVERSE_NGINX_ENVIRONMENT"}'; | ||
} | ||
|
||
# This is Docker's internal DNS resolver | ||
# In localhost it will resolve the local Plausible and forward anything else to the host | ||
# In production, AWS replaces | ||
resolver 127.0.0.11; | ||
set $plausible_event_url $OPENVERSE_NGINX_PLAUSIBLE_EVENT_URL; | ||
location = /api/event { | ||
proxy_pass $plausible_event_url; | ||
proxy_set_header Host plausible.io; | ||
proxy_buffering on; | ||
proxy_http_version 1.1; | ||
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header X-Forwarded-Host $host; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is helpful documentation. Should we have it as an issue (potentially blocked) to ensure this is completed at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍 Done here #3180