Deployment
Deploying a ShopiFast App on Fly.io
This guide will walk you through the process of deploying shopifast on Fly.io, including setting up secrets, creating a Postgres database, and linking it to your app. We'll start by installing the Fly CLI and then proceed with the deployment steps.
1. Install the Fly CLI
Before you begin, you need to install the Fly CLI, which is used to interact with Fly.io services.
macOS (using Homebrew)
brew install flyctl
Linux or Windows
Download the appropriate binary for your operating system from the Fly.io releases page and follow the installation instructions. After installation, authenticate with Fly.io:
fly auth login
2. Initialize Your App for Fly.io
Navigate to your ShopiFast project directory and initialize it for Fly.io:
cd /path/to/your/shopifast-app
fly launch
During the initialization process, Fly.io will prompt you to:
- Choose an app name (or let Fly.io generate one for you).
- Select a primary region (e.g.,
cdg
for Paris). - Set up a Postgres database (you can do this later if you prefer).
3. Configure the fly.toml
File
After running fly launch
, a fly.toml
file will be created in your project directory. This file contains the configuration for your Fly.io app. Below is an example configuration for a ShopiFast app:
app = 'your-app-name'
primary_region = 'cdg'
[build]
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
# Environment variables
[env]
APP_NAME = "Your ShopiFast App
APP_ENV = "production
APP_URL = "https://your-app-name.fly.dev"
4. Set Secrets
Sensitive values, such as database credentials and API keys, should be set using the fly secrets set
command. For example:
fly secrets set APP_KEY=base64:your-shopifast-app-key
fly secrets set DB_PASSWORD=your-database-password
fly secrets set SHOPIFY_API_SECRET=your-shopify-secret
5. Create and Attach a Postgres Database
Fly.io makes it easy to create and attach a Postgres database to your app.
Create a Postgres Database
Run the following command to create a new Postgres database:
fly postgres create
During the creation process, you'll be prompted to:
- Choose a database name.
- Select a region (preferably the same as your app).
Attach the Database to Your App
Once the database is created, attach it to your app:
fly postgres attach --app your-app-name
This command will automatically set the DATABASE_URL
environment variable for your app.
6. Deploy Your App
Once everything is configured, deploy your app:
fly deploy
Fly.io will build and deploy your app. After deployment, your app will be accessible at https://your-app-name.fly.dev
.
7. Run Migrations and Other Commands
After deployment, you may need to run migrations or other Artisan commands. Use the fly ssh console
command to access your app's environment and run commands:
Laravel
Use the fly ssh console
command to access your app's environment and run Artisan commands:
fly ssh console
php artisan migrate
php artisan db:seed
Express
For Express, you can run migrations using npm
or yarn
. Access the app's environment and run:
fly ssh console
npm run migrate
npm run db:seed:prod
8. Monitor Your App
Fly.io provides built-in monitoring and logging. You can view logs and monitor your app's performance using the Fly CLI or the Fly.io dashboard.
View Logs
fly logs
Open the Fly.io Dashboard
fly dashboard
Conclusion
You’ve successfully deployed your app on Fly.io, set up a Postgres database, and configured secrets. Fly.io provides a robust platform for hosting applications with minimal setup. For more advanced configurations, refer to the Fly.io documentation.
Let me know if you need further assistance!