Skip to content

Commit

Permalink
Add a CONTRIBUTING.md file and Makefile to guide new contributors (#305)
Browse files Browse the repository at this point in the history
* 🆕 chore(Makefile): add Makefile with global configuration and help message
This commit adds a Makefile to the project with global configuration and a help message. The Makefile includes a global configuration for the default goal, export all variables, silent mode, and bash shell. It also includes a help message with instructions on how to use the Makefile.

* 🆕 feat(Makefile): add help command
A new file `.config/make/help.mak` was added to the project, which contains a `help` target that prints a list of available make targets with their descriptions. The `Makefile` was updated to include the `help.mak` file. This makes it easier for developers to understand the available make targets and their purposes.

* 🔧 chore(Makefile): update python_launcher to version 3.10
🎉 feat(python.mak): add makefile for python virtual environment management
The python_launcher variable in the Makefile has been updated to version 3.10. This change is made to ensure that the correct version of Python is used for the virtual environment. The python.mak makefile has been added to manage the virtual environment for Python. It includes targets for creating, upgrading, and installing requirements for the virtual environment. Additionally, targets for linting and testing Python scripts have been added.

* 🆕 feat(makefile): add yaml makefile
The yaml makefile is added to the project, which includes targets for bootstrapping and running yamllint. The yaml-bootstrap target installs or upgrades linters, and the yamllint target runs yamllint on the project.

* 🎉 feat(molecule.mak): add molecule make targets
This commit adds a new file `.config/make/molecule.mak` which contains make targets for running molecule commands. These targets include `molecule-bootstrap`, `molecule-test`, `molecule-destroy`, `molecule-converge`, `molecule-reconverge`, `molecule-test-all`, `molecule-destroy-all`, `molecule-test-scenario`, `molecule-destroy-scenario`, `molecule-converge-scenario`, `molecule-dependency`, `molecule-verify`, and `molecule-lint`. These targets allow for easier management of molecule commands and scenarios.

* 🔥 chore(Makefile): add clean and reinitialization targets
The `clean` target removes all temporary files and directories created during the build process. The `reinitialization` target removes the virtual environment, vendor directory, and all makefiles, returning the collection to its initial state.

* 🔥 chore(.gitignore): add .venv to ignore list
The .venv directory is added to the ignore list to prevent it from being tracked by git. This directory is used by virtual environments and should not be included in the repository.

* 🔧 chore(Makefile): remove yaml.mak and molecule-bootstrap target
📦 chore(requirements): add ansible to requirements.txt and create requirements.dev.txt
The yaml.mak file was removed as it was no longer needed. The molecule-bootstrap target was also removed as it was not being used. The ansible package was added to requirements.txt as it was required for the project. A new requirements.dev.txt file was created to hold development dependencies such as ansible-lint, yamllint, molecule, molecule-plugins[docker], and docker.

* 🎉 feat(CONTRIBUTING.md): add CONTRIBUTING.md file
This commit adds a CONTRIBUTING.md file to the repository, which provides guidelines for contributing to the project. The guidelines include instructions for creating issues, forking the project, making changes, testing changes, and making pull requests. The guidelines also include a request for sponsorship.

* 📝 docs(CONTRIBUTING.md): fix typos and improve readability
This commit fixes several typos and improves the readability of the CONTRIBUTING.md file. Changes include fixing grammar and punctuation errors, improving sentence structure, and clarifying instructions. These changes will make it easier for contributors to understand how to contribute to the project and improve the overall quality of the file.

* 📝 docs(CONTRIBUTING.md): update link to pull request documentation
This commit updates the link to the pull request documentation to the official GitHub documentation. This will ensure that contributors are directed to the correct documentation and can create pull requests with ease.

* 🔀 merge(python): update python requirements files
✨ feat(python.mak): change python requirements file paths
🆕 chore(python): add requirements.dev.txt file
The python requirements file paths have been updated to match the new file locations. The requirements.txt file has been updated to include ansible>=2.7. A new requirements.dev.txt file has been added to include development dependencies such as ansible-lint, yamllint, molecule, molecule-plugins[docker], and docker.

* 🐛 fix(CONTRIBUTING.md): add sudo to apt update command
The sudo command was missing from the apt update command, which could cause issues with updating the package list.

* 📝 docs(CONTRIBUTING.md): add instructions for contributing with Gitpod
This commit adds a new section to the CONTRIBUTING.md file that explains how to contribute to the project using Gitpod, a cloud-based development environment platform. The section includes step-by-step instructions for creating a Gitpod workspace, making changes, committing them, and creating a pull request. This addition aims to make it easier for contributors to get started with the project without having to set up a local environment.

* 📝 docs(CONTRIBUTING.md): update sponsor links
The sponsor links have been updated to include both GitHub and Patreon options. This will make it easier for contributors to support the project in a way that is most convenient for them.

* 📝 docs(CONTRIBUTING.md): add instructions to test changes with Molecule
Added instructions to test changes with Molecule before committing. The instructions include how to test a specific distribution, set `distro`, optionally `tag`, and `namespace`. This ensures that changes are tested and working correctly before being pushed to the repository.

* 🎉 feat(docker.mak): add docker-build and docker-lint targets
🎉 feat(.gitpod.Dockerfile): add Dockerfile for Gitpod
🎉 feat(.gitpod.yml): use custom Dockerfile for Gitpod image
🎉 feat(Makefile): include docker.mak in Makefile
The Dockerfile and docker.mak files were added to the project to support building and linting Docker images. The .gitpod.yml file was updated to use the custom Dockerfile for the Gitpod image. The Makefile was updated to include the docker.mak file.

* 🐛 fix(.gitpod.yml): correct typo in bootstrap task name
The typo in the bootstrap task name has been corrected from 'boostrap' to 'bootstrap'. This ensures that the task runs correctly when executed.

* 📝 docs(CONTRIBUTING.md): update contributing guide
This commit updates the contributing guide to provide clearer instructions on how to contribute to the project. It also adds a section on how to use Gitpod for a cloud-based development environment. Additionally, it adds a reminder to consider sponsoring the maintainer via GitHub or Patreon.
  • Loading branch information
ThomasSanson authored Apr 25, 2023
1 parent c4bb248 commit e1c611f
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .config/make/docker.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## —— Docker —————————————————————————————————————————————————————————————————————————————————————
.PHONY: docker-build
docker-build: ## Run docker build image in local
docker build --tag postgresql_cluster:local --file .gitpod.Dockerfile .

.PHONY: docker-lint
docker-lint: ## Run hadolint command to lint Dokerfile
docker run --rm -i hadolint/hadolint < .gitpod.Dockerfile
5 changes: 5 additions & 0 deletions .config/make/help.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## —— Help ———————————————————————————————————————————————————————————————————————————————————————
.PHONY: help
help: ## Help command
echo -e "$$HEADER"
grep -E '(^[a-zA-Z0-9_-]+:.*?## .*$$)|(^## )' $(MAKEFILE_LIST) | sed 's/^[^:]*://g' | awk 'BEGIN {FS = ":.*?## | #"} ; {printf "${cyan}%-30s${reset} ${white}%s${reset} ${green}%s${reset}\n", $$1, $$2, $$3}' | sed -e 's/\[36m##/\n[32m##/'
61 changes: 61 additions & 0 deletions .config/make/molecule.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## —— Molecule ———————————————————————————————————————————————————————————————————————————————————
.PHONY: molecule-test
molecule-test: ## Run test sequence for default scenario
source .venv/bin/activate
molecule test

.PHONY: molecule-destroy
molecule-destroy: ## Run destroy sequence for default scenario
source .venv/bin/activate
molecule destroy

.PHONY: molecule-converge
molecule-converge: ## Run converge sequence for default scenario
source .venv/bin/activate
molecule converge

.PHONY: molecule-reconverge
molecule-reconverge: ## Run destroy and converge sequence for default scenario
source .venv/bin/activate
molecule destroy
molecule converge

.PHONY: molecule-test-all
molecule-test-all: ## Run test sequence for all scenarios
source .venv/bin/activate
molecule test --all

.PHONY: molecule-destroy-all
molecule-destroy-all: ## Run destroy sequence for all scenarios
source .venv/bin/activate
molecule destroy --all

.PHONY: molecule-test-scenario
molecule-test-scenario: ## Run molecule test with specific scenario (example: make molecule-test-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule test --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-destroy-scenario
molecule-destroy-scenario: ## Run molecule destroy with specific scenario (example: make molecule-destroy-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule destroy --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-converge-scenario
molecule-converge-scenario: ## Run molecule converge with specific scenario (example: make molecule-converge-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule converge --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-dependency
molecule-dependency: ## Run dependency sequence
source .venv/bin/activate
molecule dependency

.PHONY: molecule-verify
molecule-verify: ## Run verify sequence
source .venv/bin/activate
molecule verify

.PHONY: molecule-lint
molecule-lint: ## Run lint sequence
source .venv/bin/activate
molecule lint
75 changes: 75 additions & 0 deletions .config/make/python.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Python default launcher
python_launcher ?= python3.10
python_requirements_file ?= requirements.txt
python_requirements_dev_file ?= requirements.dev.txt

## —— Python —————————————————————————————————————————————————————————————————————————————————————
.PHONY: python-bootstrap
python-bootstrap: ## Bootstrap python
$(MAKE) python-venv-init
$(MAKE) python-venv-upgrade
$(MAKE) python-venv-requirements

.PHONY: python-bootstrap-dev
python-bootstrap-dev: ## Bootstrap python for dev env
$(MAKE) python-venv-requirements-dev
$(MAKE) python-venv-linters-install

# ===============================================================================================
# .venv
# ===============================================================================================
.PHONY: python-venv-init
python-venv-init: ## Create venv ".venv/" if not exist
if [ ! -d .venv ] ; then
$(python_launcher) -m venv .venv
fi

.PHONY: python-venv-upgrade
python-venv-upgrade: ## Upgrade venv with pip, setuptools and wheel
source .venv/bin/activate
pip install --upgrade pip setuptools wheel

.PHONY: python-venv-requirements
python-venv-requirements: ## Install or upgrade from $(python_requirements_file)
source .venv/bin/activate
pip install --upgrade --requirement $(python_requirements_file)

.PHONY: python-venv-requirements-dev
python-venv-requirements-dev: ## Install or upgrade from $(python_requirements_dev_file)
source .venv/bin/activate
pip install --upgrade --requirement $(python_requirements_dev_file)

.PHONY: python-venv-linters-install
python-venv-linters-install: ## Install or upgrade linters
source .venv/bin/activate
pip install --upgrade flake8

.PHONY: python-venv-purge
python-venv-purge: ## Remove venv ".venv/" folder
rm -rf .venv

# ===============================================================================================
# Utils
# ===============================================================================================
.PHONY: python-purge-cache
python-purge-cache: ## Purge cache to avoid used cached files
if [ -d .venv ] ; then
source .venv/bin/activate
pip cache purge
fi

.PHONY: python-version
python-version: ## Displays the python version used for the .venv
source .venv/bin/activate
$(python_launcher) --version

.PHONY: python-flake8
python-flake8: ## Run flake8 linter for python
source .venv/bin/activate
flake8 --config .config/.flake8

.PHONY: python-pytest
python-pytest: ## Run pytest to test python scripts
source .venv/bin/activate
cd scripts/
$(python_launcher) -m pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.idea
.venv
43 changes: 28 additions & 15 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ FROM ubuntu:jammy

USER root

# update system and install packages
RUN apt update && apt upgrade -y \
&& apt install -y ca-certificates gnupg lsb-release -yq git git-lfs sudo python3 python3-pip \
vim nano iproute2 wget curl htop

# install docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
# Update system and install packages, including Docker
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
lsb-release \
git \
git-lfs \
sudo \
make \
python3.10 \
python3.10-venv \
python3-pip \
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
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt update \
&& apt install -y docker-ce docker-ce-cli containerd.io

# install molecule and ansible
RUN pip3 install 'molecule[docker]<5.0.0' ansible ansible-lint yamllint

# clean
RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/*
&& apt-get update \
&& apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io \
# Clean
&& apt-get clean && rm -rf /var/lib/apt/lists/* tmp/*

# Create the gitpod user. UID must be 33333.
RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash -p gitpod gitpod
Expand Down
7 changes: 5 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
image: vitabaks/ansible-molecule-ubuntu:22.04
...
image:
file: .gitpod.Dockerfile

tasks:
- init: make bootstrap
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Contributing Guide

Help improve this project by:

- [Creating an issue](https://help.github.com/articles/creating-an-issue/) (Check for [known issues](https://github.com/search?q=user%3Avitabaks+is%3Aissue+state%3Aopen) first)
- [Submitting a pull request](https://docs.github.com/fr/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) to fix a problem or add a feature

Your contributions are appreciated and will be taken seriously.

## How to Contribute

### 1. Create an issue

Report problems or suggest improvements by [creating an issue](https://github.com/vitabaks/postgresql_cluster/issues).

### 2. Fork the project

[Fork the repository](https://github.com/vitabaks/postgresql_cluster) to your GitHub account.

### 3. Make changes

Clone your fork locally and make the necessary changes:

```
git clone [email protected]:YOURNAMESPACE/postgresql_cluster.git
```

### 4. Test your changes (Optional)

#### 4.1 Gitpod

Use Gitpod for a cloud-based development environment:

1. Sign up for Gitpod: https://gitpod.io
2. Fork the `postgresql_cluster` repository
3. Open your fork in Gitpod: `https://gitpod.io/#https://github.com/username/postgresql_cluster`
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

Keep your Gitpod workspace synced with the main repository.

#### 4.2 Desktop

Install [make](https://www.gnu.org/software/make/), [Python3.10](https://www.python.org/), [venv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/), and [docker](https://docs.docker.com/engine/install/ubuntu/).

Run `make` for Makefile help. Initialize virtualenv and install dependencies with `make reinitialization` or `make bootstrap`. Test your changes with `make molecule-test` or `make molecule-converge`.

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

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

### 5. Submit a pull request

[Create a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) and [refer to the issue number](https://help.github.com/en/github/writing-on-github/autolinked-references-and-urls) using #123, where 123 is the issue number.

### 6. Wait

Your pull request will be reviewed, and you'll receive feedback. Thanks for contributing!

Consider sponsoring the maintainer via [GitHub](https://github.com/sponsors/vitabaks) or [Patreon](https://patreon.com/vitabaks).
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.PHONY: all test SHELL

# Makefile global config
.DEFAULT_GOAL:=help
.EXPORT_ALL_VARIABLES:
.ONESHELL:
.SILENT:
MAKEFLAGS += "-j$(NUM_CORES) -l$(NUM_CORES)"
MAKEFLAGS += --silent
SHELL:=/bin/bash

# Makefile colors config
bold=$(shell tput bold)
normal=$(shell tput sgr0)
errorTitle=$(shell tput setab 1 && tput bold && echo '\n')
recommendation=$(shell tput setab 4)
underline=$(shell tput smul)
reset=$(shell tput -Txterm sgr0)
black=$(shell tput setaf 0)
red=$(shell tput setaf 1)
green=$(shell tput setaf 2)
yellow=$(shell tput setaf 3)
blue=$(shell tput setaf 4)
magenta=$(shell tput setaf 5)
cyan=$(shell tput setaf 6)
white=$(shell tput setaf 7)

define HEADER
How to use me:
make && make bootstrap
make ${cyan}<target>${reset}

endef
export HEADER

python_launcher := python3.10

-include .config/make/help.mak
-include .config/make/python.mak
-include .config/make/docker.mak
-include .config/make/molecule.mak

## —— Bootstrap collection ———————————————————————————————————————————————————————————————————————
.PHONY: bootstrap
bootstrap: ## Bootstrap Ansible collection
$(MAKE) python-bootstrap
$(MAKE) python-bootstrap-dev

## —— Virtualenv ————————————————————————————————————————————————————————————————————————————————
.PHONY: reinitialization
reinitialization: ## Return to an initial state of Bootstrap Ansible collection
rm -rf .venv/
rm -rf vendor/
rm -f *.mak
$(MAKE) bootstrap

.PHONY: clean
clean: ## Clean collection
rm -rf .venv/
rm -rf .pytest_cache/
rm -rf scripts/.pytest_cache/
rm -rf scripts/tests/__pycache__/
rm -rf scripts/modules/__pycache__/
rm -rf scripts/modules/services/__pycache__/
rm -rf scripts/modules/utils/__pycache__/
5 changes: 5 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ansible-lint==6.15.0
yamllint==1.31.0
molecule==5.0.0
molecule-plugins[docker]==23.4.0
docker==6.0.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ansible>=2.7

0 comments on commit e1c611f

Please sign in to comment.