From 0f867cd57624c4f28bbfcceda2bfd26447653e38 Mon Sep 17 00:00:00 2001 From: viktoryathegreat Date: Thu, 5 Sep 2024 16:38:08 +0400 Subject: [PATCH 1/2] fix(DMVP-5192): Updated cronjob's version to v1 --- helm/mongodb-backup-aws/templates/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/mongodb-backup-aws/templates/cronjob.yaml b/helm/mongodb-backup-aws/templates/cronjob.yaml index 99869fe..a4072e5 100644 --- a/helm/mongodb-backup-aws/templates/cronjob.yaml +++ b/helm/mongodb-backup-aws/templates/cronjob.yaml @@ -1,5 +1,5 @@ {{ if eq .Values.config.RUN_AS_DAEMON false }} -apiVersion: batch/v1beta1 +apiVersion: batch/v1 kind: CronJob metadata: name: {{ include "mongodb-backup-aws.fullname" . }} From e92584459ecde2bbfdbdd5161f4899480e197bf1 Mon Sep 17 00:00:00 2001 From: viktoryathegreat Date: Thu, 5 Sep 2024 16:42:05 +0400 Subject: [PATCH 2/2] fix(DMVP-5192): Docs update --- .github/workflows/checkov.yaml | 2 +- .github/workflows/terraform-test.yaml | 2 +- .github/workflows/tflint.yaml | 2 +- .github/workflows/verify.yml | 2 +- .gitignore | 2 +- .pre-commit-config.yaml | 4 +- README.md | 88 +++++++++++++++---- docker/README.md | 8 +- docker/docker-compose.yml | 4 +- githooks/commit-msg | 0 githooks/pre-commit | 0 .../mongodb-backup-aws/templates/service.yaml | 2 +- .../templates/volume-claim.yaml | 2 +- 13 files changed, 84 insertions(+), 34 deletions(-) mode change 100644 => 100755 githooks/commit-msg mode change 100644 => 100755 githooks/pre-commit diff --git a/.github/workflows/checkov.yaml b/.github/workflows/checkov.yaml index 960e52f..d1f1f8b 100644 --- a/.github/workflows/checkov.yaml +++ b/.github/workflows/checkov.yaml @@ -17,7 +17,7 @@ jobs: matrix: path: - / - + steps: - uses: dasmeta/reusable-actions-workflows/checkov@4.2.0 with: diff --git a/.github/workflows/terraform-test.yaml b/.github/workflows/terraform-test.yaml index 8a0f009..b498c3e 100644 --- a/.github/workflows/terraform-test.yaml +++ b/.github/workflows/terraform-test.yaml @@ -16,7 +16,7 @@ jobs: matrix: path: - / - + steps: - uses: dasmeta/reusable-actions-workflows/terraform-test@4.2.0 with: diff --git a/.github/workflows/tflint.yaml b/.github/workflows/tflint.yaml index 78eb241..fc93d7e 100644 --- a/.github/workflows/tflint.yaml +++ b/.github/workflows/tflint.yaml @@ -18,7 +18,7 @@ jobs: matrix: path: - / - + steps: - uses: dasmeta/reusable-actions-workflows/tflint@4.2.0 with: diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 6a6ac15..21d82df 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -13,7 +13,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Fetch history - run: git fetch --prune --unshallow + run: git fetch --prune --unshallow - name: Run lint uses: helm/chart-testing-action@v1.1.0 with: diff --git a/.gitignore b/.gitignore index b07e9cf..1d4006d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -backup \ No newline at end of file +backup diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd2b6fa..5d420d8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,13 +9,13 @@ repos: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] exclude: CHANGELOG.md - - id: check-yaml + # - id: check-yaml - id: check-merge-conflict - id: check-case-conflict - id: mixed-line-ending args: [--fix=lf] - id: detect-aws-credentials - args: ['--allow-missing-credentials'] + args: ["--allow-missing-credentials"] - id: detect-private-key - repo: https://github.com/antonbabenko/pre-commit-terraform rev: v1.64.1 diff --git a/README.md b/README.md index e5d4d1f..1d0ff3b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Helm chart install Terraform module to backup and restore a Mongo database. `mongodb_backup_minimal`: - ```hcl module mongodb_backup_minimal { @@ -32,11 +31,11 @@ module mongodb_backup_connection_url { app_name = "test" mongodb_host = "localhost" mongodb_uri = "mongodb+srv://..." - cron_schedule = "*/5 * * * *" + cron_schedule = "*/5 * * * *" run_as_daemon = "false" init_backup = "false" backup_user_name = "backup_user" - s3_bucket = "mongoatlas-dev-backup" + s3_bucket = "mongoatlas-dev-backup" } ``` @@ -72,19 +71,70 @@ module mongodb_backup_advanced { ``` ### Environment variables -#### `Note: Some variables are required` -| Environment Variables | Description | -| ------ | ------ | -|`mongodb_host`|(required) This is gonna be Mongo database Host name| -|`mongodb_port`|(Optional) Mongo database host Port| -|`mongodb_uri`|(Optional) Mongo connection uri| -|`mongodb_username`|(required) Mongo database username| -|`mongodb_password`|(required) Mongo database password| -|`aws_default_region`|(required) Set aws default region. See [Amazon Web Services](https://console.aws.amazon.com/)| -|`backup_user_name`|(required) this is the aws user name to create and provide accesses for pushing backup to S3| -|`s3_bucket`|(Optional) If bucket variable is set the backups will be shipped/restored to/from Amazon S3 Bucket. `Otherwise It will be saved locally.`| -|`max_backups`| (Optional) Count of maximum backups on local machine. `Necessary if S3_BUCKET variable is not set. Default value is 30`| -|`cron_schedule`| Please visit [CRON SCHEDULE](https://crontab.guru/) to choose your specific schedule time.| -|`run_as_daemon`| in case this prop value is "true" the an "Deployment" kind (k8s object type) will be created else wise the kind will be "CronJob".| -|`init_backup`|(Optional) To make mongo backup on container startup mark value `true`. `Default is: 'false'`. If `S3_BUCKET` is set, the latest backup will be shipped to bucket. Otherwise, database will be saved on local volume.| -|`init_restore`|(Optional) To make mongo restore on container startup mark value `true`. `Default is: 'false'`. If `S3_BUCKET` is set, the latest backup will be downloaded from bucket. Otherwise, database will be restored from the local volume.| +#### `Note: Some variables are required` +| Environment Variables | Description | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `mongodb_host` | (required) This is gonna be Mongo database Host name | +| `mongodb_port` | (Optional) Mongo database host Port | +| `mongodb_uri` | (Optional) Mongo connection uri | +| `mongodb_username` | (required) Mongo database username | +| `mongodb_password` | (required) Mongo database password | +| `aws_default_region` | (required) Set aws default region. See [Amazon Web Services](https://console.aws.amazon.com/) | +| `backup_user_name` | (required) this is the aws user name to create and provide accesses for pushing backup to S3 | +| `s3_bucket` | (Optional) If bucket variable is set the backups will be shipped/restored to/from Amazon S3 Bucket. `Otherwise It will be saved locally.` | +| `max_backups` | (Optional) Count of maximum backups on local machine. `Necessary if S3_BUCKET variable is not set. Default value is 30` | +| `cron_schedule` | Please visit [CRON SCHEDULE](https://crontab.guru/) to choose your specific schedule time. | +| `run_as_daemon` | in case this prop value is "true" the an "Deployment" kind (k8s object type) will be created else wise the kind will be "CronJob". | +| `init_backup` | (Optional) To make mongo backup on container startup mark value `true`. `Default is: 'false'`. If `S3_BUCKET` is set, the latest backup will be shipped to bucket. Otherwise, database will be saved on local volume. | +| `init_restore` | (Optional) To make mongo restore on container startup mark value `true`. `Default is: 'false'`. If `S3_BUCKET` is set, the latest backup will be downloaded from bucket. Otherwise, database will be restored from the local volume. | + +## Requirements + +No requirements. + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [mongodb\_backup\_s3\_storage\_user](#module\_mongodb\_backup\_s3\_storage\_user) | dasmeta/modules/aws//modules/aws-iam-user | 0.36.8 | +| [release](#module\_release) | terraform-module/release/helm | 2.7.0 | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [app\_name](#input\_app\_name) | Helm app/release name | `string` | `"mongodb-backup-aws"` | no | +| [app\_version](#input\_app\_version) | Helm app/release version | `string` | `"0.1.0"` | no | +| [aws\_default\_region](#input\_aws\_default\_region) | aws-default-region. | `string` | `"eu-central-1"` | no | +| [backup\_user\_name](#input\_backup\_user\_name) | Backup user name for s3 bucket | `string` | `"mongodb-backup-s3-bucket"` | no | +| [create\_user](#input\_create\_user) | Create User for S3 | `bool` | `true` | no | +| [cron\_schedule](#input\_cron\_schedule) | Backup schedule, in crojob format. E.g. '3 0 * * *' | `string` | `"3 0 * * *"` | no | +| [init\_backup](#input\_init\_backup) | If enabled scripts will do backup right on the start and then according to the schedule. | `string` | `false` | no | +| [init\_restore](#input\_init\_restore) | If enabled scripts will do restore right on the start and then according to the schedule. | `string` | `false` | no | +| [max\_backups](#input\_max\_backups) | Max backups' | `string` | `"30"` | no | +| [mongodb\_database](#input\_mongodb\_database) | Mongodb database to be backed up. All databases will be backed up if not specified. | `string` | `""` | no | +| [mongodb\_exclude\_collections](#input\_mongodb\_exclude\_collections) | Mongodb collections to be excluded from the backup. All collections will be backed up if not specified. | `string` | `""` | no | +| [mongodb\_host](#input\_mongodb\_host) | Mongodb host name backup script will be taking data from. | `string` | `"localhost"` | no | +| [mongodb\_password](#input\_mongodb\_password) | Mongodb user password script will need to pull data from mongodb. | `string` | `""` | no | +| [mongodb\_port](#input\_mongodb\_port) | Mongodb user password script will need to pull data from mongodb. | `string` | `"27017"` | no | +| [mongodb\_uri](#input\_mongodb\_uri) | --uri param from mongodump docs | `string` | `""` | no | +| [mongodb\_username](#input\_mongodb\_username) | Mongodb user name script will need to pull data from mongodb. | `string` | `""` | no | +| [namespace](#input\_namespace) | Helm app/release namespace | `string` | `"default"` | no | +| [resources](#input\_resources) | Allows to set cpu/memory resources Limits/Requests for deployment/cronjob |
object({
limits = object({
cpu = string
memory = string
})
requests = object({
cpu = string
memory = string
})
})
|
{
"limits": {
"cpu": "300m",
"memory": "500Mi"
},
"requests": {
"cpu": "300m",
"memory": "500Mi"
}
}
| no | +| [run\_as\_daemon](#input\_run\_as\_daemon) | in case of true deployment will be created (as daemon) elwise kube cronJob will be created | `string` | `"false"` | no | +| [s3\_bucket](#input\_s3\_bucket) | The bucket backups will be stored. | `string` | n/a | yes | +| [volume\_size](#input\_volume\_size) | Size of the backup volume storage. Should be enough big to fit backup files. | `string` | `"10Gi"` | no | +| [volume\_storageClass](#input\_volume\_storageClass) | Volume strage class AWS will be claimed for. No need for fast storage as this will be used once during backup. | `string` | `"gp2"` | no | + +## Outputs + +No outputs. + diff --git a/docker/README.md b/docker/README.md index 41459fc..d6ac50e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,10 +9,10 @@ To backup a Mongo DB container you simply have to build Docker image from follow docker build -t image_name . - + Please note the backup will be written to /backup by default, so you might want to mount that directory from your host. -## Useful example via docker compose +## Useful example via docker compose ``` mongo_backup: @@ -38,7 +38,7 @@ mongo_backup: ``` ### Environment variables -#### `Note: Some variables are required` +#### `Note: Some variables are required` | Environment Variables | Description | | ------ | ------ | |`MONGODB_HOST`|(required) This is gonna be Mongo database Host name| @@ -58,4 +58,4 @@ mongo_backup: It would be better to write environment variables in `.env` file. ## How to helm -`helm upgrade --install mongodb-backup-aws .` \ No newline at end of file +`helm upgrade --install mongodb-backup-aws .` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f23f1e2..97a22c6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -10,7 +10,7 @@ services: environment: MONGODB_HOST: host MONGODB_PORT: port - MONGODB_URI: + MONGODB_URI: MONGO_INITDB_ROOT_USERNAME: user MONGO_INITDB_ROOT_PASSWORD: example AWS_ACCESS_KEY_ID: account_key_id @@ -20,4 +20,4 @@ services: MAX_BACKUPS: 30 CRON_SCHEDULE: "* */3 * * *" INIT_BACKUP: 'false' - INIT_RESTORE: 'false' \ No newline at end of file + INIT_RESTORE: 'false' diff --git a/githooks/commit-msg b/githooks/commit-msg old mode 100644 new mode 100755 diff --git a/githooks/pre-commit b/githooks/pre-commit old mode 100644 new mode 100755 diff --git a/helm/mongodb-backup-aws/templates/service.yaml b/helm/mongodb-backup-aws/templates/service.yaml index 51fd5a7..ea0c521 100644 --- a/helm/mongodb-backup-aws/templates/service.yaml +++ b/helm/mongodb-backup-aws/templates/service.yaml @@ -14,4 +14,4 @@ spec: name: http selector: {{- include "mongodb-backup-aws.selectorLabels" . | nindent 4 }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/helm/mongodb-backup-aws/templates/volume-claim.yaml b/helm/mongodb-backup-aws/templates/volume-claim.yaml index cd714a2..630fe7f 100644 --- a/helm/mongodb-backup-aws/templates/volume-claim.yaml +++ b/helm/mongodb-backup-aws/templates/volume-claim.yaml @@ -11,4 +11,4 @@ spec: resources: requests: storage: {{ default "1Gi" .Values.volume.size }} - storageClassName: {{ default "gp2" .Values.volume.storageClass }} \ No newline at end of file + storageClassName: {{ default "gp2" .Values.volume.storageClass }}