mirror of
https://github.com/outbackdingo/cozystack.git
synced 2026-01-27 18:18:41 +00:00
add precommit and fix postgres job (#418)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a pre-commit workflow to automate checks before code merges. - Added a section in the README for testing packages locally. - **Improvements** - Enhanced PostgreSQL initialization script for better user and role management. - Updated documentation for Managed PostgreSQL Service with improved formatting and additional backup parameters. - Integrated pre-commit hooks for maintaining code quality in YAML and Markdown files. - Added a new target in the installer Makefile to run pre-checks before building images. - **Bug Fixes** - Adjusted formatting in various README files to ensure consistent presentation. - **Chores** - Updated image reference to use the latest version in configuration files. - Updated versioning for various packages in the versions map. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
35
.github/workflows/pre-commit.yml
vendored
Normal file
35
.github/workflows/pre-commit.yml
vendored
Normal file
@@ -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
|
||||
16
.pre-commit-config.yaml
Normal file
16
.pre-commit-config.yaml
Normal file
@@ -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, --]
|
||||
23
hack/pre-checks.sh
Executable file
23
hack/pre-checks.sh
Executable file
@@ -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
|
||||
9
packages/apps/README.md
Normal file
9
packages/apps/README.md
Normal file
@@ -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
|
||||
```
|
||||
@@ -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
|
||||
|
||||
@@ -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: <https://cloudnative-pg.io/docs/>
|
||||
- Github: <https://github.com/cloudnative-pg/cloudnative-pg>
|
||||
|
||||
## HowTos
|
||||
|
||||
### How to switch master/slave replica
|
||||
|
||||
See:
|
||||
- https://cloudnative-pg.io/documentation/1.15/rolling_update/#manual-updates-supervised
|
||||
|
||||
### How to restore backup:
|
||||
- <https://cloudnative-pg.io/documentation/1.15/rolling_update/#manual-updates-supervised>
|
||||
|
||||
### 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
|
||||
|
||||
- <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` |
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,6 +5,9 @@ TALOS_VERSION=$(shell awk '/^version:/ {print $$2}' images/talos/profiles/instal
|
||||
|
||||
include ../../../scripts/common-envs.mk
|
||||
|
||||
pre-checks:
|
||||
../../../hack/pre-checks.sh
|
||||
|
||||
show:
|
||||
helm template -n $(NAMESPACE) $(NAME) .
|
||||
|
||||
@@ -17,7 +20,7 @@ diff:
|
||||
update:
|
||||
hack/gen-profiles.sh
|
||||
|
||||
image: image-cozystack image-talos image-matchbox
|
||||
image: pre-checks image-cozystack image-talos image-matchbox
|
||||
|
||||
image-cozystack:
|
||||
make -C ../../.. repos
|
||||
|
||||
Reference in New Issue
Block a user