CI/CD pipeline actual combat

I don't know why, but now I want to learn any technology, because I feel that I have encountered a technical barrier, and I can't get in touch with big projects, and the projects I do are not a word 辣*. Therefore, the whole heart is impetuous, and I have to relieve this impetuousness through daily cycling and long-distance running. One weekend, I stayed at home again and studied a bit CICD.

First share shigenthe learning video resources: CICD pipeline actual combat

git

Distributed version controller. gitlabPrivate warehouses can be created, and githubprivate warehouses require a fee.

SVN is not recommended! Instead of spraying it, technological innovation, new technology will solve various problems of old technology.

Due to its centralized architecture, poor support for offline work, complex branching and merging, and lack of modern features, SVN is no longer recommended as a primary version control system. At present, Git has become a widely used distributed version control system, and it has more powerful functions and better performance. ——Summary from chatGPT

git principle

No matter how many concepts there are, there is no real and clear picture:

git configuration

~/.gitconfigThe global configuration of git will be saved, and the information of git users can be modified here, such as name email.

cat ~/.gitconfig

git in the project

.gitThere will also be a folder under the root path of the project , and there is also a configfile inside, which stores the current project configuration.

View configuration information

git config --list

set up

Usually used for configuration name email.

git config set name=shigen

View branches and commits

I configured it locally gitlog, and the specific configuration shigenis shared below.

gitlog='git log --graph --abbrev-commit --decorate --format=format:'\''%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'\'\''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'\'' --all'

Execute the command, that's it, isn't it very clear:

shigenmore recommended tig. Execute directly on the mac brew install tig.

The effect is very cool and friendly, and you can view the file changes directly on the console.

Commonly used commands

Although image-based operating tools such as idea ugitthe ones I often use can well meet daily needs, but: the underlying principles still need to be understood. Think about it, what if there are only terminal operations.

  • initialization
git init
  • file added to staging
git add xxx
  • submit
git commit -m 'msg'
  • view log
git log
  • Staging area status
git status
  • The difference between the current file and the last commit
git diff
  • back to a version
git reset --hard xxxx
  • Push from local to master branch

In general companies, masterbranches are not allowed to directly pushcode, here is just an example.

git push -u origin master

gitlab

Install

It is found that there will be problems with direct installation, such as: the mirror source cannot be found. Try to use dockerthe installation, found that the memory of the cloud server is not enough, the installation script is as follows:

mkdir -p etc/gitlab var/log/gitlab /var/opt/gitlab 
docker run -d -p 81:80 -p 10011:443 -p 10012:22  \
    --restart no \
    --name gitlab \
    -v $PWD/etc/gitlab:/etc/gitlab \
    -v $PWD/var/log/gitlab:/var/log/gitlab \
    -v $PWD/var/opt/gitlab:/var/opt/gitlab \
    --privileged=true \
    gitlab/gitlab-ce

echo '访问81端口'

Reference article: Gitlab----Using Docker to install and deploy Gitlab

If you are interested, you can take a look at how to install it on the computer with the M1 chip: How to build gitlab on the M1 Mac

Features: add users, use mailboxes, code merge

Nexus3

mavenwarehouse, private server. Download, unzip, and start directly. Similar to docker harbor.

jenkins

  • automatic build
  • Easy to install and configure
  • Distributed construction, multiple computers build together
  • Many plugins supported

Containerized CI/CD process

本地代码---git---jenkins---harbor----docker(k8s)

deploy

Reference article: Mac M1 deploys Jenkins

brew install jenkins-lts
brew services restart jenkins-lts 
open 127.0.0.1:8080

Obtained jenkinsdefault password:

cat /Users/xxxx/.jenkins/secrets/initialAdminPassword

Follow the tutorial to download the recommended plugins, create an account, and use the default URLone.

configuration

  • Chinese configuration

Reference article: jenkins setting Chinese

  • Configuration of global tools

Java path:

/opt/homebrew/opt/openjdk@17/bin
  • The division of permissions requires the use of plug-ins
  • Deployment process recommended article: Mac M1 deploys jenkins

Create a new project locally and upload it to gitee

git commit -m "first commit"
git remote add origin https://gitee.com/shigen/wx-develop.git
git push -u origin "master"

Create a new project in jenkinsthe project panel. For the specific process, see: jenkins+gitee realizes automatic code deployment

In the implementation part of the script, I wrote one by hand and uploaded it to my own harbor. This is only used as a test, and the specific actual development and application scenarios are similar.

The first thing you need to know is the location of the code I pulled. shigenThe location on the computer is like this:

/Users/xxxx/.jenkins/workspace/wx-develop

shell script

shigenThe script is like this. The first is to mavencompile and package the code, and then use dockerthe jar of the java service to be packaged into the container, and the generated container is pushed to harborrun locally.

#!/bin/bash
# jenkins shell script to deploy the java project

echo '------start deployment--------'
echo "java -version && mvn -version"

mvn clean install -DskipTests

DATE="$(date +%y%m%d-%H%M%S)"
APP_NAME="wx-xxxxx"
APP_PORT="80"
HARBOR_DOMIAN="xxxxxxxx"

TAG="$APP_NAME:$DATE"
docker build -t $TAG -f Dockerfile .

docker login $HARBOR_DOMIAN

NEW_TAG="$HARBOR_DOMIAN/xxxx/$TAG"
docker tag $TAG $NEW_TAG
docker push $NEW_TAG
echo "$TAG uploaded successfully"

docker run -d --name $APP_NAME-$DATE -p $APP_PORT:$APP_PORT $NEW_TAG

echo "Successfully started"

The specific configuration is as follows:

Click and build nowa new task will appear:

The specific log is as follows:

harborThis service and mirror do exist locally and online, so no further verification will be done here.

Finally, to summarize jenkinsthe steps of the automated process:

pipline pipeline

Reference article: pipeline pipeline

The above is shigenthe result of learning in the past few days, CICDall about the actual combat of the assembly line. It will be overcome in the later stage k8s, and I look forward to sharing it with you further.

Guess you like

Origin blog.csdn.net/weixin_55768452/article/details/132306842