edited deployment.md

This commit is contained in:
Philip Cheung 2024-11-30 13:26:24 +08:00
parent 9a8a102858
commit b84d9bda94
1 changed files with 15 additions and 95 deletions

View File

@ -1,4 +1,17 @@
# Public Traefik # Web Deployment
* DNS add cms, adminer, traefik, oneandallmusic.net
* Check the env file
* check the env file in frontend, VITE_IMAGE_URL is corrent
Using Services
* godaddy for domain
* google map
* cloudflare for dns nameserver and image storage(r2)
* hostinger for vps
## Public Traefik
Go to local usr/local/ Go to local usr/local/
@ -42,7 +55,7 @@ cd traefik-public
USERNAME=admin PASSWORD=Wingwingk3 DOMAIN=oneandallmusic.net EMAIL=oneandall.music@gmail.com HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD) docker compose -f docker-compose.traefik.yml up -d USERNAME=admin PASSWORD=Wingwingk3 DOMAIN=oneandallmusic.net EMAIL=oneandall.music@gmail.com HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD) docker compose -f docker-compose.traefik.yml up -d
``` ```
## Deploy the FastAPI Project ## Deploy Backend
Now that you have Traefik in place you can deploy your FastAPI project with Docker Compose. Now that you have Traefik in place you can deploy your FastAPI project with Docker Compose.
@ -120,99 +133,6 @@ You can have multiple environment deployments.
There are already two environments configured, `staging` and `production`. 🚀 There are already two environments configured, `staging` and `production`. 🚀
### Install GitHub Actions Runner
* On your remote server, if you are running as the `root` user, create a user for your GitHub Actions:
```bash
adduser github
```
* Add Docker permissions to the `github` user:
```bash
usermod -aG docker github
```
* Temporarily switch to the `github` user:
```bash
su - github
```
* Go to the `github` user's home directory:
```bash
cd
```
* [Install a GitHub Action self-hosted runner following the official guide](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners#adding-a-self-hosted-runner-to-a-repository).
* When asked about labels, add a label for the environment, e.g. `production`. You can also add labels later.
After installing, the guide would tell you to run a command to start the runner. Nevertheless, it would stop once you terminate that process or if your local connection to your server is lost.
To make sure it runs on startup and continues running, you can install it as a service. To do that, exit the `github` user and go back to the `root` user:
```bash
exit
```
After you do it, you would be on the `root` user again. And you will be on the previous directory, belonging to the `root` user.
* Go to the `actions-runner` directory inside of the `github` user's home directory:
```bash
cd /home/github/actions-runner
```
* Install the self-hosted runner as a service with the user `github`:
```bash
./svc.sh install github
```
* Start the service:
```bash
./svc.sh start
```
* Check the status of the service:
```bash
./svc.sh status
```
You can read more about it in the official guide: [Configuring the self-hosted runner application as a service](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service).
### Set Secrets
On your repository, configure secrets for the environment variables you need, the same ones described above, including `SECRET_KEY`, etc. Follow the [official GitHub guide for setting repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
The current Github Actions workflows expect these secrets:
* `DOMAIN_PRODUCTION`
* `DOMAIN_STAGING`
* `STACK_NAME_PRODUCTION`
* `STACK_NAME_STAGING`
* `EMAILS_FROM_EMAIL`
* `FIRST_SUPERUSER`
* `FIRST_SUPERUSER_PASSWORD`
* `POSTGRES_PASSWORD`
* `SECRET_KEY`
* `LATEST_CHANGES`
* `SMOKESHOW_AUTH_KEY`
## GitHub Action Deployment Workflows
There are GitHub Action workflows in the `.github/workflows` directory already configured for deploying to the environments (GitHub Actions runners with the labels):
* `staging`: after pushing (or merging) to the branch `master`.
* `production`: after publishing a release.
If you need to add extra environments you could use those as a starting point.
## URLs ## URLs
Replace `fastapi-project.example.com` with your domain. Replace `fastapi-project.example.com` with your domain.