mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b0e7c7c60 | ||
|
|
d091f3030b | ||
|
|
44ead050c7 | ||
|
|
c5a15ed5d4 | ||
|
|
a27dd320e6 | ||
|
|
0c53bf72e4 |
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -55,12 +55,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
working-directory: operator
|
working-directory: images/operator
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
working-directory: operator
|
working-directory: images/operator
|
||||||
run: pnpm test
|
run: pnpm test
|
||||||
|
|
||||||
update-release-draft:
|
update-release-draft:
|
||||||
|
|||||||
65
.github/workflows/publish-backup-tag.yml
vendored
Normal file
65
.github/workflows/publish-backup-tag.yml
vendored
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
name: Publish tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "main"
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
env:
|
||||||
|
environment: test
|
||||||
|
release_channel: latest
|
||||||
|
DO_NOT_TRACK: "1"
|
||||||
|
NODE_VERSION: "23.x"
|
||||||
|
DOCKER_REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}-backup
|
||||||
|
PNPM_VERSION: 10.6.0
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
attestations: write
|
||||||
|
id-token: write
|
||||||
|
pages: write
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.DOCKER_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.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
id: push
|
||||||
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
|
with:
|
||||||
|
context: ./images/backup
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
- name: Generate artifact attestation
|
||||||
|
uses: actions/attest-build-provenance@v2
|
||||||
|
with:
|
||||||
|
subject-name: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME}}
|
||||||
|
subject-digest: ${{ steps.push.outputs.digest }}
|
||||||
|
push-to-registry: true
|
||||||
2
.github/workflows/publish-tag.yml
vendored
2
.github/workflows/publish-tag.yml
vendored
@@ -52,7 +52,7 @@ jobs:
|
|||||||
id: push
|
id: push
|
||||||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
with:
|
with:
|
||||||
context: ./operator
|
context: ./images/operator
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
136
charts/apps/AGENT.md
Normal file
136
charts/apps/AGENT.md
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Agent Documentation
|
||||||
|
|
||||||
|
This document describes how to create a new application chart for the homelab operator.
|
||||||
|
|
||||||
|
## Chart Structure
|
||||||
|
|
||||||
|
Each application has its own chart located in a directory under `charts/apps`. The chart should contain the following files:
|
||||||
|
|
||||||
|
- `Chart.yaml`: The chart metadata.
|
||||||
|
- `values.yaml`: The default values for the chart.
|
||||||
|
- `templates/`: A directory containing the Kubernetes resource templates.
|
||||||
|
|
||||||
|
## Custom Resources
|
||||||
|
|
||||||
|
The homelab operator uses several custom resources to manage applications. These resources are defined in the `templates` directory of the chart.
|
||||||
|
|
||||||
|
### `PostgresDatabase`
|
||||||
|
|
||||||
|
If the application requires a PostgreSQL database, you can create a `PostgresDatabase` resource. The operator will automatically create a database and a secret containing the connection details. The secret will have the same name as the release with a `-pg-connection` postfix.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# templates/database.yaml
|
||||||
|
apiVersion: homelab.mortenolsen.pro/v1
|
||||||
|
kind: PostgresDatabase
|
||||||
|
metadata:
|
||||||
|
name: "{{ .Release.Name }}"
|
||||||
|
spec:
|
||||||
|
environment: "{{ .Values.globals.environment }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
The secret has the following values:
|
||||||
|
|
||||||
|
- `database`: name of the created database
|
||||||
|
- `host`: the hostname of the postgres server
|
||||||
|
- `port`: the port of the postgres server
|
||||||
|
- `url`: combined url in the format `postgresql://{user}:{password}@{host}:{port}/{database}`
|
||||||
|
|
||||||
|
### `OidcClient`
|
||||||
|
|
||||||
|
If the application requires OIDC authentication, you can create an `OidcClient` resource. The operator will automatically create an OIDC client and a secret containing the client ID and secret. The secret will have the same name as the release with a `-client` postfix.
|
||||||
|
|
||||||
|
You need to specify the redirect URIs for the OIDC client. The subdomain is taken from the `values.yaml` file.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# templates/client.yaml
|
||||||
|
apiVersion: homelab.mortenolsen.pro/v1
|
||||||
|
kind: OidcClient
|
||||||
|
metadata:
|
||||||
|
name: "{{ .Release.Name }}"
|
||||||
|
spec:
|
||||||
|
environment: "{{ .Values.globals.environment }}"
|
||||||
|
redirectUris:
|
||||||
|
- path: /user/oauth2/Authentik/callback
|
||||||
|
subdomain: "{{ .Values.subdomain }}"
|
||||||
|
matchingMode: strict
|
||||||
|
```
|
||||||
|
|
||||||
|
The secret has the following value:
|
||||||
|
|
||||||
|
- `authorization`: Authorization endpoint
|
||||||
|
- `clientId`
|
||||||
|
- `clientSecret`
|
||||||
|
- `configuration`: autodiscovery endpoint
|
||||||
|
- `configurationIssuer`: issuer url
|
||||||
|
- `endSession`: end session endpoint
|
||||||
|
- `jwks`: jwks endpoint
|
||||||
|
- `token`: token endpoint
|
||||||
|
- `userinfo`: user info endpoint
|
||||||
|
|
||||||
|
### `HttpService` and `ExternalHttpService`
|
||||||
|
|
||||||
|
To expose the application, you can use either an `HttpService` or an `ExternalHttpService` resource.
|
||||||
|
|
||||||
|
- `HttpService`: This will expose the application through the Istio gateway. This is for internal access only.
|
||||||
|
- `ExternalHttpService`: This will expose the application through a CloudFlare tunnel. This is for external access.
|
||||||
|
|
||||||
|
Both resources take a `subdomain` and a `destination` as parameters. The `destination` is the Kubernetes service to route traffic to.
|
||||||
|
|
||||||
|
Example of `HttpService`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# templates/http-service.yaml
|
||||||
|
apiVersion: homelab.mortenolsen.pro/v1
|
||||||
|
kind: HttpService
|
||||||
|
metadata:
|
||||||
|
name: "{{ .Release.Name }}"
|
||||||
|
spec:
|
||||||
|
environment: "{{ .Values.globals.environment }}"
|
||||||
|
subdomain: "{{ .Values.subdomain }}"
|
||||||
|
destination:
|
||||||
|
host: "{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local"
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
```
|
||||||
|
|
||||||
|
Example of `ExternalHttpService`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# templates/external-http-service.yaml
|
||||||
|
apiVersion: homelab.mortenolsen.pro/v1
|
||||||
|
kind: ExternalHttpService
|
||||||
|
metadata:
|
||||||
|
name: "{{ .Release.Name }}"
|
||||||
|
spec:
|
||||||
|
environment: "{{ .Values.globals.environment }}"
|
||||||
|
subdomain: "{{ .Values.subdomain }}"
|
||||||
|
destination:
|
||||||
|
host: "{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local"
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
```
|
||||||
|
|
||||||
|
## `values.yaml`
|
||||||
|
|
||||||
|
The `values.yaml` file should contain the following values:
|
||||||
|
|
||||||
|
- `globals.environment`: The environment the application is running in (e.g., `prod`, `dev`).
|
||||||
|
- `image.repository`: The Docker image repository.
|
||||||
|
- `image.tag`: The Docker image tag.
|
||||||
|
- `subdomain`: The subdomain for the application.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# values.yaml
|
||||||
|
globals:
|
||||||
|
environment: prod
|
||||||
|
image:
|
||||||
|
repository: docker.gitea.com/gitea
|
||||||
|
tag: latest
|
||||||
|
subdomain: gitea
|
||||||
|
```
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: movies
|
|
||||||
labels:
|
|
||||||
type: nfs
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 10Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
persistentVolumeReclaimPolicy: Retain
|
|
||||||
storageClassName: manual-movies
|
|
||||||
nfs:
|
|
||||||
path: '{{ .Values.movies.path }}'
|
|
||||||
server: '{{ .Values.host }}'
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: movies
|
|
||||||
spec:
|
|
||||||
storageClassName: manual-movies
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: music
|
|
||||||
labels:
|
|
||||||
type: nfs
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 10Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
persistentVolumeReclaimPolicy: Retain
|
|
||||||
storageClassName: manual-music
|
|
||||||
nfs:
|
|
||||||
path: '{{ .Values.music.path }}'
|
|
||||||
server: '{{ .Values.host }}'
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: music
|
|
||||||
spec:
|
|
||||||
storageClassName: manual-music
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: pictures
|
|
||||||
labels:
|
|
||||||
type: nfs
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 10Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
persistentVolumeReclaimPolicy: Retain
|
|
||||||
storageClassName: manual-pictures
|
|
||||||
nfs:
|
|
||||||
path: '{{ .Values.pictures.path }}'
|
|
||||||
server: '{{ .Values.host }}'
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: pictures
|
|
||||||
spec:
|
|
||||||
storageClassName: manual-pictures
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: podcasts
|
|
||||||
labels:
|
|
||||||
type: nfs
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 10Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
persistentVolumeReclaimPolicy: Retain
|
|
||||||
storageClassName: manual-podcasts
|
|
||||||
nfs:
|
|
||||||
path: '{{ .Values.podcasts.path }}'
|
|
||||||
server: '{{ .Values.host }}'
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: podcasts
|
|
||||||
spec:
|
|
||||||
storageClassName: manual-podcasts
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
{{- $values := .Values -}}
|
||||||
|
{{- $release := .Release -}}
|
||||||
|
|
||||||
|
---
|
||||||
|
{{- range $key, $value := $values.shares }}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolume
|
kind: PersistentVolume
|
||||||
metadata:
|
metadata:
|
||||||
name: books
|
name: "{{$key}}"
|
||||||
labels:
|
labels:
|
||||||
type: nfs
|
type: nfs
|
||||||
spec:
|
spec:
|
||||||
@@ -10,19 +15,22 @@ spec:
|
|||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteMany
|
- ReadWriteMany
|
||||||
persistentVolumeReclaimPolicy: Retain
|
persistentVolumeReclaimPolicy: Retain
|
||||||
storageClassName: manual-books
|
storageClassName: "manual-{{$key}}"
|
||||||
nfs:
|
nfs:
|
||||||
path: '{{ .Values.books.path }}'
|
path: "{{ $value.path }}"
|
||||||
server: '{{ .Values.host }}'
|
server: "{{ $values.host }}"
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
metadata:
|
metadata:
|
||||||
name: books
|
name: "{{ $key }}"
|
||||||
spec:
|
spec:
|
||||||
storageClassName: manual-books
|
storageClassName: "manual-{{ $key }}"
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteMany
|
- ReadWriteMany
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 10Gi
|
storage: 10Gi
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: tvshows
|
|
||||||
labels:
|
|
||||||
type: nfs
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 10Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
persistentVolumeReclaimPolicy: Retain
|
|
||||||
storageClassName: manual-tvshows
|
|
||||||
nfs:
|
|
||||||
path: '{{ .Values.tvshows.path }}'
|
|
||||||
server: '{{ .Values.host }}'
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: tvshows
|
|
||||||
spec:
|
|
||||||
storageClassName: manual-tvshows
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
host: 192.168.20.106
|
host: 192.168.20.106
|
||||||
|
shares:
|
||||||
movies:
|
movies:
|
||||||
path: /mnt/HDD/Movies
|
path: /mnt/HDD/Movies
|
||||||
tvshows:
|
tvshows:
|
||||||
@@ -11,3 +12,5 @@ podcasts:
|
|||||||
path: /mnt/HDD/Podcasts
|
path: /mnt/HDD/Podcasts
|
||||||
pictures:
|
pictures:
|
||||||
path: /mnt/HDD/Pictures
|
path: /mnt/HDD/Pictures
|
||||||
|
backups:
|
||||||
|
path: /mnt/HDD/Backups
|
||||||
|
|||||||
3
charts/backup/Chart.yaml
Normal file
3
charts/backup/Chart.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
version: 1.0.0
|
||||||
|
name: backup
|
||||||
45
charts/backup/templates/cron-job-backup.yaml
Normal file
45
charts/backup/templates/cron-job-backup.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{{- $values := .Values -}}
|
||||||
|
{{- $release := .Release -}}
|
||||||
|
|
||||||
|
---
|
||||||
|
{{- range $key, $value := $values.jobs}}
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: "{{ $release.Name }}-{{ $key }}-backup"
|
||||||
|
spec:
|
||||||
|
schedule: "{{ $value.cron.backup }}"
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: "{{ $release.Name }}-{{ $key }}-backup"
|
||||||
|
image: ghcr.io/morten-olsen/homelab-operator-backup:main
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command: ["/app/backup.sh"]
|
||||||
|
env:
|
||||||
|
- name: RESTIC_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "{{ $values.password.name }}"
|
||||||
|
key: "{{ $values.password.key }}"
|
||||||
|
volumeMounts:
|
||||||
|
- name: source
|
||||||
|
mountPath: "/mnt/source"
|
||||||
|
- name: target
|
||||||
|
mountPath: "/mnt/backup"
|
||||||
|
subPath: "{{ $release.Name }}-{{ $key }}"
|
||||||
|
volumes:
|
||||||
|
- name: source
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $value.source }}"
|
||||||
|
- name: target
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $values.target }}"
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
40
charts/backup/templates/cron-job-cleanup.yaml
Normal file
40
charts/backup/templates/cron-job-cleanup.yaml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{{- $values := .Values -}}
|
||||||
|
{{- $release := .Release -}}
|
||||||
|
|
||||||
|
---
|
||||||
|
{{- range $key, $value := $values.jobs}}
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: "{{ $release.Name }}-{{ $key }}-cleanup"
|
||||||
|
spec:
|
||||||
|
schedule: "{{ $value.cron.cleanup }}"
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: "{{ $release.Name }}-{{ $key }}-cleanup"
|
||||||
|
image: ghcr.io/morten-olsen/homelab-operator-backup:main
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command: ["/app/cleanup.sh"]
|
||||||
|
env:
|
||||||
|
- name: RESTIC_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "{{ $values.password.name }}"
|
||||||
|
key: "{{ $values.password.key }}"
|
||||||
|
volumeMounts:
|
||||||
|
- name: target
|
||||||
|
mountPath: "/mnt/backup"
|
||||||
|
subPath: "{{ $release.Name }}-{{ $key }}"
|
||||||
|
volumes:
|
||||||
|
- name: target
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $values.target }}"
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
10
charts/backup/values.yaml
Normal file
10
charts/backup/values.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
password:
|
||||||
|
name: backup
|
||||||
|
key: password
|
||||||
|
jobs:
|
||||||
|
pictures:
|
||||||
|
cron:
|
||||||
|
backup: "0 2 * * *"
|
||||||
|
cleanup: "0 4 * * SUN"
|
||||||
|
source: pictures
|
||||||
|
target: backups
|
||||||
10
images/backup/Dockerfile
Normal file
10
images/backup/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM alpine/git:latest
|
||||||
|
# or a more specific image like a Debian slim or Ubuntu base image.
|
||||||
|
RUN apk add --no-cache restic fuse-overlayfs
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY backup.sh /app/backup.sh
|
||||||
|
COPY cleanup.sh /app/cleanup.sh
|
||||||
|
|
||||||
|
# Make scripts executable
|
||||||
|
RUN chmod +x /app/backup.sh /app/cleanup.sh
|
||||||
35
images/backup/backup.sh
Normal file
35
images/backup/backup.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "$RESTIC_PASSWORD" ]; then
|
||||||
|
echo "Error: RESTIC_PASSWORD environment variable is not set." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
RESTIC_REPOSITORY="/mnt/backup"
|
||||||
|
SOURCE_DIR="/mnt/source"
|
||||||
|
|
||||||
|
mkdir -p "$SOURCE_DIR"
|
||||||
|
mkdir -p "/mnt/backup"
|
||||||
|
|
||||||
|
echo "Starting Restic backup from $SOURCE_DIR to $RESTIC_REPOSITORY"
|
||||||
|
|
||||||
|
echo "Checking/Initializing Restic repository..."
|
||||||
|
restic init --repo "$RESTIC_REPOSITORY" || true
|
||||||
|
|
||||||
|
echo "Running Restic backup..."
|
||||||
|
restic backup \
|
||||||
|
-r "$RESTIC_REPOSITORY"
|
||||||
|
"$SOURCE_DIR" \
|
||||||
|
--verbose \
|
||||||
|
--tag "daily"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Restic backup completed successfully!"
|
||||||
|
else
|
||||||
|
echo "Restic backup failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Backup finished."
|
||||||
42
images/backup/cleanup.sh
Normal file
42
images/backup/cleanup.sh
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "$RESTIC_PASSWORD" ]; then
|
||||||
|
echo "Error: RESTIC_PASSWORD environment variable is not set." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
RESTIC_REPOSITORY="/mnt/backup"
|
||||||
|
|
||||||
|
echo "Starting Restic cleanup for repository $RESTIC_REPOSITORY"
|
||||||
|
|
||||||
|
echo "Checking Restic repository existence..."
|
||||||
|
restic snapshots --repository "$RESTIC_REPOSITORY"
|
||||||
|
|
||||||
|
# Restic forget and prune strategy
|
||||||
|
# --keep-daily 7: Keep 7 most recent daily backups
|
||||||
|
# --keep-weekly 4: Keep 4 most recent weekly backups
|
||||||
|
# --keep-monthly 6: Keep 6 most recent monthly backups
|
||||||
|
# --keep-yearly 1: Keep 1 most recent yearly backup
|
||||||
|
# --prune: Actually delete data that's no longer referenced
|
||||||
|
# --group-by host,paths: Group snapshots for retention by host and path.
|
||||||
|
echo "Running Restic forget and prune..."
|
||||||
|
restic forget \
|
||||||
|
--group-by host,paths \
|
||||||
|
--tag "daily" \
|
||||||
|
--keep-daily 7 \
|
||||||
|
--keep-weekly 4 \
|
||||||
|
--keep-monthly 6 \
|
||||||
|
--keep-yearly 1 \
|
||||||
|
--prune \
|
||||||
|
--verbose \
|
||||||
|
--repository "$RESTIC_REPOSITORY"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Restic cleanup completed successfully!"
|
||||||
|
else
|
||||||
|
echo "Restic cleanup failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Cleanup finished."
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user