In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to deploy to a remote machine continuously with Gitlab-CI". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
SSH secret-free login
The essence of CI/CD is to script the way we manually integrate, copy and deploy, and the important posture of remote deployment is to require secret-free manipulation.
An account on the controlled machine trusts the gitlab-runner account on the CI machine.
First, execute su gitlab-runner to switch to the gitlab-runner account and use the ssh-keygen command to create the public key on your CI machine (master), and use ssh-keygen-t rsa to create it. The program will ask you to store the directory. If you do not need to modify it, you can directly enter the id_rsa.pub file under the ~ / .ssh directory to the controlled machine ~ / .ssh directory a few times, and then import the contents of the file to the master of ~ / .ssh file:
Scp / home/gitlab-runner/.ssh/id_rsa.pub * * @ 10.202.42.252:/home/***/.ssh/
Accused party:
Cat ~ / .ssh/id_rsa.pub > > ~ / .ssh/authorized_keys
Set permissions on the accused machine:
~ / .ssh permissions are set to 700; ~ / .ssh/authorized_keys permissions are set to 600
After that, the master CI machine will have the ability to log in to the remote machine without secret.
How to continue to deploy?
Continuous deployment using image tag: for gitlab project, just type out tag-- > execute build image Job (this time git tag is image tag)-> execute deployment Job, get git tag-- > deploy the tag image
The CI_COMMIT_REF_NAME variable gets The branch or tag name for which project is built to set image: ${DOCKER_REGISTRY} / eap/eap-front-end:$ {TAG} in docker-compose.yml, which is aware of the tag variable build_image:Front-end inserted at deployment time:
Stage: build_image
Script:
-docker build-t $DOCKER_REGISTRY_HOST/eap/eap-front-end:$CI_COMMIT_REF_NAME.
-docker login $DOCKER_REGISTRY_HOST-u $CI_REGISTRY_USER-p $CI_REGISTRY_PASSWORD
-docker push $DOCKER_REGISTRY_HOST/eap/eap-front-end:$CI_COMMIT_REF_NAME
Tags:
-my-tag
Only:
-tags
Deploy:alpha:
Stage: deploy
Variables:
Deploy_path: "/ home/eap/website"
Script:
-ssh-t * * @ 10.202.42.252 "cd $deploy_path & & export TAG=$CI_COMMIT_REF_NAME & & docker-compose-f docker-compose.yml pull & & docker-compose-f docker-compose.yml up-d"
Tags:
-my-tag
Only:
-tags
That's all for "how to deploy to a remote machine continuously with Gitlab-CI". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.