Skip to content

Commit

Permalink
Merge pull request #24 from dasmeta/DMVP-5192-upgrade-versions
Browse files Browse the repository at this point in the history
fix(DMVP-5192): Upgrade CronJob versions
  • Loading branch information
viktoryathegreat authored Sep 5, 2024
2 parents 32417f7 + e925844 commit 36b0cd8
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checkov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
path:
- /

steps:
- uses: dasmeta/reusable-actions-workflows/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
path:
- /

steps:
- uses: dasmeta/reusable-actions-workflows/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tflint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
path:
- /

steps:
- uses: dasmeta/reusable-actions-workflows/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea
backup
backup
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 69 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Helm chart install Terraform module to backup and restore a Mongo database.

`mongodb_backup_minimal`:


```hcl
module mongodb_backup_minimal {
Expand All @@ -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"
}
```

Expand Down Expand Up @@ -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. |
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_mongodb_backup_s3_storage_user"></a> [mongodb\_backup\_s3\_storage\_user](#module\_mongodb\_backup\_s3\_storage\_user) | dasmeta/modules/aws//modules/aws-iam-user | 0.36.8 |
| <a name="module_release"></a> [release](#module\_release) | terraform-module/release/helm | 2.7.0 |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_app_name"></a> [app\_name](#input\_app\_name) | Helm app/release name | `string` | `"mongodb-backup-aws"` | no |
| <a name="input_app_version"></a> [app\_version](#input\_app\_version) | Helm app/release version | `string` | `"0.1.0"` | no |
| <a name="input_aws_default_region"></a> [aws\_default\_region](#input\_aws\_default\_region) | aws-default-region. | `string` | `"eu-central-1"` | no |
| <a name="input_backup_user_name"></a> [backup\_user\_name](#input\_backup\_user\_name) | Backup user name for s3 bucket | `string` | `"mongodb-backup-s3-bucket"` | no |
| <a name="input_create_user"></a> [create\_user](#input\_create\_user) | Create User for S3 | `bool` | `true` | no |
| <a name="input_cron_schedule"></a> [cron\_schedule](#input\_cron\_schedule) | Backup schedule, in crojob format. E.g. '3 0 * * *' | `string` | `"3 0 * * *"` | no |
| <a name="input_init_backup"></a> [init\_backup](#input\_init\_backup) | If enabled scripts will do backup right on the start and then according to the schedule. | `string` | `false` | no |
| <a name="input_init_restore"></a> [init\_restore](#input\_init\_restore) | If enabled scripts will do restore right on the start and then according to the schedule. | `string` | `false` | no |
| <a name="input_max_backups"></a> [max\_backups](#input\_max\_backups) | Max backups' | `string` | `"30"` | no |
| <a name="input_mongodb_database"></a> [mongodb\_database](#input\_mongodb\_database) | Mongodb database to be backed up. All databases will be backed up if not specified. | `string` | `""` | no |
| <a name="input_mongodb_exclude_collections"></a> [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 |
| <a name="input_mongodb_host"></a> [mongodb\_host](#input\_mongodb\_host) | Mongodb host name backup script will be taking data from. | `string` | `"localhost"` | no |
| <a name="input_mongodb_password"></a> [mongodb\_password](#input\_mongodb\_password) | Mongodb user password script will need to pull data from mongodb. | `string` | `""` | no |
| <a name="input_mongodb_port"></a> [mongodb\_port](#input\_mongodb\_port) | Mongodb user password script will need to pull data from mongodb. | `string` | `"27017"` | no |
| <a name="input_mongodb_uri"></a> [mongodb\_uri](#input\_mongodb\_uri) | --uri param from mongodump docs | `string` | `""` | no |
| <a name="input_mongodb_username"></a> [mongodb\_username](#input\_mongodb\_username) | Mongodb user name script will need to pull data from mongodb. | `string` | `""` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Helm app/release namespace | `string` | `"default"` | no |
| <a name="input_resources"></a> [resources](#input\_resources) | Allows to set cpu/memory resources Limits/Requests for deployment/cronjob | <pre>object({<br> limits = object({<br> cpu = string<br> memory = string<br> })<br> requests = object({<br> cpu = string<br> memory = string<br> })<br> })</pre> | <pre>{<br> "limits": {<br> "cpu": "300m",<br> "memory": "500Mi"<br> },<br> "requests": {<br> "cpu": "300m",<br> "memory": "500Mi"<br> }<br>}</pre> | no |
| <a name="input_run_as_daemon"></a> [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 |
| <a name="input_s3_bucket"></a> [s3\_bucket](#input\_s3\_bucket) | The bucket backups will be stored. | `string` | n/a | yes |
| <a name="input_volume_size"></a> [volume\_size](#input\_volume\_size) | Size of the backup volume storage. Should be enough big to fit backup files. | `string` | `"10Gi"` | no |
| <a name="input_volume_storageClass"></a> [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.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8 changes: 4 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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|
Expand All @@ -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 .`
`helm upgrade --install mongodb-backup-aws .`
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,4 +20,4 @@ services:
MAX_BACKUPS: 30
CRON_SCHEDULE: "* */3 * * *"
INIT_BACKUP: 'false'
INIT_RESTORE: 'false'
INIT_RESTORE: 'false'
Empty file modified githooks/commit-msg
100644 → 100755
Empty file.
Empty file modified githooks/pre-commit
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion helm/mongodb-backup-aws/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -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" . }}
Expand Down
2 changes: 1 addition & 1 deletion helm/mongodb-backup-aws/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ spec:
name: http
selector:
{{- include "mongodb-backup-aws.selectorLabels" . | nindent 4 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion helm/mongodb-backup-aws/templates/volume-claim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
resources:
requests:
storage: {{ default "1Gi" .Values.volume.size }}
storageClassName: {{ default "gp2" .Values.volume.storageClass }}
storageClassName: {{ default "gp2" .Values.volume.storageClass }}

0 comments on commit 36b0cd8

Please sign in to comment.