Deployment

ECS Server

  1. Clone the project code to the server

  2. Compile the code into a binary executable file

export GDD_ENV=prod && go build -o api cmd/main.go 
1
  1. Launch the executable file, it is recommended to use the screen command or pm2Open in new window. Here is an example using the screen command: first create a window with screen -S app, where the window name is app, then start the program with ./app. Use ctrl + a + d to exit the screen, and screen -r app to open the previously created app window to view the logs output in the command line terminal.

Tip

If you are using a Centos server, the installation command for screen is yum install -y screen.

To see a list of currently open windows, you can use the screen -ls command

➜  ~ screen -ls   
There is a screen on:
	16048.app	(Detached)
1 Socket in /var/run/screen/S-root.
1
2
3
4

If you want to delete the app window, you can first execute the command screen -r app to log in, then enter exit and press Enter, which will exit and delete the app window.

➜  ~ screen -r app
[screen is terminating]
➜  ~  
➜  ~ screen -ls   
No Sockets found in /var/run/screen/S-root.
1
2
3
4
5

For general daily development, knowing these few commands is usually sufficient.

Docker

You can directly use the Dockerfile generated by the go-doudou svc init command, or modify it according to the actual project requirements.

First, download dependencies to the vendor folder

go mod vendor
1

Then build the image

docker build -t myservice . 
1

Finally, execute the docker run command

docker run -it -d -p 6060:6060 myservice
1

Remember to change myservice to your own image name.

Kubernetes

go-doudou provides out-of-the-box support for k8s deployment.

  1. Execute the go-doudou svc push command to package the image and push it to a remote image repository, and finally generate two k8s deployment files, one for deploying stateless services and one for deploying stateful services.
go-doudou svc push --pre godoudou_ -r wubin1989
1

You can set the image name prefix through the --pre parameter. You need to change wubin1989 to your own remote image repository address.

Each time this command is executed, it will automatically update the version number of the image, with a naming rule of v + yyyyMMddHHmmss, and automatically update the image name in the k8s deployment file.

  1. Execute the go-doudou svc deploy command. This command by default uses the file with the _deployment.yaml suffix to deploy stateless services. You can set other k8s deployment file paths through the -k parameter.