Skip to content

Commit 8aa3f8c

Browse files
committed
add precommit and fix postgres job
1 parent 03b99f5 commit 8aa3f8c

8 files changed

Lines changed: 106 additions & 17 deletions

File tree

‎.github/workflows/pre-commit.yml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Pre-Commit Checks
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
pre-commit:
7+
runs-on: ubuntu-22.04
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v3
11+
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.11'
16+
17+
- name: Install pre-commit
18+
run: pip install pre-commit
19+
20+
- name: Run pre-commit hooks
21+
run: |
22+
git fetch origin main || git fetch origin master
23+
base_commit=$(git rev-parse --verify origin/main || git rev-parse --verify origin/master || echo "")
24+
25+
if [ -z "$base_commit" ]; then
26+
files=$(git ls-files '*.yaml' '*.md')
27+
else
28+
files=$(git diff --name-only "$base_commit" -- '*.yaml' '*.md')
29+
fi
30+
31+
if [ -n "$files" ]; then
32+
echo "$files" | xargs pre-commit run --files
33+
else
34+
echo "No YAML or Markdown files to lint"
35+
fi

‎.pre-commit-config.yaml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- id: mixed-line-ending
8+
args: [--fix=lf]
9+
- id: check-yaml
10+
exclude: packages/apps/postgres/templates/init-script.yaml
11+
args: [--unsafe]
12+
- repo: https://github.com/igorshubovych/markdownlint-cli
13+
rev: v0.41.0
14+
hooks:
15+
- id: markdownlint
16+
args: [--fix, --disable, MD013, MD041, --]

‎hack/pre-checks.sh‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
YQ_VERSION="v4.35.1"
4+
RED='\033[31m'
5+
RESET='\033[0m'
6+
7+
check-yq-version() {
8+
current_version=$(yq -V | grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+')
9+
if [ -z "$current_version" ]; then
10+
echo "yq is not installed or version cannot be determined."
11+
exit 1
12+
fi
13+
echo "Current yq version: $current_version"
14+
15+
if [ "$(printf '%s\n' "$YQ_VERSION" "$current_version" | sort -V | head -n1)" = "$YQ_VERSION" ]; then
16+
echo "Greater than or equal to $YQ_VERSION"
17+
else
18+
echo -e "${RED}ERROR: yq version less than $YQ_VERSION${RESET}"
19+
exit 1
20+
fi
21+
}
22+
23+
check-yq-version

‎packages/apps/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### How to test packages local
2+
3+
```bash
4+
cd packages/core/installer
5+
make image-cozystack REGISTRY=YOUR_CUSTOM_REGISTRY
6+
make apply
7+
kubectl delete pod dashboard-redis-master-0 -n cozy-dashboard
8+
kubectl delete po -l app=source-controller -n cozy-fluxcd
9+
```

‎packages/apps/postgres/Chart.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 0.7.0
19+
version: 0.7.1
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to

‎packages/apps/postgres/README.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ PostgreSQL is currently the leading choice among relational databases, known for
66

77
This managed service is controlled by the CloudNativePG operator, ensuring efficient management and seamless operation.
88

9-
- Docs: https://cloudnative-pg.io/docs/
10-
- Github: https://github.com/cloudnative-pg/cloudnative-pg
9+
- Docs: <https://cloudnative-pg.io/docs/>
10+
- Github: <https://github.com/cloudnative-pg/cloudnative-pg>
1111

1212
## HowTos
1313

1414
### How to switch master/slave replica
1515

1616
See:
17-
- https://cloudnative-pg.io/documentation/1.15/rolling_update/#manual-updates-supervised
1817

19-
### How to restore backup:
18+
- <https://cloudnative-pg.io/documentation/1.15/rolling_update/#manual-updates-supervised>
19+
20+
### How to restore backup
2021

2122
find snapshot:
22-
```
23+
24+
```bash
2325
restic -r s3:s3.example.org/postgres-backups/database_name snapshots
2426
```
2527

2628
restore:
27-
```
29+
30+
```bash
2831
restic -r s3:s3.example.org/postgres-backups/database_name restore latest --target /tmp/
2932
```
3033

3134
more details:
32-
- https://itnext.io/restic-effective-backup-from-stdin-4bc1e8f083c1
35+
36+
- <https://itnext.io/restic-effective-backup-from-stdin-4bc1e8f083c1>
3337

3438
## Parameters
3539

@@ -64,5 +68,3 @@ more details:
6468
| `backup.s3AccessKey` | The access key for S3, used for authentication | `oobaiRus9pah8PhohL1ThaeTa4UVa7gu` |
6569
| `backup.s3SecretKey` | The secret key for S3, used for authentication | `ju3eum4dekeich9ahM1te8waeGai0oog` |
6670
| `backup.resticPassword` | The password for Restic backup encryption | `ChaXoveekoh6eigh4siesheeda2quai0` |
67-
68-

‎packages/apps/postgres/templates/init-script.yaml‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ stringData:
3434
init.sh: |
3535
#!/bin/bash
3636
set -e
37+
38+
until pg_isready ; do sleep 5; done
39+
3740
echo "== create users"
3841
{{- if .Values.users }}
3942
psql -v ON_ERROR_STOP=1 <<\EOT
@@ -60,7 +63,7 @@ stringData:
6063
DROP USER $user;
6164
EOT
6265
done
63-
66+
6467
echo "== create databases and roles"
6568
{{- if .Values.databases }}
6669
psql -v ON_ERROR_STOP=1 --echo-all <<\EOT
@@ -92,7 +95,7 @@ stringData:
9295
FOR schema_record IN SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('pg_catalog', 'information_schema') LOOP
9396
-- Changing Schema Ownership
9497
EXECUTE format('ALTER SCHEMA %I OWNER TO %I', schema_record.schema_name, '{{ $database }}_admin');
95-
98+
9699
-- Add rights for the admin role
97100
EXECUTE format('GRANT ALL ON SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_admin');
98101
EXECUTE format('GRANT ALL ON ALL TABLES IN SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_admin');
@@ -101,7 +104,7 @@ stringData:
101104
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON TABLES TO %I', schema_record.schema_name, '{{ $database }}_admin');
102105
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON SEQUENCES TO %I', schema_record.schema_name, '{{ $database }}_admin');
103106
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON FUNCTIONS TO %I', schema_record.schema_name, '{{ $database }}_admin');
104-
107+
105108
-- Add rights for the readonly role
106109
EXECUTE format('GRANT USAGE ON SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_readonly');
107110
EXECUTE format('GRANT SELECT ON ALL TABLES IN SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_readonly');
@@ -119,9 +122,9 @@ stringData:
119122
CREATE OR REPLACE FUNCTION auto_grant_schema_privileges()
120123
RETURNS event_trigger LANGUAGE plpgsql AS $$
121124
DECLARE
122-
obj record;
125+
obj record;
123126
BEGIN
124-
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag = 'CREATE SCHEMA' LOOP
127+
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag = 'CREATE SCHEMA' LOOP
125128
EXECUTE format('ALTER SCHEMA %I OWNER TO %I', obj.object_identity, '{{ $database }}_admin');
126129
EXECUTE format('GRANT ALL ON SCHEMA %I TO %I', obj.object_identity, '{{ $database }}_admin');
127130
EXECUTE format('GRANT USAGE ON SCHEMA %I TO %I', obj.object_identity, '{{ $database }}_readonly');
@@ -146,7 +149,7 @@ stringData:
146149
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT SELECT ON TABLES TO %I', obj.object_identity, '{{ $database }}_readonly');
147150
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT USAGE ON SEQUENCES TO %I', obj.object_identity, '{{ $database }}_readonly');
148151
EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT EXECUTE ON FUNCTIONS TO %I', obj.object_identity, '{{ $database }}_readonly');
149-
END LOOP;
152+
END LOOP;
150153
END;
151154
$$;
152155

‎packages/apps/versions_map‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ postgres 0.4.1 5ca8823
5252
postgres 0.5.0 c07c4bbd
5353
postgres 0.6.0 2a4768a
5454
postgres 0.6.2 54fd61c
55-
postgres 0.7.0 HEAD
55+
postgres 0.7.0 dc9d8bb
56+
postgres 0.7.1 HEAD
5657
rabbitmq 0.1.0 f642698
5758
rabbitmq 0.2.0 5ca8823
5859
rabbitmq 0.3.0 9e33dc0

0 commit comments

Comments
 (0)