Skip to content

Commit

Permalink
Update the TinaDocs for deployment on Alilibab Cloud Server (#2892)
Browse files Browse the repository at this point in the history
* Update the docs

* change style

* update content

* Apply suggestions from code review

Update the word use

Co-authored-by: Josh Berman [SSW] <[email protected]>

---------

Co-authored-by: Josh Berman [SSW] <[email protected]>
  • Loading branch information
ZenoWang1999 and joshbermanssw authored Feb 21, 2025
1 parent f0cffcd commit c53e1f7
Showing 1 changed file with 151 additions and 3 deletions.
154 changes: 151 additions & 3 deletions content/docs/tina-cloud/deployment-options/alibaba-cloud.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Deploying to Alibaba Cloud
last_edited: '2025-02-19T03:17:14.726Z'
last_edited: '2025-02-19T10:11:51.539Z'
next: content/docs/tina-cloud/api-versioning.mdx
previous: content/docs/tina-cloud/deployment-options/github-pages.mdx
---
Expand All @@ -9,7 +9,7 @@ Alibaba Cloud is the leading cloud service provider in China. Since China doesn'

## Alibaba Cloud Configuration

Alibaba Cloud offers a wide range of server options. We generally recommend using Elastic Compute Service (ECS) for TinaCMS project deployment. For detailed instructions on creating and configuring your server, please refer to the official Alibaba Cloud documentation: [https://www.alibabacloud.com/help/en/elastic-compute-service](https://www.alibabacloud.com/help/en/elastic-compute-service)
Alibaba Cloud offers a wide range of server options. We generally recommend using **Elastic Compute Service (ECS)** for TinaCMS project deployment. For detailed instructions on creating and configuring your server, please refer to the [Official Alibaba Cloud Documentation](https://www.alibabacloud.com/help/en/elastic-compute-service).

### Server Setup

Expand Down Expand Up @@ -37,7 +37,6 @@ Next, start Nginx and enable it to run on system boot:
systemctl start nginx # Start the Nginx service
systemctl enable nginx # Configure Nginx to start automatically on system boot
systemctl status nginx # Check the status of the Nginx service
```

#### Configure Nginx as a Reverse Proxy
Expand Down Expand Up @@ -76,3 +75,152 @@ Reload Nginx to apply the new configuration:
```
nginx -s reload
```

### Preparing for GitHub Actions Deployment

#### Create Deployment Directory

First, create a directory on your server where your Tina CMS project will be deployed:

```
mkdir -p /www/tinademo
cd /www/tinademo
```

#### Generate SSH Keys for GitHub Actions

Generate an SSH key pair on your Alibaba Cloud server:

```
ssh -keygen -t ed25519 -C "deploy-key"
# Press Enter to use the default path
# Leave the passphrase empty by pressing Enter
```

#### Add Public Key to Authorized Keys

Add the generated public key to the authorized\_keys file to allow GitHub Actions to authenticate:

```
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
```

## Configuring GitHub Secrets

After generating your SSH key, you'll need to add several secrets to your GitHub repository to enable secure deployment.

### Navigate to GitHub Secrets

1. GitHub repository → Settings
2. Secrets and variables → Actions
3. Click "New repository secret"

### Required GitHub Secrets

You'll need to configure the following secrets:

1. `SSH_PRIVATE_KEY` : The private key generated on your server
* View it using: `cat ~/.ssh/id_ed25519`
* Make sure to include the entire key, including the `-----BEGIN OPENSSH PRIVATE KEY----` and `-----END OPENSSH PRIVATE KEY-----`
2. `SERVER_HOST`: Your Alibaba Cloud server's IP address
* This is the public IP address of your ECS instance
3. `SERVER_USERNAME`: The username for connecting to your server
* Typically `root` or the user account you created on your ECS instance
4. `NEXT_PUBLIC_TINA_BRANCH`: The branch that Tina CMS should use for content
* Usually your main branch (e.g., `main` or `master`)
5. `NEXT_PUBLIC_TINA_CLIENT_ID`: Your TinaCloud client ID
* Find this in your TinaCloud dashboard under project settings
6. `TINA_TOKEN`: Your TinaCloud token for authentication
* Generate this from your TinaCloud dashboard under API Access

## Creating GitHub Actions Workflow

Create a new file in your repository at `.github/workflows/deploy.yml` with the following content:

```yaml
name: Deploy to Alibaba Cloud Server

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "22.14.0"

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install Dependencies
run: pnpm install

- name: Create .env file
run: |
cat > .env << EOL
NEXT_PUBLIC_TINA_CLIENT_ID=${{ secrets.NEXT_PUBLIC_TINA_CLIENT_ID }}
TINA_TOKEN=${{ secrets.TINA_TOKEN }}
NEXT_PUBLIC_TINA_BRANCH=${{ secrets.NEXT_PUBLIC_TINA_BRANCH }}
EOL
- name: Build
env:
NEXT_PUBLIC_TINA_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_TINA_CLIENT_ID }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
NEXT_PUBLIC_TINA_BRANCH: ${{ secrets.NEXT_PUBLIC_TINA_BRANCH }}
run: pnpm build

- name: Deploy to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ".next/,public/,package.json,pnpm-lock.yaml,.env,tina/,next.config.js,.tina/"
target: "/tina/tinademo/"
rm: true

- name: Execute Remote SSH Commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /tina/tinademo
pnpm install
pm2 delete tinademo || true
pm2 flush tinademo
NODE_ENV=production pm2 start "pnpm start" --name tinademo
```
## Configuring a Custom Domain
To use a custom domain with your TinaCMS project in China:
### Domain Setup
1. Purchase a domain from a Chinese provider (e.g. Alibaba Cloud, Tencent Cloud)
2. Add an A record pointing to your Alibaba Cloud server's IP address
3. Update your Nginx configuration:
```
server {
listen 80;
server_name yourdomain.cn;
# Rest of configuration
}
```

### ICP Filing

Remember that websites hosted in mainland China require ICP filing. Start this process through your domain provider or Alibaba Cloud.

0 comments on commit c53e1f7

Please sign in to comment.