Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Revel deployment


May 15, 2021 Revel


Table of contents


Revel deployment profile

Several common deployment methods are:

  1. The code is compiled locally and then copied to run on the server
  2. Pull the code on the server and compile and run it
  3. Use Heroku for deployment

Use the command line to demonstrate an interactive deployment - web servers are typically run as daemons. Common tools are:

Locally compiled

The Go language environment does not need to be installed on the target machine. The Revel command-line tool package package commands for compiling and compressing applications, as follows:

# 本地测试运行
$ revel run import/path/to/app
.. 测试程序 ..

# 打包程序
$ revel package import/path/to/app
打包的文件准备好了: app.tar.gz

# 复制到目标机器
$ scp app.tar.gz target:/srv/

# 在目标机器上运行
$ ssh target
$ cd /srv/
$ tar xzvf app.tar.gz
$ bash run.sh

If your local machine has the same architecture as the target machine, there will be no problem. Otherwise, you need to refer to cross-compilation to build the program for the specified platform architecture.

Incremental deployment

Incremental deployment is supported because statically linked binary programs with full resource files can become quite large.

# 构建应用程序到一个临时目录
$ revel build import/path/to/app /tmp/app

# 将临时目录 Rsync 到服务器上的主目录
$ rsync -vaz --rsh="ssh" /tmp/app server

# 连接到服务器,并重新启动应用程序
...

Rsync supports ssh full replication. For example, here's a more complex operation:

# 一个使用自定义证书、登录名和目标目录的例子
$ rsync -vaz --rsh="ssh -i .ssh/go.pem" /tmp/myapp2 ubuntu@ec2-50-16-80-4.compute-1.amazonaws.com:~/rsync

Build on the server

This approach relies on your version control system to distribute and update code. Y ou need to install the Go language environment on the server. The benefit is that you avoid potential cross-compilation.

$ ssh server
... 安装Go语言环境 ...
... 配置存储库 ...

# 进入你的应用程序所在的目录 (GOPATH环境变量), 拉取代码, 并运行。
$ cd gocode/src/import/path/to/app
$ git pull
$ revel run import/path/to/app prod

Heroku

Revel maintains a Heroku Buildpack that allows code to be deployed with a single command, refer to the Read Me file usage instructions

Cross-compilation

In order to create a cross-compilation environment, we need to build from source code. R efer to Install Go from source code for more information. You must set the $PATH and $GOPATH environment variables correctly, otherwise, if there is already a binary Go language pack, you will get into a serious error.

When the Go compiler is installed successfully, a cross-compilation environment is established by specifying the GOOS and GOARCH target environments. Refer to the available environment variables for more information.

$ cd /path/to/goroot/src
$ GOOS=linux GOARCH=amd64 ./make.bash --no-clean
$ GOOS=windows GOARCH=386 ./make.bash --no-clean

Install Revel in a new environment, then set the target architecture and package the application.

$ GOOS=linux GOARCH=amd64 revel package import/path/to/app

The package is then copied to the target platform.