https://github.com/upsun/bigfoot-multiapp-example
https://github.com/upsun/bigfoot-multiapp-example
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/upsun/bigfoot-multiapp-example
- Owner: upsun
- Created: 2024-03-13T15:52:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-14T09:24:35.000Z (about 2 years ago)
- Last Synced: 2024-03-14T10:32:32.483Z (about 2 years ago)
- Language: PHP
- Size: 1.03 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[DEMO] Deploy a multi-app project with Bigfoot website, API Platform admin (ReactJS), Gatsby website and Mercure.rocks server on Upsun
Contribute, request a feature, or check out our resources
Join our community      
Documentation      
Blog      
Report a bug      
Request a feature
Contents
About      
Getting started      
Migrate      
Learn      
Contribute      
> **_DISCLAIMER:_**
>
This is an example codebase to host a multiple applications project with Upsun.
>
This repo is used in [this blogpost](https://upsun.com/blog/upsun-and-running-with-multiple-applications/) as a starting point for the users and is not meant to be updated along the way.
## About
We have just created a new multi-app project for you, based on Bigfoot Project, API Platform Admin, Gatsby and Mercure.rocks server.
The generated code has been setup for a typical web multi-application project hosted on Upsun.
### Features
- PHP 8.3
- PostgreSQL v15
- Composer-based build
- Yarn v1.22.17
- GO 1.21
- NodeJS v20
- Mercure.rocks server v0.14.4
## Getting started
### Local development
This section provides instructions for running the `Bigfoot Multi-app Example` locally, connected to a local database instance.
In all cases for developing with Upsun, it's important to develop on an isolated environment - do not connect to data on your production environment when developing locally.
Each of the options below assume that you have already deployed this template to Upsun, as well as the following starting commands:
1. Install the Upsun CLI
Follow the instructions to [install the Upsun CLI](https://docs.upsun.com/administration/cli.html) for your operating system.
You can verify the installation by logging in (`upsun login`) and listing your projects (`upsun project:list`).
1. Find your `PROJECT_ID` by running the command `upsun project:list`
```bash
+---------------+------------------------------------+------------------+---------------------------------+
| ID | Title | Region | Organization |
+---------------+------------------------------------+------------------+---------------------------------+
| PROJECT_ID | Your Project Name | xx-3.platform.sh | your-username |
+---------------+------------------------------------+------------------+---------------------------------+
```
1. Get your Upsun project
```
upsun get PROJECT_ID
cd
```
or fork this repo if you don't have any existing project and then clone your own repo
```
git clone git@github.com:/bigfoot-multiapp-example.git bigfoot-multiapp
cd bigfoot-multiapp
```
1. Start the API component:
1. `cd ./api`
1. Install Symfony CLI
1. Start docker container for the database : `docker-compose up -d`
1. `symfony composer install`
1. check that your `api/.env` file contains a valid `DATABASE_URL` to let Symfony connect to your database
``` {location="./api/.env""}
DATABASE_HOST=127.0.0.1
DATABASE_PORT=52947
DATABASE_NAME=app
DATABASE_USER=symfony
DATABASE_PASSWORD=ChangeMe
DATABASE_URL="postgresql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?serverVersion=14&charset=utf8"
```
1. `symfony console doctrine:schema:create --dump-sql` (use `--force` if there any SQL requests displayed)
1. `symfony server:start -d`
1. `yarn install && yarn encore dev`
1. `symfony open:local` or you can go on `https://localhost:8000/api`
> **Note:**
> if symfony server does not start your app using default port 8000, please change `REACT_APP_PUBLIC_URL` from `./admin/.env` file to reflect new port in use
1. Start Gatsby app in a new terminal tab
1. Open a new terminal using CTRL+T (to be on the same root folder)
1. `cd ../gatsby`
1. [Install Gatsby CLI](https://www.gatsbyjs.com/docs/reference/gatsby-cli/)
1. Start Gatsby
```
export SHARP_IGNORE_GLOBAL_LIBVIPS=true (optional if using a mac)
yarn
NODE_TLS_REJECT_UNAUTHORIZED=0 gatsby develop -p 8080
```
1. open http://localhost:8080/ in your browser
1. Start Mercure server locally in a new terminal tab
1. Open a new terminal using CTRL+T (to be on the same root folder)
1. ``cd ../mercure``
1. create docker Mercure.rocks container
```bash
docker run \
-e MERCURE_PUBLISHER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' \
-e MERCURE_SUBSCRIBER_JWT_KEY='!ChangeThisMercureHubJWTSecretKey!' \
-p 8006:80 \
-p 8007:443 \
dunglas/mercure caddy run --config /etc/caddy/Caddyfile.dev
```
1. open [localhost:8007](https://localhost:8007) in your browser
1. Start the ADMIN component in a new terminal tab
1. `cd ../admin` (assuming that you were in the `./mercure` folder)
1. `yarn install`
1. `yarn start`
1. a new browser tab should be opened automatically with url http://localhost:3000
1. Create a new branch
```
upsun branch new_branch
```
1. Develop your feature and commit it in GIT
1. Push your code to your environment (can be done multiple time)
```
upsun push
```
1. Push to production
```
upsun checkout main
upsun merge new_branch
```
> **Note:**
> For many of the steps above, you may need to include the CLI flags `-p PROJECT_ID` and `-e ENVIRONMENT_ID` if you are not in the project directory or if the environment is associated with an existing pull request.
### Deploying to Upsun
This repository has all the code it needs in order to deploy to Upsun.
Deploy directly to Upsun from the command line
1. Create a free trial:
[Register for a 30 day free trial with Upsun](https://auth.api.upsun.com/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
1. Install the Upsun CLI
Follow the instructions to [install the Upsun CLI](https://docs.upsun.com/administration/cli.html) for your operating system.
You can verify the installation by logging in (`upsun login`) and listing your projects (`upsun project:list`).
1. Set the project remote
Find your `PROJECT_ID` by running the command `upsun project:list`
```bash
+---------------+------------------------------------+------------------+---------------------------------+
| ID | Title | Region | Organization |
+---------------+------------------------------------+------------------+---------------------------------+
| PROJECT_ID | Your Project Name | xx-5.platform.sh | your-username |
+---------------+------------------------------------+------------------+---------------------------------+
```
Then from within your local copy, run the command `upsun project:set-remote PROJECT_ID`.
1. Push using git
```bash
git push upsun DEFAULT_BRANCH
```
1. or Push using Upsun CLI
```bash
upsun push
```
Integrate with a GitHub repo and deploy pull requests
1. Create a free trial:
[Register for a 30 day free trial with Upsun](https://auth.api.upsun.com/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to whatever you have set at `https://YOUR_NAMESPACE/nextjs-drupal`.
1. Install the Upsun CLI
Follow the instructions to [install the Upsun CLI](https://docs.upsun.com/administration/cli.html) for your operating system.
You can verify the installation by logging in (`upsun login`) and listing your projects (`upsun project:list`).
1. Setup the integration:
Consult the [GitHub integration documentation](https://docs.upsun.com/integrations/source/github.html#setup) to finish connecting your repository to a project on Upsun. You will need to create an Access token on GitHub to do so.
1. Then, just use regular GIT commands to push your code to your repository. It will automatically update your corresponding Upsun environment
Integrate with a GitLab repo and deploy merge requests
1. Create a free trial:
[Register for a 30 day free trial with Upsun](https://auth.api.upsun.com/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
1. Install the Upsun CLI
Follow the instructions to [install the Upsun CLI](https://docs.upsun.com/administration/cli.html) for your operating system.
You can verify the installation by logging in (`upsun login`) and listing your projects (`upsun project:list`).
1. Create the repository
Create a new repository on GitLab, set it as a new remote for your local copy, and push to the default branch.
1. Setup the integration:
Consult the [GitLab integration documentation](https://docs.upsun.com/integrations/source/gitlab.html#setup) to finish connecting a repository to a project on Upsun. You will need to create an Access token on GitLab to do so.
1. Then, just use regular GIT commands to push your code to your repository. It will automatically update your corresponding Upsun environment
Integrate with a Bitbucket repo and deploy pull requests
1. Create a free trial:
[Register for a 30 day free trial with Upsun](https://auth.api.upsun.com/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
1. Install the Upsun CLI
Follow the instructions to [install the Upsun CLI](https://docs.upsun.com/administration/cli.html) for your operating system.
You can verify the installation by logging in (`upsun login`) and listing your projects (`upsun project:list`).
1. Create the repository
Create a new repository on Bitbucket, set it as a new remote for your local copy, and push to the default branch.
1. Setup the integration:
Consult the [Bitbucket integration documentation](https://docs.upsun.com/integrations/source/bitbucket.html#setup) to finish connecting a repository to a project on Upsun. You will need to create an Access token on Bitbucket to do so.
1. Then, just use regular GIT commands to push your code to your repository. It will automatically update your corresponding Upsun environment
### Migrating your data
If you are moving an existing site to Upsun, then in addition to code you also need to migrate your data. That means your database and your files.
Importing the database
First, obtain a database dump from your current site and save your dump file as `database.sql`. Then, import the database into your Upsun site using the CLI:
```bash
upsun sql -e main < database.sql
```
Importing files
You first need to download your files from your current hosting environment.
The easiest way is likely with rsync, but consult your old host's documentation.
The `upsun mount:upload` command provides a straightforward way to upload an entire directory to your site at once to a `mount` defined in a `.upsun/config.yaml` file.
Under the hood, it uses an SSH tunnel and rsync, so it is as efficient as possible.
(There is also a `upsun mount:download` command you can use to download files later.)
Run the following from your local Git repository root (modifying the `--source` path if needed and setting `BRANCH_NAME` to the branch you are using).
A few examples are listed below, but repeat for all directories that contain data you would like to migrate.
```bash
upsun mount:upload -e main --mount web/sites/default/files --source ./web/sites/default/files
upsun mount:upload -e main --mount private --source ./private
```
Note that `rsync` is picky about its trailing slashes, so be sure to include those.
With your application now deployed on Upsun, things get more interesting.
Run the command `upsun environment:branch new-feature` for your project, or open a trivial pull request off of your current branch.
The resulting environment is an *exact* copy of production (or corresponding parent environment).
It contains identical infrastructure to what's been defined in your configuration files, and even includes data copied from your production environment in its services.
On this isolated environment, you're free to make any changes to your application you need to, and really test how they will behave on production.
After that, here are a collection of additional resources you might find interesting as you continue with your migration to Upsun:
[comment]: <> (- [Local development](#local-development))
- [Troubleshooting](#troubleshooting)
- [Adding a domain and going live](https://docs.upsun.com/domains/steps.html)
- [(CDN) Content Delivery Networks](https://docs.upsun.com/domains/cdn.html)
- [Performance and observability with Blackfire.io](https://docs.upsun.com/integrations/observability/blackfire.html)
- [Pricing](https://docs.upsun.com/overview/pricing.html)
- [Security and compliance](https://docs.upsun.com/security.html)
## Learn
### Troubleshooting
Accessing logs
After the environment has finished its deployment, you can investigate issues that occured on startup, `deploy` and `post_deploy` hooks, and generally at runtime using the CLI. Run the command:
```bash
upsun ssh
```
If you are running the command outside a local copy of the project, you will need to include the `-p` (project) and/or `-e` (environment) flags as well.
Once you have connected to the container, [logs](https://docs.upsun.com/development/logs.html#container-logs) are available within `/var/log/` for you to investigate.
Rebuilding cache
You may run into a database error after installing Symfony on your production environment initially.
To fix, SSH into the `api` application container (`upsun ssh`) and rebuild the cache using Symfony console:
```bash
php bin/console cache:clear
php bin/console cache:pool:clear cache.app
```
### Blackfire.io: creating a Continuous Observability Strategy
This template includes a starting [`.blackfire.yml`](.blackfire.yml) file that can be used to enable [Application Performance Monitoring](https://blackfire.io/docs/monitoring-cookbooks/index), [Profiling](https://blackfire.io/docs/profiling-cookbooks/index), [Builds](https://blackfire.io/docs/builds-cookbooks/index) and [Performance Testing](https://blackfire.io/docs/testing-cookbooks/index) on your project. Upsun comes with Blackfire pre-installed on application containers, and [setting up requires minimal configuration](https://docs.upsun.com/integrations/observability/blackfire.html).
* [What is Blackfire?](https://blackfire.io/docs/introduction)
* [Configuring Blackfire.io on a Upsun project](https://docs.upsun.com/integrations/observability/blackfire.html)
* [Blackfire.io Upsun documentation](https://blackfire.io/docs/integrations/paas/platformsh)
* [Profiling Cookbooks](https://blackfire.io/docs/profiling-cookbooks/index)
* [Monitoring Cookbooks](https://blackfire.io/docs/monitoring-cookbooks/index)
* [Testing Cookbooks](https://blackfire.io/docs/testing-cookbooks/index)
* [Using Builds](https://blackfire.io/docs/builds-cookbooks/index)
* [Configuring Integrations](https://blackfire.io/docs/integrations/index)
### Resources
- [API Platform](https://api-platform.com/)
- [Upsun PHP documentation](https://docs.upsun.com/languages/php.html)
### Contact
This template is maintained by the Upsun Developer Relations team, and they will be notified of all issues and pull requests you open here.
- **Discord:** If you haven't done so already, you can join Upsun's community on [Discord](https://discord.gg/z2YQzTeZqY) channels and ping the `@devrel_team` with any questions.
### About Upsun
This template has been specifically designed to deploy on Upsun.
What is Upsun?
Upsun is a unified, secure, enterprise-grade platform for building, running and scaling web applications. We’re the leader in Fleet Ops: Everything you need to manage your fleet of websites and apps is available from the start. Because infrastructure and workflows are handled from the start, apps just work, so teams can focus on what really matters: making faster changes, collaborating confidently, and scaling responsibly. Whether managing a fleet of ten or ten thousand sites and apps, Upsun is the Developer- preferred solution that scales right.
Our key features include:
* **GitOps: Git as the source of truth**
Every branch becomes a development environment, and nothing can change without a commit.
* **Batteries included: Managed infrastructure**
[Simple abstraction in YAML](https://docs.upsun.com/configuration/yaml.html) for [committing and configuring infrastructure](https://docs.upsun.com/overview/structure.html), fully managed patch updates, and 24 [runtimes](https://docs.upsun.com/languages.html) & [services](https://docs.upsun.com/configuration/services.html) that can be added with a single line of code.
* **Instant cloning: Branch, merge, repeat**
[Reusable builds](https://docs.upsun.com/overview/build-deploy.html) and automatically inherited production data provide true staging environments - experiment in isolation, test, then destroy or merge.
* **FleetOps: Fleet management platform**
Leverage our public API along with custom tools like [Source Operations](https://docs.upsun.com/configuration/app/source-operations.html) and [Activity Scripts](https://docs.upsun.com/integrations/activity.html) to [manage thousands of applications](https://youtu.be/MILHG9OqhmE) - their dependency updates, fresh content, and upstream code.
Contribute
Help us keep top-notch templates!
Every one of our templates is open source, and they're important resources for users trying to deploy to Upsun for the first time or better understand the platform. They act as getting started guides, but also contain a number of helpful tips and best practices when working with certain languages and frameworks.
See something that's wrong with this template that needs to be fixed? Something in the documentation unclear or missing? Let us know!
How to contribute
Report a bug      
Submit a feature request      
Open a pull request      
Need help?
Thanks to all of our amazing contributors!
Made with contrib.rocks