-
Notifications
You must be signed in to change notification settings - Fork 118
Add Dockerfile for agent #399
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
Merged
kate-osborn
merged 5 commits into
feature/cp-dp-separation
from
feature/agent-dockerfile
Feb 1, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,47 @@ | ||
FROM nginx:1.22.1-alpine | ||
ARG AGENT_VERSION | ||
ARG ALPINE_VERSION | ||
|
||
WORKDIR /nginx-with-agent | ||
|
||
RUN apk add --no-cache libcap | ||
|
||
# For now, get the agent apk package from github release. Eventually, we will pull the pre-build package from nginx.org. | ||
RUN wget -nv -O agent.apk https://github.com/nginx/agent/releases/download/v$AGENT_VERSION/nginx-agent-$AGENT_VERSION-v$ALPINE_VERSION-x86_64.apk \ | ||
&& apk add --allow-untrusted agent.apk | ||
|
||
# Copy nginx-agent config file and entrypont script. | ||
# We could also mount this to the Pod. | ||
COPY ./build/nginx-with-agent/nginx-agent.conf /etc/nginx-agent/nginx-agent.conf | ||
COPY ./build/nginx-with-agent/entrypoint.sh /nginx-with-agent/entrypoint.sh | ||
|
||
# Copy nginx config file and httpmatches njs module. | ||
# We could also mount this to the Pod. | ||
COPY ./internal/nginx/modules/src/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js | ||
COPY ./build/nginx-with-agent/nginx.conf /etc/nginx/nginx.conf | ||
|
||
# Create nginx directories, clear /conf.d directory, change owner of nginx and agent directories to nginx user 101, | ||
# and make the entrypoint script executable. | ||
RUN mkdir -p /etc/nginx/secrets /var/lib/nginx /var/log/nginx \ | ||
&& rm -f /etc/nginx/conf.d/* \ | ||
&& chown -R 101:101 /etc/nginx /var/lib/nginx /var/log/nginx /var/cache/nginx \ | ||
&& chown -R 101:101 /var/log/nginx-agent /etc/nginx-agent /var/log/nginx-agent /etc/nginx-agent\ | ||
&& chmod +x /nginx-with-agent/entrypoint.sh | ||
|
||
|
||
# The following instructions allow nginx and nginx-debug binaries to bind to privileged ports. | ||
# However, adding this capability prevents the agent from reading nginx's /proc/<pid>/exe symlink which is required by | ||
# the agent to determine the path to the nginx binary. While we wait for a more permanent fix, we will work around this | ||
# by having nginx bind to non-privileged ports. See this write-up for more details: https://dxuuu.xyz/filecaps.html | ||
|
||
#RUN setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug | ||
#RUN setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug | ||
|
||
# Set user to 101 (nginx) | ||
USER 101:101 | ||
|
||
STOPSIGNAL SIGTERM | ||
|
||
EXPOSE 8080 8443 | ||
|
||
ENTRYPOINT ["/nginx-with-agent/entrypoint.sh"] |
This file contains hidden or 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,47 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -x | ||
set -euxo pipefail | ||
|
||
handle_term() | ||
{ | ||
echo "received TERM signal" | ||
echo "stopping nginx-agent ..." | ||
kill -TERM "${agent_pid}" 2>/dev/null | ||
echo "stopping nginx ..." | ||
kill -TERM "${nginx_pid}" 2>/dev/null | ||
} | ||
|
||
trap 'handle_term' TERM | ||
|
||
# Launch nginx | ||
echo "starting nginx ..." | ||
nginx -g "daemon off;" & | ||
|
||
nginx_pid=$! | ||
|
||
cat /etc/nginx-agent/nginx-agent.conf | ||
# start nginx-agent, pass args | ||
echo "starting nginx-agent ..." | ||
nginx-agent "$@" & | ||
|
||
agent_pid=$! | ||
|
||
if [ $? != 0 ]; then | ||
echo "couldn't start the agent, please check the log file" | ||
exit 1 | ||
fi | ||
|
||
wait_term() | ||
{ | ||
wait ${agent_pid} | ||
trap - TERM | ||
kill -QUIT "${nginx_pid}" 2>/dev/null | ||
echo "waiting for nginx to stop..." | ||
wait ${nginx_pid} | ||
} | ||
|
||
wait_term | ||
|
||
echo "nginx-agent process has stopped, exiting." |
This file contains hidden or 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,42 @@ | ||
# | ||
# /etc/nginx-agent/nginx-agent.conf | ||
# | ||
# Configuration file for NGINX Agent. | ||
# | ||
# This file is to track agent configuration values that are meant to be statically set. There | ||
# are additional agent configuration values that are set via the API and agent install script | ||
# which can be found in /etc/nginx-agent/agent-dynamic.conf. | ||
|
||
log: | ||
# set log level (panic, fatal, error, info, debug, trace; default "info") | ||
level: info | ||
# set log path. if empty, don't log to file. | ||
path: /var/log/nginx-agent/ | ||
|
||
nginx: | ||
# path of NGINX logs to exclude | ||
exclude_logs: "" | ||
socket: "" | ||
|
||
dataplane: | ||
status: | ||
# poll interval for data plane status - the frequency the agent will query the dataplane for changes | ||
poll_interval: 30s | ||
# report interval for data plane status - the maximum duration to wait before syncing dataplane information if no updates have being observed | ||
report_interval: 24h | ||
|
||
metrics: | ||
# specify the size of a buffer to build before sending metrics | ||
bulk_size: 20 | ||
# specify metrics poll interval | ||
report_interval: 1m | ||
collection_interval: 15s | ||
mode: aggregated | ||
|
||
# OSS NGINX default config path | ||
# path to aux file dirs can also be added | ||
config_dirs: "/etc/nginx" | ||
|
||
api: | ||
# default port for Agent API, this is for the server configuration of the REST API | ||
port: 8081 |
This file contains hidden or 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,33 @@ | ||
# This manifest is for testing purposes and is not the final manifest for the nginx-with-agent. | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-with-agent | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: nginx-with-agent | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx-with-agent | ||
spec: | ||
serviceAccountName: default | ||
automountServiceAccountToken: false | ||
containers: | ||
- image: docker.io/nginx-kubernetes-gateway/nginx-with-agent:edge | ||
imagePullPolicy: IfNotPresent | ||
name: nginx-with-agent | ||
securityContext: | ||
allowPrivilegeEscalation: true | ||
runAsNonRoot: true | ||
runAsUser: 101 #nginx | ||
capabilities: | ||
drop: | ||
- ALL | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
- name: https | ||
containerPort: 8443 |
This file contains hidden or 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 @@ | ||
load_module /usr/lib/nginx/modules/ngx_http_js_module.so; | ||
|
||
events {} | ||
|
||
pid /etc/nginx/nginx.pid; | ||
|
||
error_log /var/log/nginx/error.log debug; | ||
|
||
http { | ||
include /etc/nginx/conf.d/*.conf; | ||
js_import /usr/lib/nginx/modules/njs/httpmatches.js; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for" '; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
# stub status API | ||
# needed by the agent in order to collect metrics | ||
server { | ||
listen 127.0.0.1:8082; | ||
location /api { | ||
stub_status; | ||
allow 127.0.0.1; | ||
deny all; | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.