30 部署, 附游戏连结 (可以玩拉!)

什麽你不想部署,没关系我部署好了:

怎麽玩,复习一下规则

虽然规则简单,但里面没有指引与说明,没有看前面的朋友应该会满困惑的
这边就复习一下怎麽建立游戏跟游戏规则:

建立游戏:
按下 "Start a game" 後,下面有 "Copy to clipboard" 按钮可以复制连结,
再贴给朋友(如果你跟我一样没有朋友,可以开两个分页玩)
双方都按 "Yes" 後游戏开始

规则:
每场游戏有三回合,三战两胜
每回合出三张卡,三张卡点数加起来大的赢该回合,
"Rev" 卡是把该局获胜条件相反,可以叠加

游戏网址
http://card.weizheng.tw

原始码在这
https://github.com/weizhengliu/card

都有设计了当然还有部署

这边也是偷懒快的部署
如果要部署正式的东西建议不要用这个做法

开好机器後 开机器就不介绍了有点范围外
我是在 linode 开一台东京的服务器
作业系统这边用 ubuntu 20.04 LTS 使用者直接用 root

在部署之前有几个东西要改

  1. config/prod.exs 档案里面 他有预设的网址 example.com,必须要是部署後的网址,还没有就先填会连的 ip
  2. config/runtime.exs 的第 38 行 config :card, CardWeb.Endpoint, server: true 要把他取消注解

安装 erlang

wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add -
echo "deb https://packages.erlang-solutions.com/ubuntu focal contrib" | sudo tee /etc/apt/sources.list.d/erlang-solution.list
sudo apt update
sudo apt install esl-erlang

安装 elixir

sudo apt install elixir

安装 nodejs

这个是从这个说明 偷的
也可以用其他方式装, 只要是 tailwind 需要的 12.13.0 以上就好
我这边装最新的16

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

从 github clone 专案

git clone [email protected]:weizhengliu/card.git

cd card

安装套件 与 compile

mix deps.get --only prod
MIX_ENV=prod mix compile

产生 SECRET KEY BASE

在专案根目录执行

mix phx.gen.secret

就会发给我们一段 key
待会把他设定成环境变数

设定环境变数

我们把 port 直接指向 80

export SECRET_KEY_BASE=刚刚产生的很长的key
export PORT=80

准备前端 assets

MIX_ENV=prod mix setup
MIX_ENV=prod mix assets.deploy

发行 release

MIX_ENV=prod mix release

他会显示

root@localhost:~/card# MIX_ENV=prod mix release
* assembling card-0.1.0 on MIX_ENV=prod
* using config/runtime.exs to configure the release at runtime
* skipping elixir.bat for windows (bin/elixir.bat not found in the Elixir installation)
* skipping iex.bat for windows (bin/iex.bat not found in the Elixir installation)

Release created at _build/prod/rel/card!

    # To start your system
    _build/prod/rel/card/bin/card start

Once the release is running:

    # To connect to it remotely
    _build/prod/rel/card/bin/card remote

    # To stop it gracefully (you may also send SIGINT/SIGTERM)
    _build/prod/rel/card/bin/card stop

To list all commands:

    _build/prod/rel/card/bin/card

启动

他们所有东西都打包发行成 release 到 _build/prod/rel/card
我们照他讲的执行 _build/prod/rel/card/bin/card 来列出所有选项

root@localhost:~/card# _build/prod/rel/card/bin/card
Usage: card COMMAND [ARGS]

The known commands are:

    start          Starts the system
    start_iex      Starts the system with IEx attached
    daemon         Starts the system as a daemon
    daemon_iex     Starts the system as a daemon with IEx attached
    eval "EXPR"    Executes the given expression on a new, non-booted system
    rpc "EXPR"     Executes the given expression remotely on the running system
    remote         Connects to the running system via a remote shell
    restart        Restarts the running system via a remote command
    stop           Stops the running system via a remote command
    pid            Prints the operating system PID of the running system via a remote command
    version        Prints the release name and version to be booted

可以直接用 _build/prod/rel/card/bin/card start 来启动看看
就好了,网页也连得上了,但是这样要终端机一直挂着。
先 control + d 两次退出

所以我们这次要用的是 _build/prod/rel/card/bin/card daemon
他就会跑在背景了,我们也可以离开服务器

下次上来要关掉服务器也只需要执行 _build/prod/rel/card/bin/card stop

全部完成了

我架的网址:
http://card.weizheng.tw
github repo
https://github.com/weizhengliu/card


<<:  Day29 React - Styled-Components

>>:  DAY29-EXCEL统计分析:回归分析实例

第 28 型 - 路由 (Router) - Resolve / 延迟载入 (Lazy Router)

上一篇利用路由机制传递参数来实作待办事项的编辑功能,除了透过网址路径来传递所需要的参数,还可以在路由...

standardize VS normalize

当我们想要把资料丢进model前,常常会需要把资料标准化,尤其是针对跟距离有关的模型(像是knn, ...

Day 17 「提枪上阵」在测试保护下重构出 State 设计模式

报告班长,图片截自网路 大家有听过「报告班长」吗?这部 1987 年的电影,当年推出後一炮而红,带...

IT铁人DAY 1-进入物件导向世界前的心理准备

  在开始之前,还是很惊讶自己有天可以在这里写文章,分享自身所学的IT技术,提供给大家参考。那其实我...