Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate code improvements and add linters #307

Merged
merged 10 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ skip_list:
- role-name
- ignore-errors
- package-latest
- risky-file-permissions # TODO
- no-log-password # We do not display passwords
- fqcn-builtins # Use FQCN for builtin actions
- risky-file-permissions # TODO
- no-log-password # We do not display passwords
- fqcn-builtins # Use FQCN for builtin actions
- no-changed-when
- name[missing] # All tasks should be named.
- name[casing] # TODO: All names should start with an uppercase letter.
- name[template] # Rule for checking task and play names
- jinja[spacing] # TODO
- jinja[invalid] # TODO
- name[missing] # All tasks should be named.
- name[casing] # TODO: All names should start with an uppercase letter.
- name[template] # Rule for checking task and play names
- jinja[spacing] # TODO
- jinja[invalid] # TODO
- no-handler
- schema[tasks]
- template-instead-of-copy # Templated files should use template instead of copy
- experimental # all rules tagged as experimental
- command-instead-of-shell # Using command rather than shell where necessary
- command-instead-of-module # Using command rather than module where necessary
- template-instead-of-copy # Templated files should use template instead of copy
- experimental # all rules tagged as experimental
- command-instead-of-shell # Using command rather than shell where necessary
- command-instead-of-module # Using command rather than module where necessary
- fqcn[action]
- no-relative-paths
- key-order[task] # TODO
- key-order[task] # TODO
- no-free-form

exclude_paths:
- roles/consul/ # TODO - https://github.com/ansible-community/ansible-consul/pull/520

- .venv
# https://ansible-lint.readthedocs.io/configuring/
# https://ansible-lint.readthedocs.io/rules/
9 changes: 9 additions & 0 deletions .config/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist,
.venv
32 changes: 32 additions & 0 deletions .config/make/linters.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## —— Linter —————————————————————————————————————————————————————————————————————————————————————

# Activate virtual environment
ACTIVATE_VENV = source .venv/bin/activate

# Configuration files
YAMLLINT_CONFIG = .yamllint
FLAKE8_CONFIG = .config/.flake8

.PHONY: linter-yamllint
linter-yamllint: ## Lint YAML files using yamllint
echo "yamllint #############################################################"
$(ACTIVATE_VENV) && \
yamllint --strict -c $(YAMLLINT_CONFIG) .

.PHONY: linter-ansible-lint
linter-ansible-lint: ## Lint Ansible files using ansible-lint
echo "ansible-lint #########################################################"
$(ACTIVATE_VENV) && \
ansible-lint --force-color --offline --parseable

.PHONY: linter-flake8
linter-flake8: ## Lint Python files using flake8
echo "flake8 ###############################################################"
$(ACTIVATE_VENV) && \
flake8 --config $(FLAKE8_CONFIG)

.PHONY: lint
lint: ## Run all linters
$(MAKE) linter-yamllint
$(MAKE) linter-ansible-lint
$(MAKE) linter-flake8
17 changes: 9 additions & 8 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ USER root
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
bash-completion \
ca-certificates \
gnupg \
lsb-release \
curl \
git \
git-lfs \
sudo \
gnupg \
htop \
iproute2 \
lsb-release \
make \
nano \
python3-pip \
python3.10 \
python3.10-venv \
python3-pip \
sudo \
vim \
nano \
iproute2 \
wget \
curl \
htop \
&& python3 -m pip install --no-cache-dir --upgrade pip \
&& python3 -m pip install --no-cache-dir virtualenv \
# Install Docker
Expand Down
3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ extends: default
rules:
line-length: disable
comments-indentation: disable
comments:
min-spaces-from-content: 1
braces:
min-spaces-inside: 1
max-spaces-inside: 1

ignore: |
.github/
.venv
13 changes: 8 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Report problems or suggest improvements by [creating an issue](https://github.co

Clone your fork locally and make the necessary changes:

```
```bash
git clone git@github.com:YOURNAMESPACE/postgresql_cluster.git
```

Expand All @@ -37,9 +37,10 @@ Use Gitpod for a cloud-based development environment:
4. Create a new branch: `git checkout -b my-feature-branch`
5. Make your changes and commit: `git add .` and `git commit -m "Description of changes"`
6. Test with Molecule: `make molecule-test` or `make molecule-converge`
7. Push your changes: `git push origin my-feature-branch`
8. Create a pull request on GitHub
9. Wait for a review
7. Test with linters(otpional): `make lint`
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
8. Push your changes: `git push origin my-feature-branch`
9. Create a pull request on GitHub
10. Wait for a review

Keep your Gitpod workspace synced with the main repository.

Expand All @@ -51,7 +52,9 @@ Run `make` for Makefile help. Initialize virtualenv and install dependencies wit

To test a specific distribution, set `distro`, `tag`, and `namespace`:

```
You can lint with `make lint`

```bash
IMAGE_NAMESPACE=geerlingguy IMAGE_DISTRO=debian10 make molecule-converge
```

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ python_launcher := python3.10
-include .config/make/python.mak
-include .config/make/docker.mak
-include .config/make/molecule.mak
-include .config/make/linters.mak

## —— Bootstrap collection ———————————————————————————————————————————————————————————————————————
.PHONY: bootstrap
Expand Down
33 changes: 15 additions & 18 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

dependency:
name: galaxy
enabled: false
Expand All @@ -10,21 +9,21 @@ platforms:
hostname: pgnode01
image: "${IMAGE_NAMESPACE:-geerlingguy}/docker-${IMAGE_DISTRO:-ubuntu2204}-ansible:${IMAGE_TAG:-latest}"
# docker_networks: # TODO github.com/ansible-community/molecule/pull/2696
# - name: test_docker_network
# ipam_config:
# - subnet: 10.172.0.0/24
# gateway: 10.172.0.1
# - name: test_docker_network
# ipam_config:
# - subnet: 10.172.0.0/24
# gateway: 10.172.0.1
networks:
- name: test_docker_network
ipv4_address: 10.172.0.20
exposed_ports:
- 2379/tcp # if dcs_type: "etcd"
- 2380/tcp # if dcs_type: "etcd"
- 8300/tcp # if dcs_type: "consul"
- 8301/tcp # if dcs_type: "consul"
- 8302/tcp # if dcs_type: "consul"
- 8500/tcp # if dcs_type: "consul"
- 8600/tcp # if dcs_type: "consul"
- 2379/tcp # if dcs_type: "etcd"
- 2380/tcp # if dcs_type: "etcd"
- 8300/tcp # if dcs_type: "consul"
- 8301/tcp # if dcs_type: "consul"
- 8302/tcp # if dcs_type: "consul"
- 8500/tcp # if dcs_type: "consul"
- 8600/tcp # if dcs_type: "consul"
- 8008/tcp
- 5432/tcp
- 6432/tcp
Expand All @@ -35,8 +34,8 @@ platforms:
privileged: true
pre_build_image: true
groups:
- etcd_cluster # if dcs_type: "etcd"
- consul_instances # if dcs_type: "consul"
- etcd_cluster # if dcs_type: "etcd"
- consul_instances # if dcs_type: "consul"
- master
- postgres_cluster
- balancers
Expand Down Expand Up @@ -133,13 +132,11 @@ scenario:
- prepare
- create
- converge
# - idempotence # >> role:patroni,task:"data directory check result"
# - idempotence # >> role:patroni,task:"data directory check result"
- verify
- cleanup
- destroy

verifier:
name: ansible
enabled: false # TODO

...
enabled: false # TODO
10 changes: 4 additions & 6 deletions molecule/postgrespro/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
tasks:
- name: Set variables for molecule
set_fact:
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
sysctl_set: false # Added to prevent test failures in CI.
firewall_enable_ipv6: false # Added to prevent test failures in CI.
swap_file_create: false # Added to prevent test failures in CI.
sysctl_set: false # Added to prevent test failures in CI.
nameservers: ["8.8.8.8", "9.9.9.9"]
with_haproxy_load_balancing: true
cacheable: true
Expand All @@ -26,8 +26,6 @@
- ansible_distribution_major_version is version('8', '>=')

- name: Include postgrespro vars
include_vars: ./postgrespro_vars.yml
ansible.builtin.include_vars: vars/postgrespro_vars.yml
vitabaks marked this conversation as resolved.
Show resolved Hide resolved

- import_playbook: ../../deploy_pgcluster.yml

...
33 changes: 15 additions & 18 deletions molecule/postgrespro/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

dependency:
name: galaxy
enabled: false
Expand All @@ -10,21 +9,21 @@ platforms:
hostname: pgnode01
image: "${IMAGE_NAMESPACE:-geerlingguy}/docker-${IMAGE_DISTRO:-ubuntu2204}-ansible:${IMAGE_TAG:-latest}"
# docker_networks: # TODO github.com/ansible-community/molecule/pull/2696
# - name: test_docker_network
# ipam_config:
# - subnet: 10.172.0.0/24
# gateway: 10.172.0.1
# - name: test_docker_network
# ipam_config:
# - subnet: 10.172.0.0/24
# gateway: 10.172.0.1
networks:
- name: test_docker_network
ipv4_address: 10.172.1.20
exposed_ports:
- 2379/tcp # if dcs_type: "etcd"
- 2380/tcp # if dcs_type: "etcd"
- 8300/tcp # if dcs_type: "consul"
- 8301/tcp # if dcs_type: "consul"
- 8302/tcp # if dcs_type: "consul"
- 8500/tcp # if dcs_type: "consul"
- 8600/tcp # if dcs_type: "consul"
- 2379/tcp # if dcs_type: "etcd"
- 2380/tcp # if dcs_type: "etcd"
- 8300/tcp # if dcs_type: "consul"
- 8301/tcp # if dcs_type: "consul"
- 8302/tcp # if dcs_type: "consul"
- 8500/tcp # if dcs_type: "consul"
- 8600/tcp # if dcs_type: "consul"
- 8008/tcp
- 5432/tcp
- 6432/tcp
Expand All @@ -35,8 +34,8 @@ platforms:
privileged: true
pre_build_image: true
groups:
- etcd_cluster # if dcs_type: "etcd"
- consul_instances # if dcs_type: "consul"
- etcd_cluster # if dcs_type: "etcd"
- consul_instances # if dcs_type: "consul"
- master
- postgres_cluster
- balancers
Expand Down Expand Up @@ -133,13 +132,11 @@ scenario:
- prepare
- create
- converge
# - idempotence # >> role:patroni,task:"data directory check result"
# - idempotence # >> role:patroni,task:"data directory check result"
- verify
- cleanup
- destroy

verifier:
name: ansible
enabled: false # TODO

...
enabled: false # TODO