4.2 KiB
Mnemo Cards Deployment Guide
This guide describes how to deploy the Mnemo Cards project (Backend + Web App) using the CI/CD scripts.
Overview
The deployment strategy is designed to optimize resource usage:
- Backend: Built directly on the server (saves bandwidth, ensures environment compatibility).
- Web App: Built on the client (your machine), then static files are transferred to the server (saves server RAM).
Prerequisites
-
SSH Access: You must have SSH access to the server
147.45.152.129asroot.- Ensure your public SSH key is added to
~/.ssh/authorized_keyson the server. - You can verify access by running:
ssh root@147.45.152.129
- Ensure your public SSH key is added to
-
Flutter Installed: You need Flutter installed on your local machine to build the web app.
-
Rsync: Ensure
rsyncis installed on your local machine (usually pre-installed on macOS/Linux).
Project Structure
deploy_all.sh: Master script to trigger deployments.mnemo_cards_web_v2/deploy.sh: Script to build and deploy the web app.tools/deploy/backend/deploy_remote.sh: Script to trigger the backend build on the server.tools/deploy/web-app/config.sh: Configuration for web deployment (server IP, paths, ports).
Forgejo CI/CD Setup
The project includes a workflow .forgejo/workflows/deploy.yaml to automate deployment via Forgejo Actions.
Why SSH?
Even though Forgejo runs on the same server, the Actions runner usually executes jobs inside isolated Docker containers (like ubuntu-latest). To modify files or restart services on the host machine (the server itself), the runner needs to "break out" of the container. We use SSH for this because it's secure and standard.
Secrets Configuration
To enable the workflow, go to your repository on Forgejo: Settings -> Actions -> Secrets and add the following:
| Secret Name | Value | Description |
|---|---|---|
SSH_HOST |
147.45.152.129 |
The public IP of your server. |
SSH_USER |
root |
The user to log in as (must have permissions to restart services). |
SSH_KEY |
(Your Private Key) | The content of your private SSH key (e.g., ~/.ssh/id_rsa). |
Tip: You can generate a new key pair specifically for CI/CD if you prefer not to use your personal one:
ssh-keygen -t ed25519 -C "ci-cd"Then add the public key to~/.ssh/authorized_keyson the server.
Runner Installation (Reference)
The Forgejo runner (act_runner) has been installed on the server to execute the workflows.
- Service:
act_runner.service - User:
root(required for Docker/SSH access) - Config: Registered with tag
ubuntu-latestto match the workflow.
If you ever need to restart it:
systemctl restart act_runner
How to Deploy
Option 1: Via Forgejo UI (Recommended)
- Go to your repository in Forgejo.
- Click on the Actions tab.
- Select Deploy Mnemo Cards from the left sidebar.
- Click the Run workflow button (dropdown).
- Select the branch (usually
master) and click Run workflow.
Option 2: Via Command Line (Manual)
If you want to run scripts manually without Forgejo Actions:
Full Deployment (Backend + Web)
To deploy both the backend and the web application, run:
./deploy_all.sh
2. Web Only Deployment
If you only made changes to the frontend:
./deploy_all.sh --web-only
3. Backend Only Deployment
If you only made changes to the backend:
./deploy_all.sh --backend-only
Troubleshooting
- Permission Denied (SSH): Check your SSH keys. Ensure you can login to
root@147.45.152.129without a password prompt (using keys). - Build Failed (Web): Run
flutter doctorto ensure your local environment is correct. Try runningflutter build web --releasemanually inmnemo_cards_web_v2to see detailed errors. - Backend Not Restarting: SSH into the server and check logs:
journalctl -u mnemo_cards_server -f. - Port Conflicts: The web app is configured to talk to the API on port
8444(HTTPS). Ensure the backend is actually running on this port.
Configuration
To change server IP, ports, or paths, edit:
tools/deploy/web-app/config.shtools/deploy/backend/deploy_remote.sh