Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
digiserg committed Sep 18, 2023
1 parent 5c7adb6 commit 2b85a16
Show file tree
Hide file tree
Showing 18 changed files with 750 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: Publish Docker image

on:
release:
types: [published]

jobs:
release:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Setup mirror
uses: self-actuated/hub-mirror@master

- name: Get TAG
id: get_tag
run: echo TAG=${GITHUB_REF##*/} >> $GITHUB_ENV

- name: Get Repo Owner
id: get_repo_owner
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" > $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: "Get docker info"
run: |
echo "Actor: ${{ github.actor }}"
- name: "Log into GitHub Container Registry"
if: "github.event_name != 'pull_request'"
uses: "docker/login-action@v1"
with:
registry: "ghcr.io"
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ env.TAG }}
GitCommit=${{ github.sha }}
context: .
push: true
tags: |
ghcr.io/${{ env.REPO_OWNER }}/squid:${{ github.sha }}
ghcr.io/${{ env.REPO_OWNER }}/squid:${{ env.TAG }}
ghcr.io/${{ env.REPO_OWNER }}/squid:latest
labels: |
LABEL org.opencontainers.image.source="https://github.com/${{ env.REPO_OWNER }}/squid"
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM centos:7

RUN yum -y install squid openssl
COPY squid.conf.template /etc/squid/squid.conf.template
COPY myCA.pem /etc/squid/ssl_cert/myCA.pem
COPY entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh && yum clean all

CMD ["/entrypoint.sh"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Squid with SSL support

A simple squid container with SSL support (ssl_bump) enabled by default
plus a helm chart to install it into Kubernetes.

23 changes: 23 additions & 0 deletions charts/squid/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/squid/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: squid
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
22 changes: 22 additions & 0 deletions charts/squid/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "squid.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "squid.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "squid.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "squid.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/squid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "squid.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "squid.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "squid.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "squid.labels" -}}
helm.sh/chart: {{ include "squid.chart" . }}
{{ include "squid.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "squid.selectorLabels" -}}
app.kubernetes.io/name: {{ include "squid.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "squid.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "squid.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/squid/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "squid.fullname" . }}-conf
labels:
app: {{ template "squid.name" . }}
chart: {{ template "squid.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
squid.conf: |
{{- if .Values.metrics.enabled }}
acl prometheus src 127.0.0.1/32
http_access allow manager prometheus
{{- end }}
{{ .Values.config | indent 4 }}
151 changes: 151 additions & 0 deletions charts/squid/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "squid.fullname" . }}
labels:
app: {{ template "squid.name" . }}
chart: {{ template "squid.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "squid.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "squid.name" . }}
release: {{ .Release.Name }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
spec:
{{- if .Values.image.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.image.imagePullSecrets }}
{{- end }}
initContainers:
# if there is a line in config map that starts with `cache_dir`
# run `squid -z` which will create the cache structure on the filesystem
- name: create-cache-dir
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{ toYaml .Values.resources | indent 12 }}
volumeMounts:
- name: {{ template "squid.fullname" . }}-conf
mountPath: /etc/squid/squid.conf
subPath: squid.conf
- name: cache
mountPath: /var/cache/squid
{{- if .Values.configSecret }}
- name: config-secret
mountPath: /etc/squid/config
{{- end }}
command:
- /bin/sh
- -c
args:
{{ toYaml .Values.initContainersArgs | indent 12 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 3128
protocol: TCP
- name: https
containerPort: 3129
protocol: TCP
volumeMounts:
- name: {{ template "squid.fullname" . }}-conf
mountPath: /etc/squid/squid.conf
subPath: squid.conf
- name: cache
mountPath: /var/cache/squid
{{- if .Values.configSecret }}
- name: config-secret
mountPath: /etc/squid/config
{{- end }}
# Load the configuration files for nginx
livenessProbe:
tcpSocket:
port: 3128
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 3128
initialDelaySeconds: 5
periodSeconds: 10
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.metrics.enabled }}
- name: exporter
image: "{{ .Values.metrics.exporter.image.repository }}:{{ .Values.metrics.exporter.image.tag }}"
imagePullPolicy: {{ .Values.metrics.exporter.image.pullPolicy }}
env:
- name: SQUID_HOSTNAME
value: {{ .Values.hostname | default "localhost" | quote }}
- name: SQUID_EXPORTER_LISTEN
value: ":{{ .Values.metrics.exporter.port }}"
- name: SQUID_PORT
value: "3128"
ports:
- name: metrics
containerPort: {{ .Values.metrics.exporter.port }}
protocol: TCP
livenessProbe:
tcpSocket:
port: {{ .Values.metrics.exporter.port }}
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /metrics
port: metrics
initialDelaySeconds: 5
periodSeconds: 10
resources:
{{ toYaml .Values.metrics.exporter.resources | indent 12 }}
{{- end }}
volumes:
- name: {{ template "squid.fullname" . }}-conf
configMap:
name: {{ template "squid.fullname" . }}-conf
- emptyDir: {}
name: cache
{{- if .Values.configSecret }}
- name: config-secret
secret:
secretName: {{ .Values.configSecret }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- if or .Values.releaseAntiAffinity .Values.affinity }}
affinity:
{{- end }}
{{- if .Values.releaseAntiAffinity }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
topologyKey: kubernetes.io/hostname
labelSelector:
matchExpressions:
- key: release
operator: In
values:
- {{ .Release.Name }}
{{- end }}
{{- with .Values.affinity }}
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
Loading

0 comments on commit 2b85a16

Please sign in to comment.