Deploying Go Apps
Deploying Go Apps
The Go Deploy app builds a Go application from a website's folder and runs the binary as a systemd service, with your web server (Nginx, Apache2 or OpenLiteSpeed) in front of it as a reverse proxy. It can also deploy from a Git repository on every push and roll back to an earlier release.
Before you start
- Install Go Deploy from the Vinza Store. It is included with every paid plan; on the Free plan it is available per server. See Pricing.
- Install the Go toolchain yourself — the app does not install it. It looks for
goin/usr/local/go/bin,/usr/bin,/usr/local/binand/snap/bin, and warns when it is missing. Extracting the official release into/usr/local/goworks. - Deploying is an administrator task.
Step 1: Create the website
- Go to Server → Websites and create a website with the Go runtime.
- After saving you are taken straight to the Go Deploy page for that site. Later you reach it from the website's page: the Go Deploy card under Extensions (
/apps/go-deploy/?domain=<domain>).
Until the app is deployed, the site shows a holding page.
Step 2: Upload and build
Put your code (with go.mod) in the website's folder using Git Manager, the File Manager or SFTP. Your app must listen on the port in the PORT environment variable:
port := os.Getenv("PORT")
http.ListenAndServe("127.0.0.1:"+port, mux)On the Build tab the panel shows whether go.mod was found, the Go version and the binary. Press Build to run go mod download and go build -o vp-go-app as the site's Linux user.
Step 3: Deploy
- On Deployment check the Entry point / binary (detected for you; a subfolder such as
bin/serveris kept). - Leave the Port on auto to get a free port in the 8400–8499 range, or enter one from 1024 to 65535 that no other panel app uses.
- Press Preview service to see the systemd unit, then Deploy.
The unit is written to /etc/systemd/system/vp-go-<domain>.service (every character that is not a letter or digit becomes a dash), systemd is reloaded, and the service is enabled and restarted. The vhost is switched to proxy to it. If the service then fails to start, the result says so.
Running the app
- Start, Stop, Restart and Reload (which restarts the service) and Logs are on the deploy page.
- Edit settings re-opens the form; Save & re-deploy restarts the app. Tick Pick a new free port instead to change the port.
- Remove deletes the service, the web-server config, the environment file and the deploy state. Deleting the website removes its service too.
Configuration
Environment
Under Configuration → Environment press Add variable, then Save variables. Names use letters, digits and _ and cannot start with a digit; values cannot contain line breaks. PORT is set by the panel. Variables are stored in a file only the site's account can read, loaded by systemd, and passed to Git deploy builds. Values are hidden after saving. Tick Restart the app after saving to apply them at once.
Limits
Configuration → Limits sets Soft memory limit (MemoryHigh), Hard memory limit (MemoryMax; above it the app is killed and restarted, and GOMEMLIMIT is set to 90% of it), CPU (50% = half a core, 200% = two cores) and the Go GC target (%). Leave a field empty for no limit. If a systemd drop-in overrides these, the page warns you.
Static & Media
A Go app usually serves its own routes. Add aliases here only to let the web server serve static or uploaded folders directly, then press Save aliases. Keep Directory indexing (autoindex) off in production.
Deploy from Git
- On the Git tab enter the Repository URL and Branch, then Link repository. Use
https://for public repositories, orgit@host:owner/repo.gitwith the Deploy key for private ones (Generate deploy key; the key is shared with Git Manager). Credentials in the URL are not accepted. - Press Deploy now: the branch is fetched, the app folder is reset to it (local changes to tracked files are discarded), the app is built and restarted. Everything runs as the site's account, and the output goes to the Deploy log.
- For Push to deploy press Turn on and copy the Webhook URL and Secret (shown once) into GitHub, GitLab or Bitbucket. Unsigned requests and pushes to other branches are ignored.
Releases lists recent deploys. Roll back re-activates the binary kept for one of the last 5 successful releases and restarts the app; if that binary is gone, it is rebuilt from the commit.
If your app has queue workers run by Supervisor, turn on Restart after a deploy for them. A successful Go deploy then restarts them too. See Supervisor & Background Workers.
Troubleshooting
- Go not installed: install the toolchain and reload the page.
- 502 Bad Gateway: the app is not listening on
PORTon127.0.0.1, or it crashed — check Logs. - Deploy refused while a Git deploy of the app is running: wait for it to finish.
- The panel's health check flags any deployed Go app whose service is not active.