Skip to content

Commit

Permalink
Fix: Remove unneccessary dependendancy on external logrotate image
Browse files Browse the repository at this point in the history
We now include logrotate in the the basic image. This does -- up to a
point -- reduce the "separation of concerns", but it simplifies image
management considerably and removes an unneccessary dependency on a
third-party container.
  • Loading branch information
bokysan committed Oct 27, 2023
1 parent 5fb369a commit b90b336
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 128 deletions.
58 changes: 0 additions & 58 deletions .github/actions/build-logrotate/action.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ jobs:

- uses: ./.github/actions/helm-chart-tests

Build_Logrotate:
runs-on: ubuntu-latest
needs:
- Helm_chart_Tests
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: ./.github/actions/build-logrotate
with:
DOCKER_ACCESS_TOKEN: '${{ secrets.DOCKER_ACCESS_TOKEN }}'
tags: |
boky/logrotate:latest
boky/logrotate:edge
Build_PostfixExporter:
runs-on: ubuntu-latest
needs:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ jobs:

- uses: ./.github/actions/helm-chart-tests

Build_Logrotate:
runs-on: ubuntu-latest
needs:
- Helm_chart_Tests
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: ./.github/actions/build-logrotate
with:
DOCKER_ACCESS_TOKEN: '${{ secrets.DOCKER_ACCESS_TOKEN }}'
tags: |
boky/logrotate:latest
boky/logrotate:edge
Build_PostfixExporter:
runs-on: ubuntu-latest
needs:
Expand Down
4 changes: 2 additions & 2 deletions build-scripts/postfix-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ do_alpine() {
apk add --upgrade cyrus-sasl cyrus-sasl-static cyrus-sasl-digestmd5 cyrus-sasl-crammd5 cyrus-sasl-login cyrus-sasl-ntlm
apk add postfix
apk add opendkim
apk add --upgrade ca-certificates tzdata supervisor rsyslog musl musl-utils bash opendkim-utils libcurl jsoncpp lmdb
apk add --upgrade ca-certificates tzdata supervisor rsyslog musl musl-utils bash opendkim-utils libcurl jsoncpp lmdb logrotate
}

do_ubuntu() {
Expand All @@ -17,7 +17,7 @@ do_ubuntu() {
apt-get install -y libsasl2-modules
apt-get install -y postfix
apt-get install -y opendkim
apt-get install -y ca-certificates tzdata supervisor rsyslog bash opendkim-tools curl libcurl4 libjsoncpp25 sasl2-bin postfix-lmdb netcat
apt-get install -y ca-certificates tzdata supervisor rsyslog bash opendkim-tools curl libcurl4 libjsoncpp25 sasl2-bin postfix-lmdb netcat logrotate cron
}

if [ -f /etc/alpine-release ]; then
Expand Down
6 changes: 6 additions & 0 deletions configs/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ autorestart = false
directory = /etc/postfix
startsecs = 0

[program:cron]
command = /scripts/cron.sh
autostart = true
autorestart = true
startsecs = 0

[program:opendkim]
command = /scripts/opendkim.sh
user = opendkim
Expand Down
12 changes: 12 additions & 0 deletions helm/mail/templates/configmap-metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ data:
maillog.conf: |
template(name="metricslog" type="string" string={{ .Values.metrics.path | quote }})
action(type="omfile" DynaFile="metricslog" template="plain" DirCreateMode="0755" FileCreateMode="0644")
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ print $fullName "-scripts" | quote }}
labels:
{{- $labels | nindent 4 }}
data:
logrotate.sh: |
#!/bin/sh
set -e
exec /usr/sbin/logrotate /etc/logrotate.d/logrotate.conf
{{- end }}
35 changes: 15 additions & 20 deletions helm/mail/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ spec:
mountPath: {{ regexFind "^/?.*/" .Values.metrics.maillog | quote }}
readOnly: false
subPath: logs
{{- if .Values.metrics.logrotate.enabled }}
- name: metrics-config
mountPath: /etc/logrotate.d/logrotate.conf
subPath: logrotate.conf
- name: metrics-config-scripts
mountPath: /etc/cron.hourly/ # Ubuntu
subPath: logrotate.sh
- name: metrics-config-scripts
mountPath: /etc/periodic/hourly # Alpine
subPath: logrotate.sh
{{- end }}
{{- end }}
{{- if .Values.certs.create }}
- name: certs
Expand Down Expand Up @@ -161,26 +172,6 @@ spec:
path: {{ .Values.metrics.path | quote }}
port: {{ .Values.metrics.port }}
initialDelaySeconds: 5
{{- if .Values.metrics.logrotate.enabled }}
- name: logrotate
image: "{{ .Values.metrics.logrotate.image.repository }}:{{ .Values.metrics.logrotate.image.tag | default "latest" }}"
startupProbe:
exec:
command:
- sh
- -c
- >-
[ -f {{ .Values.metrics.maillog | quote }} ] && grep -qi "starting the Postfix mail system" {{ .Values.metrics.maillog | quote }}
failureThreshold: 30
periodSeconds: 10
volumeMounts:
- name: {{ $fullName | quote }}
mountPath: {{ regexFind "^/?.*/" .Values.metrics.maillog | quote }}
subPath: logs
- mountPath: /etc/logrotate.d/logrotate.conf
name: metrics-config
subPath: logrotate.conf
{{- end }}
{{- end }}
{{- if .Values.extraContainers }}
{{- tpl .Values.extraContainers $root | nindent 8 }}
Expand Down Expand Up @@ -215,6 +206,10 @@ spec:
- name: metrics-config
configMap:
name: {{ print $fullName "-metrics" | quote }}
- name: metrics-config-scripts
configMap:
name: {{ print $fullName "-scripts" | quote }}
defaultMode: 0777
{{- end }}
{{- if .Values.extraVolumes }}{{- toYaml .Values.extraVolumes | nindent 8 }}{{ end }}
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
Expand Down
5 changes: 1 addition & 4 deletions helm/mail/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ metrics:
maillog: /var/log/mail.log
logrotate:
enabled: true
image:
repository: "boky/logrotate"
tag: "latest"
logrotate.conf: |
/var/log/mail.log {
rotate 1
Expand All @@ -55,7 +52,7 @@ metrics:
missingok
notifempty
dateext
olddir /var/log/old
olddir /var/log/
maxage 90
}
Expand Down
12 changes: 0 additions & 12 deletions logrotate-01.patch

This file was deleted.

7 changes: 7 additions & 0 deletions scripts/cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ -f /usr/sbin/cron ]; then # Ubuntu
exec /usr/sbin/cron -f
else # Alpine / Busybox cron
exec /usr/sbin/crond -f -S
fi
2 changes: 1 addition & 1 deletion scripts/opendkim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ ! -d /etc/opendkim/keys ]; then
elif [ -z "$(find /etc/opendkim/keys -type f ! -name .)" ]; then
noop
else
/usr/sbin/opendkim -D -f -x /etc/opendkim/opendkim.conf
exec /usr/sbin/opendkim -D -f -x /etc/opendkim/opendkim.conf
fi


2 changes: 1 addition & 1 deletion scripts/postfix.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
/usr/sbin/postfix -c /etc/postfix start-fg
exec /usr/sbin/postfix -c /etc/postfix start-fg

0 comments on commit b90b336

Please sign in to comment.