Skip to content

Commit

Permalink
Have Squid log to /dev/stdout to stream logs to Cloud Logging (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunzese authored Nov 16, 2022
1 parent ea36007 commit df539b5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion blueprints/networking/filtering-proxy-psc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module "project" {
services = [
"dns.googleapis.com",
"compute.googleapis.com",
"logging.googleapis.com"
"logging.googleapis.com",
"monitoring.googleapis.com"
]
}

Expand Down
8 changes: 8 additions & 0 deletions blueprints/networking/filtering-proxy-psc/squid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ http_port 0.0.0.0:3128 require-proxy-header
# only proxy, don't cache
cache deny all

# redirect all logs to /dev/stdout
logfile_rotate 0
cache_log stdio:/dev/stdout
access_log stdio:/dev/stdout
cache_store_log stdio:/dev/stdout

pid_filename /var/run/squid/squid.pid

acl ssl_ports port 443
acl safe_ports port 80
acl safe_ports port 443
Expand Down
4 changes: 2 additions & 2 deletions modules/cloud-config-container/squid/cloud-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ write_files:
[Service]
Environment="HOME=/home/squid"
ExecStartPre=/usr/bin/docker-credential-gcr configure-docker
ExecStart=/usr/bin/docker run --rm --name=squid \
ExecStart=/usr/bin/docker run --rm --name=squid \
--network host \
-v /etc/squid:/etc/squid \
gcr.io/pso-cft-fabric/squid:0.10
gcr.io/pso-cft-fabric/squid:20221116
ExecStop=/usr/bin/docker stop squid
ExecStopPost=/usr/bin/docker rm squid
Expand Down
8 changes: 8 additions & 0 deletions modules/cloud-config-container/squid/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ FROM debian:buster-slim
ENV SQUID_VERSION=4.6 \
SQUID_CACHE_DIR=/var/spool/squid \
SQUID_LOG_DIR=/var/log/squid \
SQUID_PID_DIR=/var/run/squid \
SQUID_USER=proxy

RUN apt-get update \
Expand All @@ -26,5 +27,12 @@ RUN apt-get update \
COPY entrypoint.sh /sbin/entrypoint.sh
RUN chmod 755 /sbin/entrypoint.sh

# Create the PID file directory as root, as the non-privileged user squid is not
# allowed to write in /var/run.
RUN mkdir -p ${SQUID_PID_DIR} \
&& chown ${SQUID_USER}:${SQUID_USER} ${SQUID_PID_DIR}

USER ${SQUID_USER}

EXPOSE 3128/tcp
ENTRYPOINT ["/sbin/entrypoint.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
- .

substitutions:
_IMAGE_VERSION: "20210215"
_IMAGE_VERSION: "20221116"
images:
- "gcr.io/$PROJECT_ID/squid:${_IMAGE_VERSION}"
- "gcr.io/$PROJECT_ID/squid:latest"
8 changes: 8 additions & 0 deletions modules/cloud-config-container/squid/squid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ http_port 0.0.0.0:3128
# only proxy, don't cache
cache deny all

# redirect all logs to /dev/stdout
logfile_rotate 0
cache_log stdio:/dev/stdout
access_log stdio:/dev/stdout
cache_store_log stdio:/dev/stdout

pid_filename /var/run/squid/squid.pid

acl ssl_ports port 443
acl safe_ports port 80
acl safe_ports port 443
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_resources(e2e_plan_runner):
"Test that plan works and the numbers of resources is as expected."
modules, resources = e2e_plan_runner()
assert len(modules) == 12
assert len(resources) == 33
assert len(resources) == 34

0 comments on commit df539b5

Please sign in to comment.