diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..ddfc2de88 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,35 @@ +name: Pre-Commit Checks + +on: [push, pull_request] + +jobs: + pre-commit: + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit hooks + run: | + git fetch origin main || git fetch origin master + base_commit=$(git rev-parse --verify origin/main || git rev-parse --verify origin/master || echo "") + + if [ -z "$base_commit" ]; then + files=$(git ls-files '*.yaml' '*.md') + else + files=$(git diff --name-only "$base_commit" -- '*.yaml' '*.md') + fi + + if [ -n "$files" ]; then + echo "$files" | xargs pre-commit run --files + else + echo "No YAML or Markdown files to lint" + fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..c669497fb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + args: [--fix=lf] + - id: check-yaml + exclude: packages/apps/postgres/templates/init-script.yaml + args: [--unsafe] +- repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.41.0 + hooks: + - id: markdownlint + args: [--fix, --disable, MD013, MD041, --] diff --git a/hack/pre-checks.sh b/hack/pre-checks.sh new file mode 100755 index 000000000..be0e2a675 --- /dev/null +++ b/hack/pre-checks.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +YQ_VERSION="v4.35.1" +RED='\033[31m' +RESET='\033[0m' + +check-yq-version() { + current_version=$(yq -V | grep -oP 'v[0-9]+\.[0-9]+\.[0-9]+') + if [ -z "$current_version" ]; then + echo "yq is not installed or version cannot be determined." + exit 1 + fi + echo "Current yq version: $current_version" + + if [ "$(printf '%s\n' "$YQ_VERSION" "$current_version" | sort -V | head -n1)" = "$YQ_VERSION" ]; then + echo "Greater than or equal to $YQ_VERSION" + else + echo -e "${RED}ERROR: yq version less than $YQ_VERSION${RESET}" + exit 1 + fi +} + +check-yq-version diff --git a/packages/apps/README.md b/packages/apps/README.md new file mode 100644 index 000000000..b2cb30cf4 --- /dev/null +++ b/packages/apps/README.md @@ -0,0 +1,9 @@ +### How to test packages local + +```bash +cd packages/core/installer +make image-cozystack REGISTRY=YOUR_CUSTOM_REGISTRY +make apply +kubectl delete pod dashboard-redis-master-0 -n cozy-dashboard +kubectl delete po -l app=source-controller -n cozy-fluxcd +``` diff --git a/packages/apps/postgres/Chart.yaml b/packages/apps/postgres/Chart.yaml index 029983438..40483895f 100644 --- a/packages/apps/postgres/Chart.yaml +++ b/packages/apps/postgres/Chart.yaml @@ -16,7 +16,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.7.0 +version: 0.7.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/packages/apps/postgres/README.md b/packages/apps/postgres/README.md index bf053ed4f..c0d2dfd71 100644 --- a/packages/apps/postgres/README.md +++ b/packages/apps/postgres/README.md @@ -6,30 +6,34 @@ PostgreSQL is currently the leading choice among relational databases, known for This managed service is controlled by the CloudNativePG operator, ensuring efficient management and seamless operation. -- Docs: https://cloudnative-pg.io/docs/ -- Github: https://github.com/cloudnative-pg/cloudnative-pg +- Docs: +- Github: ## HowTos ### How to switch master/slave replica See: -- https://cloudnative-pg.io/documentation/1.15/rolling_update/#manual-updates-supervised -### How to restore backup: +- + +### How to restore backup find snapshot: -``` + +```bash restic -r s3:s3.example.org/postgres-backups/database_name snapshots ``` restore: -``` + +```bash restic -r s3:s3.example.org/postgres-backups/database_name restore latest --target /tmp/ ``` more details: -- https://itnext.io/restic-effective-backup-from-stdin-4bc1e8f083c1 + +- ## Parameters @@ -64,5 +68,3 @@ more details: | `backup.s3AccessKey` | The access key for S3, used for authentication | `oobaiRus9pah8PhohL1ThaeTa4UVa7gu` | | `backup.s3SecretKey` | The secret key for S3, used for authentication | `ju3eum4dekeich9ahM1te8waeGai0oog` | | `backup.resticPassword` | The password for Restic backup encryption | `ChaXoveekoh6eigh4siesheeda2quai0` | - - diff --git a/packages/apps/postgres/templates/init-script.yaml b/packages/apps/postgres/templates/init-script.yaml index d02a1894f..69d91c25a 100644 --- a/packages/apps/postgres/templates/init-script.yaml +++ b/packages/apps/postgres/templates/init-script.yaml @@ -34,6 +34,9 @@ stringData: init.sh: | #!/bin/bash set -e + + until pg_isready ; do sleep 5; done + echo "== create users" {{- if .Values.users }} psql -v ON_ERROR_STOP=1 <<\EOT @@ -60,7 +63,7 @@ stringData: DROP USER $user; EOT done - + echo "== create databases and roles" {{- if .Values.databases }} psql -v ON_ERROR_STOP=1 --echo-all <<\EOT @@ -92,7 +95,7 @@ stringData: FOR schema_record IN SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('pg_catalog', 'information_schema') LOOP -- Changing Schema Ownership EXECUTE format('ALTER SCHEMA %I OWNER TO %I', schema_record.schema_name, '{{ $database }}_admin'); - + -- Add rights for the admin role EXECUTE format('GRANT ALL ON SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_admin'); EXECUTE format('GRANT ALL ON ALL TABLES IN SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_admin'); @@ -101,7 +104,7 @@ stringData: EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON TABLES TO %I', schema_record.schema_name, '{{ $database }}_admin'); EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON SEQUENCES TO %I', schema_record.schema_name, '{{ $database }}_admin'); EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT ALL ON FUNCTIONS TO %I', schema_record.schema_name, '{{ $database }}_admin'); - + -- Add rights for the readonly role EXECUTE format('GRANT USAGE ON SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_readonly'); EXECUTE format('GRANT SELECT ON ALL TABLES IN SCHEMA %I TO %I', schema_record.schema_name, '{{ $database }}_readonly'); @@ -119,9 +122,9 @@ stringData: CREATE OR REPLACE FUNCTION auto_grant_schema_privileges() RETURNS event_trigger LANGUAGE plpgsql AS $$ DECLARE - obj record; + obj record; BEGIN - FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag = 'CREATE SCHEMA' LOOP + FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag = 'CREATE SCHEMA' LOOP EXECUTE format('ALTER SCHEMA %I OWNER TO %I', obj.object_identity, '{{ $database }}_admin'); EXECUTE format('GRANT ALL ON SCHEMA %I TO %I', obj.object_identity, '{{ $database }}_admin'); EXECUTE format('GRANT USAGE ON SCHEMA %I TO %I', obj.object_identity, '{{ $database }}_readonly'); @@ -146,7 +149,7 @@ stringData: EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT SELECT ON TABLES TO %I', obj.object_identity, '{{ $database }}_readonly'); EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT USAGE ON SEQUENCES TO %I', obj.object_identity, '{{ $database }}_readonly'); EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA %I GRANT EXECUTE ON FUNCTIONS TO %I', obj.object_identity, '{{ $database }}_readonly'); - END LOOP; + END LOOP; END; $$; diff --git a/packages/apps/versions_map b/packages/apps/versions_map index 302bbcae5..05f8cb7f3 100644 --- a/packages/apps/versions_map +++ b/packages/apps/versions_map @@ -52,7 +52,8 @@ postgres 0.4.1 5ca8823 postgres 0.5.0 c07c4bbd postgres 0.6.0 2a4768a postgres 0.6.2 54fd61c -postgres 0.7.0 HEAD +postgres 0.7.0 dc9d8bb +postgres 0.7.1 HEAD rabbitmq 0.1.0 f642698 rabbitmq 0.2.0 5ca8823 rabbitmq 0.3.0 9e33dc0