diff --git a/.github/workflows/helm-release.yml b/.github/workflows/helm-release.yml new file mode 100644 index 0000000..8792cc5 --- /dev/null +++ b/.github/workflows/helm-release.yml @@ -0,0 +1,33 @@ +name: Release Charts + +on: + push: + branches: + - main + - helm-wip + +jobs: + release: + # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions + # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + 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: Install Helm + uses: azure/setup-helm@v3 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 8b8d822..2462908 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -7,7 +7,7 @@ name: Deploy mdBook site to Pages on: # Runs on pushes targeting the default branch push: - branches: ["main"] + branches: ["main", "helm-wip"] paths: - "docs/**" diff --git a/.github/workflows/slackwatch.yml b/.github/workflows/slackwatch.yml index 6c6ec37..7436778 100644 --- a/.github/workflows/slackwatch.yml +++ b/.github/workflows/slackwatch.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - helm-wip paths: - 'src/**' diff --git a/.gitignore b/.gitignore index a9ce187..197d1b5 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ docker-compose*.yml # Dioxus .dioxus/ -slackwatch/ +.slackwatch/ # Rust target/ diff --git a/book.toml b/book.toml index 2424153..7f6e4cb 100644 --- a/book.toml +++ b/book.toml @@ -14,3 +14,6 @@ edition = "2021" default-theme = "ayu" git-repository-url = "https://github.com/slackspace-io/slackwatch" highlight-code = true + +[output.html.redirect] +"index.yaml" = "https://raw.githubusercontent.com/slackspace-io/slackwatch/gh-pages/index.yaml" diff --git a/charts/slackwatch/Chart.yaml b/charts/slackwatch/Chart.yaml new file mode 100644 index 0000000..33bbc0b --- /dev/null +++ b/charts/slackwatch/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: slackwatch-helm +description: A Helm chart for Kubernetes to deploy Slackwatch +type: application +version: 0.1.0 +appVersion: 0.3.3 diff --git a/charts/slackwatch/templates/configmap.yaml b/charts/slackwatch/templates/configmap.yaml new file mode 100644 index 0000000..12aa0fe --- /dev/null +++ b/charts/slackwatch/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Chart.Name }}-config +data: + config.yaml: | + {{- if .Values.config }} + {{- toYaml .Values.config | nindent 4 }} + {{- end }} diff --git a/charts/slackwatch/templates/deployment.yaml b/charts/slackwatch/templates/deployment.yaml new file mode 100644 index 0000000..1951c99 --- /dev/null +++ b/charts/slackwatch/templates/deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Chart.Name }} + namespace: {{ .Release.Namespace }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ .Chart.Name }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ .Chart.Name }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + serviceAccountName: {{ .Chart.Name }}-serviceaccount + containers: + - name: slackwatch + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.port }} + volumeMounts: + - name: config-volume + mountPath: /app/config + volumes: + - name: config-volume + configMap: + name: {{ .Chart.Name }}-config diff --git a/charts/slackwatch/templates/ingress.yaml b/charts/slackwatch/templates/ingress.yaml new file mode 100644 index 0000000..1ad27a8 --- /dev/null +++ b/charts/slackwatch/templates/ingress.yaml @@ -0,0 +1,71 @@ +{{- if .Values.ingress.enabled -}} +{{- $paths := .Values.ingress.paths -}} +{{- $extraPaths := .Values.ingress.extraPaths -}} +{{- $pathType := .Values.ingress.pathType -}} +{{- $servicePort := .Values.service.port -}} +{{- $serviceName := .Chart.Name}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Chart.Name }}-ingress + namespace: {{ .Release.Namespace | quote }} + labels: + {{- with .Values.ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.ingressClassName }} + ingressClassName: {{ . }} + {{- end }} + rules: + {{- if .Values.ingress.hosts }} + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host | quote }} + http: + paths: + {{- with $extraPaths }} + {{- toYaml . | nindent 10 }} + {{- end }} + {{- range $p := $paths }} + - path: {{ $p }} + pathType: {{ $pathType }} + backend: + service: + name: {{ $serviceName }}-svc + port: + {{- if kindIs "float64" $servicePort }} + number: {{ $servicePort }} + {{- else }} + name: {{ $servicePort }} + {{- end }} + {{- end -}} + {{- end -}} + {{- else }} + - http: + paths: + {{- with $extraPaths }} + {{- toYaml . | nindent 10 }} + {{- end }} + {{- range $p := $paths }} + - path: {{ $p }} + pathType: {{ $pathType }} + backend: + service: + name: {{ .Chart.Name }}-svc + port: + {{- if kindIs "float64" $servicePort }} + number: {{ $servicePort }} + {{- else }} + name: {{ $servicePort }} + {{- end }} + {{- end -}} + {{- end -}} + {{- with .Values.ingress.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/slackwatch/templates/rbac.yaml b/charts/slackwatch/templates/rbac.yaml new file mode 100644 index 0000000..de40a64 --- /dev/null +++ b/charts/slackwatch/templates/rbac.yaml @@ -0,0 +1,23 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ .Chart.Name }}-clusterrole + namespace: {{ .Release.Namespace }} +rules: +- apiGroups: ["*"] + resources: ["*"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Chart.Name }}-clusterrolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ .Chart.Name }}-clusterrole +subjects: +- kind: ServiceAccount + name: {{ .Chart.Name }}-serviceaccount + namespace: {{ .Release.Namespace }} diff --git a/charts/slackwatch/templates/role.yaml b/charts/slackwatch/templates/role.yaml new file mode 100644 index 0000000..ec65433 --- /dev/null +++ b/charts/slackwatch/templates/role.yaml @@ -0,0 +1,23 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Chart.Name }}-role +rules: +- apiGroups: ["*"] + resources: ["*"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ .Chart.Name }}-rolebinding + namespace: {{ .Release.Namespace }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ .Chart.Name }}-role +subjects: +- kind: ServiceAccount + name: {{ .Chart.Name }}-serviceaccount + namespace: {{ .Release.Namespace }} diff --git a/charts/slackwatch/templates/service.yaml b/charts/slackwatch/templates/service.yaml new file mode 100644 index 0000000..258b459 --- /dev/null +++ b/charts/slackwatch/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Chart.Name }}-svc +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 8080 + selector: + app.kubernetes.io/name: {{ .Chart.Name }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/slackwatch/templates/serviceaccount.yaml b/charts/slackwatch/templates/serviceaccount.yaml new file mode 100644 index 0000000..03e3e7b --- /dev/null +++ b/charts/slackwatch/templates/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Chart.Name }}-serviceaccount + namespace: {{ .Release.Namespace }} diff --git a/charts/slackwatch/values.yaml b/charts/slackwatch/values.yaml new file mode 100644 index 0000000..65fd649 --- /dev/null +++ b/charts/slackwatch/values.yaml @@ -0,0 +1,51 @@ +replicaCount: 1 +namespace: slackwatch + +image: + repository: ghcr.io/slackspace-io/slackwatch # Assuming this image is accessible as a placeholder + pullPolicy: IfNotPresent + tag: "latest" + +service: + annotations: {} + labels: {} + type: ClusterIP + port: 80 + +ingress: + enabled: false + labels: {} + ingressClassName: "" + paths: + - / + pathType: Prefix + extraPaths: [] + https: false + annotations: {} + tls: [] + hosts: + - test.slackwatch.default # Placeholder domain + +config: + system: + #default schedule is every 2 hours + schedule: "0 0 */2 * *" + data_dir: "/app/slackwatch/data" + + notifications: + ntfy: + url: "http://ntfy-server.default:80" # Assumes an 'ntfy-server' available in the 'default' namespace + topic: "slackwatch-test" + token: "slackwatch-ntfy-token" + priority: 1 + reminder: "24h" + # ... other notification provider settings + + gitops: + - name: "test-repo" # Placeholder name + repository_url: "https://github.com/your-org/test-repo.git" + branch: "main" + access_token_env_name: "TEST_REPO_ACCESS_TOKEN" + commit_message: "Automated commit by slackwatch" + commit_email: "slackwatch@yourmail.default" + # ... other GitOps settings diff --git a/helm/config.toml b/helm/config.toml new file mode 100644 index 0000000..7c87b8a --- /dev/null +++ b/helm/config.toml @@ -0,0 +1,31 @@ + +[system] +schedule = "0 0 9-22/2 * * *" +data_dir = "/app/slackwatch/data" + +[notifications.ntfy] +url = "http://localhost:9090" +topic = "slackwatch" +priorty = 1 +reminder = "24h" +token = "dummy" + + +[[gitops]] +name = "fleet-slack-house" +repository_url = "https://github.com/slackspace-io/slackwatch.git" +branch = "main" +access_token_env_name = "SLACKWATCH_TOKEN" +commit_message = "Updated by slackwatch" +commit_name = "slackwatch" +commit_email = "slackwatch@slackspace.io" + +[[gitops]] +name = "noauth" +repository_url = "https://github.com/slackspace-io/slackwatch.git" +branch = "main" +access_token_env_name = "your_github_access_token_for_repoA" +commit_message = "Updated by slackwatch" +commit_name = "slackwatch" +commit_email = "slackwatch@slackspace.io" + diff --git a/src/config.rs b/src/config.rs index fc1f42a..fc3d947 100644 --- a/src/config.rs +++ b/src/config.rs @@ -50,7 +50,8 @@ impl Settings { let s = Config::builder() //add source if env var slackwatch_config path is set .add_source(File::with_name("/app/config/config").required(false)) - .add_source(File::with_name(".env.toml").required(false)) +// .add_source(File::with_name(".env.toml").required(false)) + .add_source(File::with_name(".env.yaml").required(false)) .add_source(File::with_name(&env_config).required(false)) .add_source(Environment::with_prefix("slackwatch")) .build()?;