Skip to content

Commit

Permalink
Merge branch 'main' into erral-gitlab-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
erral authored Oct 30, 2024
2 parents 4df2d9f + 6e8c38d commit c148692
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 52 deletions.
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 @@ -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
4 changes: 2 additions & 2 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
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 @@ -39,6 +39,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 @@ -61,12 +62,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 @@ -126,8 +128,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
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"
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ services:

networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}

{%- if cookiecutter.devops_cache == '1' %}

Expand All @@ -89,7 +90,7 @@ services:
PURGER_SERVICE_PORT: 80
PURGER_PUBLIC_SITES: "['{{ cookiecutter.hostname }}']"
networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}
deploy:
replicas: 2
update_config:
Expand All @@ -115,7 +116,7 @@ services:
- frontend
- backend
networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}
deploy:
replicas: 1
update_config:
Expand Down Expand Up @@ -150,6 +151,7 @@ services:
- backend
networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}
deploy:
replicas: 2
update_config:
Expand Down Expand Up @@ -189,6 +191,7 @@ services:
- db
networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}
deploy:
replicas: 2
update_config:
Expand Down Expand Up @@ -251,17 +254,19 @@ services:
volumes:
- vol-site-data:/var/lib/postgresql/data
networks:
- {{ cookiecutter.__devops_swarm_public_network }}
- {{ cookiecutter.__devops_swarm_stack_network }}

volumes:
vol-traefik-certs: {}
vol-site-data:
driver_opts:
type: none
device: "${DEPLOY_FOLDER:/srv/{{ cookiecutter.project_slug }}/data}"
device: ${DEPLOY_FOLDER:-/srv/{{ cookiecutter.project_slug }}/data}
o: bind

networks:
{{ cookiecutter.__devops_swarm_public_network }}:
external: true
{{ cookiecutter.__devops_swarm_stack_network }}:
internal: true
driver: overlay
Loading

0 comments on commit c148692

Please sign in to comment.