Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Oct 23, 2021
0 parents commit 86e07fe
Show file tree
Hide file tree
Showing 29 changed files with 756 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules

CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))


# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

.PHONY: build-images
build-images: ## Build docker images
@echo "Build"
$(MAKE) -C "./backend/" build-image
$(MAKE) -C "./frontend/" build-image

.PHONY: release-images
release-images: build-images ## Build docker images
@echo "Release"
$(MAKE) -C "./backend/" release-image
$(MAKE) -C "./frontend/" release-image

.PHONY: start-images
start-images: ## Start docker compose
@echo "Build"
@docker-compose -f dockerfiles/local-dev.yml up --build
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Plone Deployment Training Example Repo

## Initial Setup

* Fork this repo into your Github account
* `git clone [email protected]:MYUSER/training-deploy-project.git`
* Open in your favorite text editor. ie: `cd training-deploy-project && code ./`
* Find all occurences of **DOCKER_HUB_USER_CHANGE_ME** and replace it with your Docker Hub user name

## Setup backend

Create a Python virtual environment, install Plone 6.0.0a1 and one addon.

```shell
cd backend
make setup
```

Run the Plone Backend instance
```shell
make start
```

In a browser, go to [http://localhost:8080/@@plone-addsite?site_id=Plone&advanced=1](http://localhost:8080/@@plone-addsite?site_id=Plone&advanced=1 and create a new site:

![Plone site creation](./docs/plone-setup.png "Plone site creation")

Stop the process

## Setup a new frontend project

On the root of this project

```shell
npm init yo @plone/volto
```

Answer the questions:
```
Project name (e.g. my-volto-project) frontend
Would you like to add addons? True
Addon name, plus extra loaders, like: volto-addon:loadExtra,loadAnotherExtra volto-slate:asDefault
Would you like to add another addon? false
```

Edit ```frontend/package.json``` and change ```"@plone/volto": "13.15.1",``` to ```"@plone/volto": "14.0.0-alpha.23",```

And run ```cd frontend && yarn```

Start it with

```yarn start```

## Running everything with docker

```shell
make start-images
```
7 changes: 7 additions & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.vagrant
.vagrant_private_key
bin
include
lib
lib64
pyvenv.cfg
70 changes: 70 additions & 0 deletions ansible/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules


# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

.PHONY: all
all: build

# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: ## remove all build, test, coverage and Python artifacts
rm -Rf bin lib lib64 include pyvenv.cfg

bin/pip:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
python3 -m venv .
bin/pip install -U pip

bin/ansible: bin/pip
@echo "$(GREEN)==> Setup Ansible $(RESET)"
bin/pip install -r requirements.txt --upgrade

.PHONY: setup
setup: bin/ansible ## Create VirtualEnv and install Ansible via Pip
@echo "$(GREEN)==> Ansible available at ./bin/ansible $(RESET)"

.PHONY: vagrant-provision
vagrant-destroy: bin/ansible ## Provision Vagrant box
@echo "$(GREEN)==> Provision Vagrant box $(RESET)"
sudo vagrant destroy
sudo rm .vagrant_private_key .vagrant

.PHONY: vagrant-provision
vagrant-provision: bin/ansible ## Provision Vagrant box
@echo "$(GREEN)==> Provision Vagrant box $(RESET)"
sudo vagrant up
sudo cp .vagrant/machines/default/virtualbox/private_key .vagrant_private_key
USER=`whoami` sudo chown ${USER}: .vagrant_private_key
ssh-keygen -f ~/.ssh/known_hosts -R "[127.0.0.1]:2222"

.PHONY: playbook-setup
playbook-setup: bin/ansible ## Run playbook
@echo "$(GREEN)==> Apply playbook $(RESET)"
./bin/ansible-playbook -i hosts playbook-setup.yml

.PHONY: compose-pull
compose-pull: ## Run Compose pull
docker-compose --context vagrant --project-directory project pull

.PHONY: compose-up
compose-up: ## Run Compose up
docker-compose --context vagrant --project-directory project up -d
70 changes: 70 additions & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Ansible deployment

## Setup

Install Python 3 virtual environment and Ansible

```shell
cd ansible
make clean
make setup
```

## Provision a local Vagrant box

```shell
make vagrant-provision
```

This may take a while to download the Ubuntu 20.04 Vagrant image.

To check if the vagrant box is up and running:

```shell
sudo vagrant status
```

## Configure the server

Now we run an Ansible playbook (`playbook-setup.yml`) that will:

* Install base packages
* Create a user plone
* Configure nginx webserver to listen on port 80 (`files/nginx/default`)
* Copy the docker-compose.yml configuration to the server

First, you need to edit the file `playbook-setup.yml` and replace the line:
```
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDJIwjHxRAM1a8zc1kuTJ0GyzvloaBTz/fO7bGoNOlxY2lnUDop+q3CbHF28IkmVQCk28I+MXCnUXG6ARZgnBcb4LDey9WPVsiy3NRCXOmaZK6NKmKUejdA5Y4ZTHbs6rdIInDLWaFxzoxg5p/LaXUaTrKra2SpGc3kv7xKiZKXyTznFjFSv/u6Wm/vvZopWM6m4k8Z00fTUtxQO0eWKArStF99YFszUDU2w2jhL7n8irLow0UqjNjp0MvkPiic2SueoylQRIlD57XzveMBpGynYdsZWKDa3Czzo5ykHPLYrOByioKKjnpwgruXnXkkN4ov8sK+LqqAXaicxed6ohbOh68IWVB8nssb+RbISmzzpIXUwd1qkAyeiSjt5b9MFcIT56zeRb5B+aWZbYffc+pKy8kAjrYHCWEFl6O3N+M/bI9jgtXcZ9L6FSBN5vWjgRQPn7UwiMXIUssm0lU5AgCxs7q7S0xACj0xVFk5NeUM9vcCzXkY9vAjJmE1hzBWeOVhhQqLKmkbi/scr5hW2rrNwnuPBpyHUu2wTIyGHbnZ9CCwU3u21XDyvvO9ufxDjIH3v2EwEPqpbejKRM8QUH6YuH2goy89yQQijsC0YUE8AlJpbs9ctxSyzsJ6Z3ZwHJA681Ei15omhab2iwmT4KcS+3mC5pSCsFQgA4OsJKy5OQ== [email protected]"
```
With your ssh public key (probably available in `~/.ssh/id_rsa.pub`)

Then we run the playbook:

```shell
make playbook-setup
```

You can test if the `plone` user setup is correct:

```shell
ssh [email protected] -p 2222
```

## Create a new Docker context

```shell
docker context create vagrant --description "Plone Deployment training" --docker "host=ssh://[email protected]:2222"
```

## Pull Docker images

```shell
make compose-pull
```

## Start all services

```shell
make compose-up
```
13 changes: 13 additions & 0 deletions ansible/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/focal64"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 1
end
end
38 changes: 38 additions & 0 deletions ansible/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3"
services:

frontend:
image: plone/plone-frontend:14.0.0-alpha-node14
environment:
RAZZLE_INTERNAL_API_PATH: http://backend:8080/Plone
RAZZLE_DEV_PROXY_API_PATH: http://backend:8080/Plone
restart: always
ports:
- "3000:3000"
depends_on:
- backend

backend:
image: plone/plone-backend:6.0-dev-python39
environment:
RELSTORAGE_DSN: "dbname='plone' user='plone' host='db' password='plone'"
restart: always
ports:
- "8080:8080"
depends_on:
- db

db:
image: postgres
environment:
POSTGRES_USER: plone
POSTGRES_PASSWORD: plone
POSTGRES_DB: plone
restart: always
volumes:
- data:/var/lib/postgresql/data
ports:
- "5432:5432"

volumes:
data: {}
44 changes: 44 additions & 0 deletions ansible/files/nginx/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
upstream backend {
server localhost:8080;
}
upstream frontend {
server localhost:3000;
}


server {
listen 80;
server_name localhost
vagrant;

location ~ /\+\+api\+\+($|/.*) {
rewrite ^/\+\+api\+\+($|/.*) /VirtualHostBase/http/$server_name/Plone/++api++/VirtualHostRoot/$1 break;
proxy_pass http://backend;
}

location ~ / {
location ~* \.(js|jsx|css|less|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
expires +1y;
proxy_pass http://frontend;
}
location ~* static.*\.(ico|jpg|jpeg|png|gif|svg)$ {
add_header Cache-Control "public";
expires +1y;
proxy_pass http://frontend;
}

location ~ /(@@download|@@images|@@ical_view) {
rewrite ^(.*) /VirtualHostBase/http/$server_name/Plone/VirtualHostRoot$1 break;
proxy_pass http://backend;
break;
}

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://frontend;
}
}
5 changes: 5 additions & 0 deletions ansible/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Define all machines and then group them
vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_user=vagrant ansible_ssh_private_key_file=./.vagrant_private_key

[all]
vagrant
Loading

0 comments on commit 86e07fe

Please sign in to comment.