Using eZ Launchpad with Platform.sh

For eZ Platform Development with eZ Platform Cloud

Sébastien Morel
3 min readDec 26, 2018

Context

Merry Christmas all, on vacation and still a bit jet-lagged I am waking up early and I am taking the time to write this article that could have followed this one: https://medium.com/@Plopix/ez-platform-cloud-and-ez-launchpad-dont-host-don-t-deploy-don-t-install-just-code-6140d75a439d

As you may know, I am a huge fan of PHP, Symfony, and eZ Platform along with Docker and Platform.sh. eZ Platform is a Content Management System (CMS) fully based on Symfony (i.e: it does not just use few Symfony components, it is a full Symfony application using the framework). And eZ Platform Cloud is one of the White-Label PaaS for Platform.sh

I saw a tweet this morning about Docksal.io and Platform.sh, and I decided to write this one to explain how we are using eZ Launchpad for local development with Platform.sh and how it is simple.

@Platform.sh: I would be very proud to write or see a part of this article in your documentation.

Let’s get started!

eZ Launchpad Install

eZ Launchpad approach is to stay as decoupled as possible from your development machine and your remote hosting whether you are Linux or Mac OSX. Installation is really simple:

$ curl -LSs https://ezsystems.github.io/launchpad/install_curl.bash | bash

Then you can just start to use it to initialize your eZ Platform project on top docker (see my previous article)

~/ez init

or just create the docker stack based on an existing project

git clone yourproject.git ezplatform; cd ezplatform; ~/ez create

Done!

Now how to nicely work with Platform.sh

Platform.sh integration

First the .platform.app.yaml and the .platform generation, those two files are the key for Platform.sh.

To generate them, you just have to run

~/ez platformsh:setup

Launchpad will generate the files for you and you are then totally free to finetune them.

Local development with Platform.sh

First, let’s describe what do we mean here. Local development is ensured by the docker stack but what are the minimum day-to-day tasks that we need with our remote PaaS?

  • Database synchronization (getting it from the PaaS to the local)
  • File storage synchronization (getting it from the PaaS to the local)
  • Deployment

We could also used SSH tunnels, but that is not the way we are doing it, we, as mentioned want to be as decoupled as possible. Then we want the whole project to work offline on our local.

Thankfully Platform.sh provides a CLI that you probably already have, if you don’t

curl -sS https://platform.sh/cli/installer | php

So we want to automate actions, right? Makefile! Here are my 4 best friend targets:

# Makefile
PLATFORMSH := platform
EZ := ~/ez
GIT := git
.PHONY: reinitdb
reinitdb: ## Re initialize a fresh database
@$(EZ) importdata
@$(EZ) sfrun cache:clear
.PHONY: sync-local-db-only
sync-local-db-only: ## Sync the local db ONLY
@$(PLATFORMSH) db:dump --gzip -f ezplatform.sql.gz -d data/ -y
@$(MAKE) reinitdb
.PHONY: sync-local-storage
sync-local-storage: sync-local-db-only ## Sync the local db and storage
@$(PLATFORMSH) mount:download -m ezplatform/web/var --target=ezplatform/web/var/ -y
tag := master-$(shell date +%F-%H-%M-%S-%Z)
.PHONY: deploy-prod ## Tag and deploy on the master(prod) env
deploy-prod:
$(GIT) tag -a $(tag) -m 'New Release' master
$(GIT) push origin $(tag)
$(GIT) push platform +$(tag)~0:master

Explanations:

~/ez importdata

This is an eZ Launchpad command that takes the data and the database (from the local data/folder) and imports it in the local docker stack. (~/ez dumpdata would do the opposite)

~/ez sfrun cache:clear

This runs the Symfony command (“symfony run”): cache:clear

Yes, remember, you need to execute PHP from within your container (local docker stack) eZ Launchpad is a wrapper made to simplify that:

  • ~/ez sfrun something : to run bin/console something inside the container
  • ~/ez comprun something : to run composer something inside the container
  • ~/ez enter : to enter by default in the PHP container

Now you know that the following is just straightforward, staying on the host (i.e: you don’t that to go in the container)

  • We get the database dump in the data/folder and we import
platform db:dump --gzip -f ezplatform.sql.gz -d data/ -y
~/ez importdata
  • and we sync the storage
platform mount:download -m ezplatform/web/var --target=ezplatform/web/var/ -y

The last target deploy-prodis one automation to tag /push master in your code authority and push to Platform.sh to deploy.

That’s it!

Many more things can be done using eZ Launchpad to rock your Developer eXperience, ~/ez list will give you an overview.

Hope you will try it!

See you!

https://www.novactive.us

--

--

Sébastien Morel

CTO @AlmaviaCX / Head of U.S. | #web #mobile #innovation #symfony #ezplatform #php #ios #docker #varnish #opensource #dad #plop