Skip to content

Commit

Permalink
Merge branch 'main' into erral-allow-using-plonecli
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTango authored Nov 5, 2024
2 parents 0388397 + e664f3e commit 949dbb0
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 67 deletions.
18 changes: 13 additions & 5 deletions backend_addon/hooks/pre_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]


def sanity_check() -> bool:
def sanity_check() -> data.SanityCheckResults:
"""Run sanity checks on the system."""
checks = [
data.SanityCheck(
Expand All @@ -31,8 +31,7 @@ def sanity_check() -> bool:
),
data.SanityCheck("git", commands.check_command_is_available, ["git"], "error"),
]
result = sanity.run_sanity_checks(checks)
return result.status
return sanity.run_sanity_checks(checks)


def main():
Expand All @@ -41,8 +40,17 @@ def main():
print("This template should be run with cookieplone")
sys.exit(1)

console.panel(title="Plone Addon", msg="Creating a new Plone Addon")
if not sanity_check():
msg = """
Creating a new Plone Addon
Sanity check results:
"""
check_results = sanity_check()
for check in check_results.checks:
label = "green" if check.status else "red"
msg = f"{msg}\n - {check.name}: [{label}]{check.message}[/{label}]"
console.panel(title="Plone Addon", msg=f"{msg}\n")
if not check_results.status:
sys.exit(1)


Expand Down
6 changes: 2 additions & 4 deletions frontend_addon/{{ cookiecutter.__folder_name }}/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const fs = require('fs');
const projectRootPath = __dirname;
const AddonConfigurationRegistry = require('@plone/registry/src/addon-registry');
const { AddonRegistry } = require('@plone/registry/addon-registry');

let coreLocation;
if (fs.existsSync(`${projectRootPath}/core`))
coreLocation = `${projectRootPath}/core`;
else if (fs.existsSync(`${projectRootPath}/../../core`))
coreLocation = `${projectRootPath}/../../core`;

const registry = new AddonConfigurationRegistry(
`${coreLocation}/packages/volto`,
);
const { registry } = AddonRegistry.init(`${coreLocation}/packages/volto`);

// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
const addonAliases = Object.keys(registry.packages).map((o) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
run: make install

- name: Unit tests
run: make test-ci
run: make ci-test
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ module.exports = {
[],
defaultRazzleOptions,
);
const AddonConfigurationRegistry = require('@plone/registry/src/addon-registry');
const { AddonRegistry } = require('@plone/registry/addon-registry');

const registry = new AddonConfigurationRegistry(projectRootPath);
const { registry } = AddonRegistry.init(projectRootPath);

config = lessPlugin({ registry }).modifyWebpackConfig({
env: { target: 'web', dev: 'dev' },
Expand Down
6 changes: 3 additions & 3 deletions frontend_addon/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ start: ## Starts Volto, allowing reloading of the add-on during development
build: ## Build a production bundle for distribution of the project with the add-on
pnpm build

core/packages/registry/dist: core/packages/registry/src
core/packages/registry/dist: $(shell find core/packages/registry/src -type f)
pnpm --filter @plone/registry build

core/packages/components/dist: core/packages/components/src
core/packages/components/dist: $(shell find core/packages/components/src -type f)
pnpm --filter @plone/components build

.PHONY: build-deps
Expand Down Expand Up @@ -91,7 +91,7 @@ release-dry-run: ## Dry-run the release of the add-on on npmjs.org
test: ## Run unit tests
pnpm test

.PHONY: test-ci
.PHONY: ci-test
ci-test: ## Run unit tests in CI
# Unit Tests need the i18n to be built
VOLTOCONFIG=$(pwd)/volto.config.js pnpm --filter @plone/volto i18n
Expand Down
6 changes: 6 additions & 0 deletions frontend_addon/{{ cookiecutter.__folder_name }}/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@
"devDependencies": {
"mrs-developer": "{{ cookiecutter.__version_mrs_developer }}"
},
"pnpm": {
"overrides": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"react-refresh": "^0.14.2"
}
},
"packageManager": "pnpm@{{ cookiecutter.__version_pnpm }}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"plugins": {
"../../core/packages/scripts/prepublish.js": {}
},
"hooks": {
"after:bump": [
"pipx run towncrier build --draft --yes --version ${version} > .changelog.draft",
Expand All @@ -9,6 +12,9 @@
],
"after:release": "rm .changelog.draft README.md"
},
"npm": {
"publish": false
},
"git": {
"changelog": "pipx run towncrier build --draft --yes --version 0.0.0",
"requireUpstream": false,
Expand Down
13 changes: 7 additions & 6 deletions project/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"__python_package_name_upper": "{{ cookiecutter.python_package_name | pascal_case }}",
"__node_version": "{{ cookiecutter.volto_version | node_version_for_volto }}",
"__version_plone_volto": "{{ cookiecutter.volto_version }}",
"__version_pnpm": "9.1.1",
"__container_registry_prefix": "{{ cookiecutter.container_registry | image_prefix }}",
"__container_image_prefix": "{{ cookiecutter.__container_registry_prefix }}{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}",
"__profile_version": "{% now 'utc', '%Y%m%d001' %}",
Expand All @@ -57,12 +58,13 @@
"__devops_host": "{{ cookiecutter.hostname | extract_host }}",
"__devops_compose_name": "{{ cookiecutter.project_slug | replace('.','-') | replace('_','-') }}",
"__devops_stack_name": "{{ cookiecutter.hostname | replace('.','-') | replace('_','-') }}",
"__devops_swarm_public_network": "nw-internal",
"__devops_traefik_version": "v2.10",
"__devops_swarm_public_network": "nw-public",
"__devops_swarm_stack_network": "nw-internal",
"__devops_traefik_version": "v2.11",
"__devops_traefik_local_include_ui": "yes",
"__devops_traefik_stack_include_ui": "no",
"__devops_traefik_docker_network": "{{ cookiecutter.__devops_stack_name }}_{{ cookiecutter.__devops_swarm_public_network }}",
"__devops_varnish_version": "7.4",
"__devops_traefik_docker_network": "{{ cookiecutter.__devops_stack_name }}_{{ cookiecutter.__devops_swarm_stack_network }}",
"__devops_varnish_version": "7.6",
"__devops_db_version": "14",
"__devops_db_password": "{{ random_ascii_string(12) }}",
"__backend_addon_format": "1",
Expand Down Expand Up @@ -117,8 +119,7 @@
"devops/playbooks",
"devops/requirements",
"devops/tasks",
"devops/inventory/group_vars/all/users.yml",
"devops/inventory/group_vars/all/projects.yml"
"devops/inventory/group_vars/all/users.yml"

],
"_extensions": [
Expand Down
18 changes: 13 additions & 5 deletions project/hooks/pre_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]


def sanity_check() -> bool:
def sanity_check() -> data.SanityCheckResults:
"""Run sanity checks on the system."""
checks = [
data.SanityCheck(
Expand All @@ -36,8 +36,7 @@ def sanity_check() -> bool:
"Docker", commands.check_docker_version, ["docker"], "warning"
),
]
result = sanity.run_sanity_checks(checks)
return result.status
return sanity.run_sanity_checks(checks)


def main():
Expand All @@ -46,8 +45,17 @@ def main():
print("This template should be run with cookieplone")
sys.exit(1)

console.panel(title="Plone Project", msg="Creating a new Plone Project")
if not sanity_check():
msg = """
Creating a new Plone Project
Sanity check results:
"""
check_results = sanity_check()
for check in check_results.checks:
label = "green" if check.status else "red"
msg = f"{msg}\n - {check.name}: [{label}]{check.message}[/{label}]"
console.panel(title="Plone Project", msg=f"{msg}\n")
if not check_results.status:
sys.exit(1)


Expand Down
7 changes: 7 additions & 0 deletions project/tests/test_project_devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ def test_project_devops_no_gha_deploy(
folder = cutter_result_devops_no_gha_deploy.project_path
path = folder / filepath
assert path.exists() is False


def test_ansible_inventory_projects_replacement(cutter_result):
"""Test GHA deploy files are not present."""
folder = cutter_result.project_path
path = folder / "devops/inventory/group_vars/all/projects.yml"
assert "{{ cookiecutter.hostname }}" not in path.read_text()
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
black:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@{{ cookiecutter.__gha_version_checkout }}
Expand All @@ -41,6 +43,8 @@ jobs:

flake8:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@{{ cookiecutter.__gha_version_checkout }}
Expand All @@ -53,6 +57,8 @@ jobs:

isort:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@{{ cookiecutter.__gha_version_checkout }}
Expand All @@ -65,6 +71,8 @@ jobs:

zpretty:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@{{ cookiecutter.__gha_version_checkout }}
Expand Down Expand Up @@ -105,6 +113,7 @@ jobs:
release:
runs-on: ubuntu-latest
needs:
- meta
- black
- flake8
- isort
Expand Down Expand Up @@ -162,3 +171,5 @@ jobs:
push: {{"${{ github.event_name != 'pull_request' }}"}}
tags: {{"${{ steps.meta.outputs.tags }}"}}
labels: {{"${{ steps.meta.outputs.labels }}"}}
build-args: |
PLONE_VERSION={{"${{ needs.meta.outputs.PLONE_VERSION }}"}}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: vars
run: |
echo 'BASE_TAG=sha-$(git rev-parse --short HEAD)' >> $GITHUB_OUTPUT
python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or "latest")' >> $GITHUB_OUTPUT
python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + (data["core"].get("tag") or "latest"))' >> $GITHUB_OUTPUT
- name: Test vars
run: |
echo 'BASE_TAG={{"${{ steps.vars.outputs.BASE_TAG }}"}}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"eslint.workingDirectories": ["./frontend"],
"flake8.cwd": "${workspaceFolder}/backend",
"flake8.args": ["--config=pyproject.toml"]
"flake8.args": ["--config=pyproject.toml"],
"black-formatter.cwd": "${workspaceFolder}/backend",
"isort.args": ["--settings-path=${workspaceFolder}/backend/pyproject.toml"]
}
29 changes: 15 additions & 14 deletions project/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ stack-create-site: ## Local Stack: Create a new site
@echo "Create a new site in the local Docker stack"
@docker compose -f docker-compose.yml exec backend ./docker-entrypoint.sh create-site

.PHONY: start-ps
.PHONY: stack-status
stack-status: ## Local Stack: Check Status
@echo "Check the status of the local Docker stack"
@docker compose -f docker-compose.yml ps
Expand All @@ -154,29 +154,29 @@ stack-rm: ## Local Stack: Remove Services and Volumes

## Acceptance
.PHONY: acceptance-backend-dev-start
acceptance-backend-dev-start: ## Build Acceptance Servers
@echo "Build acceptance backend"
acceptance-backend-dev-start:
@echo "Start acceptance backend"
$(MAKE) -C "./backend/" acceptance-backend-start

.PHONY: acceptance-frontend-dev-start
acceptance-frontend-dev-start: ## Build Acceptance Servers
@echo "Build acceptance backend"
acceptance-frontend-dev-start:
@echo "Start acceptance frontend"
$(MAKE) -C "./frontend/" acceptance-frontend-dev-start

.PHONY: acceptance-test
acceptance-test: ## Start Acceptance tests in interactive mode
@echo "Build acceptance backend"
acceptance-test:
@echo "Start acceptance tests in interactive mode"
$(MAKE) -C "./frontend/" acceptance-test

# Build Docker images
.PHONY: acceptance-frontend-image-build
acceptance-frontend-image-build: ## Build Acceptance frontend server image
@echo "Build acceptance frontend"
acceptance-frontend-image-build:
@echo "Build acceptance frontend image"
@docker build frontend -t {{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}-frontend:acceptance -f frontend/Dockerfile --build-arg VOLTO_VERSION=$(VOLTO_VERSION)

.PHONY: acceptance-backend-image-build
acceptance-backend-image-build: ## Build Acceptance backend server image
@echo "Build acceptance backend"
acceptance-backend-image-build:
@echo "Build acceptance backend image"
@docker build backend -t {{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}-backend:acceptance -f backend/Dockerfile.acceptance --build-arg PLONE_VERSION=$(PLONE_VERSION)

.PHONY: acceptance-images-build
Expand All @@ -185,12 +185,12 @@ acceptance-images-build: ## Build Acceptance frontend/backend images
$(MAKE) acceptance-frontend-image-build

.PHONY: acceptance-frontend-container-start
acceptance-frontend-container-start: ## Start Acceptance frontend container
acceptance-frontend-container-start:
@echo "Start acceptance frontend"
@docker run --rm -p 3000:3000 --name {{ cookiecutter.project_slug }}-frontend-acceptance --link {{ cookiecutter.project_slug }}-backend-acceptance:backend -e RAZZLE_API_PATH=http://localhost:55001/plone -e RAZZLE_INTERNAL_API_PATH=http://backend:55001/plone -d {{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}-frontend:acceptance

.PHONY: acceptance-backend-container-start
acceptance-backend-container-start: ## Start Acceptance backend container
acceptance-backend-container-start:
@echo "Start acceptance backend"
@docker run --rm -p 55001:55001 --name {{ cookiecutter.project_slug }}-backend-acceptance -d {{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}-backend:acceptance

Expand All @@ -206,7 +206,8 @@ acceptance-containers-stop: ## Stop Acceptance containers
@docker stop {{ cookiecutter.project_slug }}-backend-acceptance

.PHONY: ci-acceptance-test
ci-acceptance-test: ## Run Acceptance tests in ci mode
ci-acceptance-test:
@echo "Run acceptance tests in CI mode"
$(MAKE) acceptance-containers-start
pnpm dlx wait-on --httpTimeout 20000 http-get://localhost:55001/plone http://localhost:3000
$(MAKE) -C "./frontend/" ci-acceptance-test
Expand Down
1 change: 1 addition & 0 deletions project/{{ cookiecutter.__folder_name }}/devops/.env_dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ANSIBLE_REMOTE_PORT=22
DEPLOY_ENV=prod
DEPLOY_HOST={{ cookiecutter.hostname }}
DEPLOY_PORT=22
Expand Down
5 changes: 5 additions & 0 deletions project/{{ cookiecutter.__folder_name }}/devops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ stack-logs-backend: ## Display backend logs
@echo "$(GREEN)==> Stack $(STACK_NAME): Logs for backend in context $(DEPLOY_ENV) $(RESET)"
${DOCKER_CMD_CONTEXT} service logs $(STACK_NAME)_backend

.PHONY: stack-logs-db
stack-logs-db: ## Display db logs
@echo "$(GREEN)==> Stack $(STACK_NAME): Logs for db in context $(DEPLOY_ENV) $(RESET)"
${DOCKER_CMD_CONTEXT} service logs $(STACK_NAME)_db

.PHONY: stack-scale-services
stack-scale-services: ## Scale services
@echo "$(GREEN)==> Stack $(STACK_NAME): Scaling Frontend and Backend to $(DEPLOY_SCALES) in context $(DEPLOY_ENV) $(RESET)"
Expand Down
2 changes: 2 additions & 0 deletions project/{{ cookiecutter.__folder_name }}/devops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ cp .env_dist .env
Edit the `.env` file to suit your environment. For example:

```
ANSIBLE_REMOTE_PORT=22
DEPLOY_ENV=prod
DEPLOY_HOST={{ cookiecutter.hostname }}
DEPLOY_PORT=22
DEPLOY_USER=plone
DEPLOY_FOLDER=/srv/{{ cookiecutter.project_slug }}/data
DOCKER_CONFIG=.docker
STACK_NAME={{ cookiecutter.__devops_stack_name }}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
project_folders:
# Path to store {{ cookiecutter.hostname }} postgres data
path: "{{ lookup('ansible.builtin.env', 'DEPLOY_FOLDER', default='/srv/plone/data') }}"
- path: {{ "\"{{ lookup('ansible.builtin.env', 'DEPLOY_FOLDER', default='/srv/plone/data') }}\"" }}
owner: 999
group: 999
mode: "0750"
Loading

0 comments on commit 949dbb0

Please sign in to comment.