Integrate Gitpod into an existing Magento project.
To get started clone our Magento Gitpod repository into the root of your Magento project
$ git clone https://github.com/develodesign/magento-gitpod
$ cd ./magento-gitpod
Now copy our Magento Repo contents into the root of your Magento project repository.
cp -R ./* ../
You can now commit these files to your repository and start a new server instance for this repository from Github using the Gitpod button.
Importing an existing Magento 2 database
There is a section of the m2.install.sh file that can be uncommented out, this will install your exiting staging database, replacing all URLS in the .sql file with the Gitpod instance URLs.
What about pub/media files?
The following hack is a quick way of having the site show all images but not require a local copy. Edit the pub/get.php file and add the following code, this will look at the live domain if no local file is found.
*Warning, please understand how this works before trying it. This will cause lots of requests to the live domain, hopefully your static assets on live are served via a CDN, but if you have issues with images not on live you may find lots of 404 requests to the live domain, don't go DDOS' your own site, use with caution!
Once an instance has started and it's ready to work, your workspace files are already directly checked out from Git, and any changes you make can be committed and pushed directly without any additional authentication or setup.
You can edit the files via VSCode or PHPStorm directly on the instance!
What's required to get started with Magento?
I wanted to keep the gitpod files added to the project root to a minimal, so all configuration files goes in the gitpod folder. The .gitpod.yml and .gitpod.Dockerfiles are the only files required at the root.
The contents of the gitpod folder are as follows,
Most of these are straight forward service configuration that most Magento developers are familiar with. Update these files as needed to support the projects requirements.
The only file that won't be familiar is m2-install.sh. This is responsible for the Magento application installation, so it will git checkout the required Magento 2 version, install all dependances, remove modules that aren't needed for development env's 2FA CSP etc.
Use this file to configure the Magento application as needed, for local development.
This the main file used by Gitpod to orchestrate the build process, this tells Gitpod to build the server as explained in the Docker file. You can adjust the DockerFile to change PHP/MySql versions etc, any changes to the DockerFile will cause Gitpod to rebuild the image used. After a rebuild anyone else loading that project will use the pre-built image, speeding up deployment.
After an image is built Gitpod will then run the tasks of the .gitpod file. You can learn more about the different tasks and when they run during the build and deployment lifecycle process here.
Our Magento command task is here,
There might seem a lot of commands here but the main purpose of them is to configure the services, php/mysql etc for the current workspaces URL and directory structure, as each instance is given unique urls on creation and directory names per project.
The last line is what's responsible to ensure Magento is installed on this instance only once, per startup. This speeds up the deployment start up time, and enables you to keep database / Magento admin changes while working on the workspace instance.
Starting and stopping Instances
Gitpod workspaces can be stopped and started at any time, a workspace will be stopped if idle for more than an hour, or it can be extended to 3 hours idle as needed.
Having an instance stop is not the end of the world, here are some rough estimates on start up time, from opening an instance to seeing the Magento site start in the browser.
Start up times
- First time anyone has built a specific project : 15 mins
- Starting a project from a prebuilt image : 5 mins
- Opening a project that has been started and is idle : 10 seconds