Deployment
ECS Server
Clone the project code to the server
Compile the code into a binary executable file
export GDD_ENV=prod && go build -o api cmd/main.go
- Launch the executable file, it is recommended to use the screen command or pm2. Here is an example using the screen command: first create a window with
screen -S app, where the window name isapp, then start the program with./app. Usectrl + a + dto exit the screen, andscreen -r appto 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.
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.
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
Then build the image
docker build -t myservice .
Finally, execute the docker run command
docker run -it -d -p 6060:6060 myservice
Remember to change myservice to your own image name.
Kubernetes
go-doudou provides out-of-the-box support for k8s deployment.
- Execute the
go-doudou svc pushcommand 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
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.
- Execute the
go-doudou svc deploycommand. This command by default uses the file with the_deployment.yamlsuffix to deploy stateless services. You can set other k8s deployment file paths through the-kparameter.
