diff --git a/modules/cloud-config-container/squid/docker/Dockerfile b/modules/cloud-config-container/squid/docker/Dockerfile new file mode 100644 index 00000000..180971da --- /dev/null +++ b/modules/cloud-config-container/squid/docker/Dockerfile @@ -0,0 +1,30 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM debian:buster-slim + +ENV SQUID_VERSION=4.6 \ + SQUID_CACHE_DIR=/var/spool/squid \ + SQUID_LOG_DIR=/var/log/squid \ + SQUID_USER=proxy + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y squid=${SQUID_VERSION}* \ + && rm -rf /var/lib/apt/lists/* + +COPY entrypoint.sh /sbin/entrypoint.sh +RUN chmod 755 /sbin/entrypoint.sh + +EXPOSE 3128/tcp +ENTRYPOINT ["/sbin/entrypoint.sh"] diff --git a/modules/cloud-config-container/squid/docker/cloudbuild.yaml b/modules/cloud-config-container/squid/docker/cloudbuild.yaml new file mode 100644 index 00000000..a942320a --- /dev/null +++ b/modules/cloud-config-container/squid/docker/cloudbuild.yaml @@ -0,0 +1,31 @@ + +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# In this directory, run the following command to build this builder. +# $ gcloud builds submit . + +steps: +- name: 'gcr.io/cloud-builders/docker' + args: + - build + - --tag=gcr.io/$PROJECT_ID/squid:${_IMAGE_VERSION} + - --tag=gcr.io/$PROJECT_ID/squid:latest + - . + +substitutions: + _IMAGE_VERSION: "20210215" +images: + - 'gcr.io/$PROJECT_ID/squid:${_IMAGE_VERSION}' + - 'gcr.io/$PROJECT_ID/squid:latest' diff --git a/modules/cloud-config-container/squid/docker/entrypoint.sh b/modules/cloud-config-container/squid/docker/entrypoint.sh new file mode 100755 index 00000000..5349208c --- /dev/null +++ b/modules/cloud-config-container/squid/docker/entrypoint.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This container is based off Sameer Naik's existing squid container. +# https://github.com/sameersbn/docker-squid + +set -e + +create_log_dir() { + mkdir -p ${SQUID_LOG_DIR} + chmod -R 755 ${SQUID_LOG_DIR} + chown -R ${SQUID_USER}:${SQUID_USER} ${SQUID_LOG_DIR} +} + +create_cache_dir() { + mkdir -p ${SQUID_CACHE_DIR} + chown -R ${SQUID_USER}:${SQUID_USER} ${SQUID_CACHE_DIR} +} + +create_log_dir +create_cache_dir + +# allow arguments to be passed to squid +if [[ ${1:0:1} = '-' ]]; then + EXTRA_ARGS="$@" + set -- +elif [[ ${1} == squid || ${1} == $(which squid) ]]; then + EXTRA_ARGS="${@:2}" + set -- +fi + +# default behaviour is to launch squid +if [[ -z ${1} ]]; then + if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then + echo "Initializing cache..." + $(which squid) -N -f /etc/squid/squid.conf -z + fi + echo "Starting squid..." + exec $(which squid) -f /etc/squid/squid.conf -NYCd 1 ${EXTRA_ARGS} +else + exec "$@" +fi