How to workaround the following errors:
The default website isn't defined. Set the website and try again. in
The store that was requested wasn't found
When setting up a Continuous Integration/Continuous Deployment (CI/CD) process for Magento 2. Make sure you do this without direct database access. Ensure that your CI/CD environment can handle the compilation of static files. Here's a guide on how to do this:
1) Set Up CI/CD Environment:
Choose a CI/CD platform such as Bamboo, Bitbucket Pipeline, Jenkins, GitLab CI/CD, Travis CI, or any other that suits your needs.
Ensure that your CI/CD environment has the necessary dependencies installed, including PHP, Composer, and any required Magento dependencies.
2) Clone Magento Repository:
In your CI/CD environment, clone your Magento 2 repository from your version control system (e.g., Git).
3) Install Magento Dependencies:
Run composer install in the root directory of your Magento 2 installation to install all required PHP dependencies.
4) Generate Environment Configuration:
Create app/etc/config.php using your Magento 2 installation's command:
bin/magento app:config:dump
and modify it to keep only modules, scopes and themes sections to provide the necessary configurations through environment variables or another method that your CI/CD environment supports.
5) Compile Static Files:
Run the following command to compile static files:
php bin/magento setup:static-content:deploy
You may need to pass additional options such as locales and themes depending on your setup. Check Magento's documentation for more details.
6) Deploy Compiled Static Files:
After compiling static files, deploy them to your web server or hosting environment. You can use tools like rsync, scp, or FTP to transfer the files.
7) Testing:
Implement automated tests (unit tests, integration tests, etc.) in your CI/CD pipeline to ensure that the Magento instance is functioning correctly after compiling static files.
8) Deploy to Production:
If your CI/CD pipeline includes deployment to a production environment, ensure that proper validation steps are in place before deploying changes.
9) Monitoring and Maintenance:
Set up monitoring and alerting for your Magento instance to detect any issues that may arise post-deployment. Regular maintenance and monitoring are essential for ensuring the stability and performance of your Magento store.
By following these steps, you can incorporate static files compilation into your CI/CD process for Magento 2 without direct database access. Be sure to adjust the process according to your specific environment and requirements.