Intro
I'd just updated my blog's architecture yesterday, and when I woke up this morning, the server subscription had expired—the site was completely down, and I didn't even get an expiration reminder email.
I'd planned not to renew it after it expired, but once it expired, I couldn't connect to the server anymore, so I couldn't get the data out either. Fortunately, I'd gotten into the habit of backing up the data to OneDrive on a schedule; see this post for details.
The awkward part is that I'd only backed up the data, not the environment variables needed for deployment. That caused a few problems worth recording.
Backend Deployment
The deployment is the same as the previous deployment post. The only thing to watch out for—and the trouble I ran into this time—was writing the .env file. In ALLOWED_ORIGINS, just enter the domain name. Don't enter https://xxu.do.
JWT_SECRET=XXXXXX #随便填写,长度在 16-32 之间
ALLOWED_ORIGINS=xxu.do #这里需要注意的是,仅填写域名即可,不要填写 https://xxu.do,这会导致前端无法连接
ENCRYPT_ENABLE=false
ENCRYPT_KEY=
Frontend Deployment
This time I deployed using the GitHub Action that builds Shiroi and deploys it to a remote server, mainly following this post.
First, do the following on the server:
- Install
Nodejsandunzip
- Install
Node.js,npm,pnpm,pm2, andsharp
npm i -g sharp pm2 pnpm
- In your server's home directory, create a folder called
shiro, then create a.envfile and fill in your variables.
cd && mkdir shiro && cd $_
vi .env
- Then fill in the corresponding environment variables. For a single-domain setup, set
NEXT_PUBLIC_API_URLandNEXT_PUBLIC_GATEWAY_URLas shown below. You can create aGH_TOKENhere with thereposcope checked.
NEXT_PUBLIC_API_URL=http://localhost:2333
NEXT_PUBLIC_GATEWAY_URL=http://localhost:2333
TMDB_API_KEY=
GH_TOKEN=
- After forking the project, add the following under
Settings -> Secrets and variables -> Actions -> Repository secrets:
HOST— server addressUSER— server usernamePASSWORD— server passwordPORT— server SSH portKEY— server SSH key (optional; use either the password or the key)GH_PAT— a GitHub token with access to the Shiroi repository
GH_PAT can be the same as the GH_TOKEN above.
In the Actions tab of the forked repo, enable the workflow. After making any change to the
build_hashfile, the workflow will trigger. If it runs successfully, check/root/shiroon your server to see whether the built files are there. The first run failed for me; it turned out pm2 wasn't installed—just for reference.For scheduled runs: in your forked GitHub repo, edit
.github/workflows/deploy.ymland uncomment theschedule:and-corn: '0 3 * * *'lines.
Nginx Reverse Proxy
A single-domain example:
Outro
Switching to this new frontend deployment method did solve the high memory usage problem.
There's also a lesson here: always back up your .env files. That will save you a lot of trouble when you need to redeploy.