Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI/CD
on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
push-docker:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI/CD
on:
push:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release-chart:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.5.0
with:
charts_dir: charts
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:alpine as build

WORKDIR /app

COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY . .

RUN go build -o announcer

FROM alpine
WORKDIR /announcer
COPY --from=build /app/announcer /bin/announcer

ENTRYPOINT [ "/bin/announcer" ]
12 changes: 12 additions & 0 deletions announcements/announcements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package announcements
import (
"context"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -111,10 +112,21 @@ func remove(im *imap.Dialer, uids []int) error {
return err
}

var bracketLinkRe = regexp.MustCompile(`\[((https?://)([^\]]*[^\\\]]))\]\((https?://[^)]*[^\\)])\)`)

var converter = md.NewConverter("", true, &md.Options{
HeadingStyle: "setext",
StrongDelimiter: "**",
LinkStyle: "inlined",
}).After(func(content string) string {
return bracketLinkRe.ReplaceAllStringFunc(content, func(bracketLink string) string {
matches := bracketLinkRe.FindStringSubmatch(bracketLink)
text, textNoSchema, link := matches[1], matches[3], matches[4]
if text == link {
return "<" + link + ">"
}
return fmt.Sprintf("[%s](%s)", textNoSchema, link)
})
})

// markdownBody takes a html string and converts it into a formatted markdown body.
Expand Down
24 changes: 24 additions & 0 deletions charts/noncer/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: noncer
description: A Helm chart for the go announcements bot

# 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.1

# 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: "0.0.2"
1 change: 1 addition & 0 deletions charts/noncer/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dr-docso deployed!
62 changes: 62 additions & 0 deletions charts/noncer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "noncer.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 "noncer.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 "noncer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "noncer.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "noncer.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
81 changes: 81 additions & 0 deletions charts/noncer/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "noncer.fullname" . }}
labels:
{{- include "noncer.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "noncer.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "noncer.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- -user
- "{{ .Values.email.user }}"
- -host
- "{{ .Values.email.host }}"
- -port
- "{{ .Values.email.port }}"
- -pass
- "$(PASSWORD)"
- -period
- "{{ .Values.bot.period }}"
- -webhook
- "$(WEBHOOK)"
{{- range .Values.bot.allowList}}
- -allowlist
- "{{ . }}"
{{- end }}
env:
- name: PASSWORD
valueFrom:
secretKeyRef:
{{- if .Values.existingSecret }}
name: "{{ .Values.existingSecret }}"
{{- else }}
name: "{{ include "noncer.name" . }}"
{{- end }}
key: password
- name: WEBHOOK
valueFrom:
secretKeyRef:
{{- if .Values.existingSecret }}
name: "{{ .Values.existingSecret }}"
{{- else }}
name: "{{ include "noncer.name" . }}"
{{- end }}
key: webhook
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/noncer/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if not .Values.existingSecret -}}
apiVersion: v1
kind: Secret
metadata:
name: "{{ include "noncer.name" . }}"
type: Opaque
data:
password: {{ .Values.email.password | required ".Values.email.password is required." | b64enc }}
webhook: {{ .Values.bot.webhook | required ".Values.bot.webhook is required" | b64enc }}
{{- end -}}
47 changes: 47 additions & 0 deletions charts/noncer/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
image:
repository: ghcr.io/discord-gophers/noncer
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""

# The bot can be provided with an existing secret that contains both the password and the webhook.
# Otherwise a secret will be created
existingSecret: ""

email:
user: ""
password: ""
host: ""
port: 993

bot:
period: 60
webhook: ""
allowList: []


imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}
podSecurityContext: {}
securityContext: {}

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}