As anyone who has used Netlify or Vercel knows, the experience of automatically triggering a build and updating it online can greatly improve development efficiency and reduce mental load
Similar experience can be easily obtained through Coding, and relevant practical configuration process is recorded in this paper
To prepare
Because Vue does SSR and needs to be deployed to multiple servers on the Intranet, Coding can send deployment tasks to multiple machines on the Intranet through bastion.
SPA applications can upload built resources to OSS or some other static service directly after the build is completed.
Open the team configuration page: https://${Team}.coding.net/cd-deck/admin/host-server/agents
Fortress mounting machine
Copy the command to install, after successful installation you can see added to the fortress.
The main unit
Select the fortress and add the internal IP address of the host to be deployed
Avoid close login
The fortress generates a public key
ssh-keygen
Copy the code
Copy the public key to the machine to be controlled to avoid secret login
Pub [email protected] ssh-copy-id -i ~/. SSH /id_rsa.pub [email protected]Copy the code
Build tasks
Open a project, project Settings turn on continuous integration and artifacts, and then add a build task.
After successfully installing the dependency BUID, the dist will be packaged and uploaded to the artifact library dist. Zip
Jenkinsfile
Pipeline {agent any stages {stage(' checkout ') {steps {checkout([$class: 'GitSCM', Branches: [[name: env.GIT_BUILD_REF]], userRemoteConfigs: [[ url: env.GIT_REPO_URL, credentialsId: Env. CREDENTIALS_ID]]])}} stage(' Custom build process ') {steps {echo 'custom build process start' sh 'NPM install -g CNPM --registry=https://registry.npm.taobao.org' sh 'cnpm install' sh 'npm run build' sh 'zip -r dist.zip dist/*' echo Steps {codingArtifactsGeneric(files: 'dist. Zip ', repoName: "${GENERIC_REPO_NAME}") } } } }Copy the code
Set the trigger rule of the build task to trigger when a new label is pushed
Create an
Open the team continuous deployment page https://${your team}.coding.net/cd-deck/app
Create an Application > Select a Host Group for Deployment
Choose Details > New Deployment Process
Configuration products Download > dist. Zip to the specified directory
Add a post-execute script > that will restart the NodeJS service
update.sh
BASE_FOLDER=$(dirname "$0")
cd $BASE_FOLDER
rm -rf ./dist
unzip dist.zip
forever stop server.js
forever start server.js
Copy the code
Configure health Probe > to check whether the service is running properly
Add trigger > Automatically triggers the deployment process when the artifact is updated
And finally the whole process
This way, when a new tag is pushed (manually, of course), the build task is triggered, and the artifact repository dist. Zip is updated to trigger the deployment process.
The deployment process downloads dist. Zip to the specified storage location in the host group list. Run the update.sh command to restart the Web service.
disadvantages
The current problems are as follows:
- The build is still a little slow
- Build tasks sometimes fail
But the overall is still very easy to use, compared with the previous update deployment, save a lot of mental burden, push just wait, during the can continue to touch the hh