系列文章:这个系列已完结,如对您有帮助,求点赞收藏评论。
读者寄语:再小的帆,也能远航!

  1. 【k8s完整实战教程0】前言
  2. 【k8s完整实战教程1】源码管理-Coding
  3. 【k8s完整实战教程2】腾讯云搭建k8s托管集群
  4. 【k8s完整实战教程3】k8s集群部署kubesphere
  5. 【k8s完整实战教程4】使用kubesphere部署项目到k8s
  6. 【k8s完整实战教程5】网络服务配置(nodeport/loadbalancer/ingress)
  7. 【k8s完整实战教程6】完整实践-部署一个federated_download项目

Coding平台官方链接
拥有以下功能:
在这里插入图片描述
是一个比较好的管理工具,还可以以记录版本的形式写文档(非广子,coding官方看到可给我打钱)


废话不多说,主要有以下流程:(自己总结的,不喜勿喷,可选择自己喜欢的方式)

Coding创建代码仓库–>本地创建git代码仓库–>本地代码仓库克隆Coding代码仓库以进行关联–>本地代码仓库中进行开发–>本地推送到Coding仓库–>创建制品仓库–>Coding代码仓库构建计划制作镜像制品并推送到制品仓库

1 Coding创建代码仓库

有三种方式:

  1. 基于本地代码创建代码仓库
  2. 基于现有模板创建代码仓库
  3. 直接导入外部已有代码仓库

1.1 基于本地代码创建代码仓库

1 先创建一个代码仓库

.gitignore 文件的作用是忽略指定文件类型不进行推送,一般创建时需要添加此文件,但本次仅为测试,所以不设置这玩意儿。
在这里插入图片描述

2 本地拉取此远程仓库

我理解为本地与远程仓库关联起来了。

# 进入到一个新的目录下
17211@hqc MINGW64 /d/data/Git/git-learning
$ cd other-repo/

# 将远程仓库的文件克隆下来
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo (master)
$ git clone https://e.coding.net/hqc12/hqc/flask.git
Cloning into 'flask'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.

# 进入本地拉取的这个仓库
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo (master)
$ cd flask/

3 本地开发

直接在这个文件夹中添加文件,模拟本地开发文件

# 查看文件状态
# 可见添加了以下7个文件
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        Dockerfile
        Jenkinsfile
        app.py
        learn-git.txt
        readme.txt
        requirements.txt

no changes added to commit (use "git add" and/or "git commit -a")

4 跟踪并提交文件

# 跟踪所有文件,提交所有文件到暂存区
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git add .
warning: in the working copy of 'learn-git.txt', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it

# 提交文件
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git commit -m "add all the example flask files into my new_create repository"
[master 03dbc22] add all the example flask files into my new_create repository
 8 files changed, 200 insertions(+), 1 deletion(-)
 create mode 100644 .gitignore
 create mode 100644 Dockerfile
 create mode 100644 Jenkinsfile
 create mode 100644 app.py
 create mode 100644 learn-git.txt
 create mode 100644 readme.txt
 create mode 100644 requirements.txt

5 推送到远程仓库

# 推送到远程仓库
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git push
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 16 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 2.61 KiB | 1.30 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0), pack-reused 0
To https://e.coding.net/hqc12/hqc/flask.git
   43aef0c..03dbc22  master -> master

6 查看远程仓库

在这里插入图片描述

成功推送!

1.2 基于现有模板创建代码仓库

1 本地安装好Git并初始化git仓库

已完成

2 创建代码仓库

基于模板使用
在这里插入图片描述

3 推拉代码

在此操作中将会演示如何从远端仓库拉取代码 / 上传本地代码至远端仓库,助力你的代码上云之旅

3.1 拉取远程仓库代码

可能是访问代码仓库的权限问题,需要填写账户密码
在这里插入图片描述

克隆:
在这里插入图片描述

查看:拉取下来了
在这里插入图片描述

3.2 本地进行代码修改

在文件夹中新建 readme.txtlearn-git.txt文件,在其中一个文件中写入 I'm learning git.

3.3 跟踪文件(git add)

创建或修改文件后调用 git add 命令,将变更的文件添加至本地 Git 仓库的暂存区(Index Stage)。
追踪特定文件时的命令:
git add readme.txt
添加多个文件的命令:
git add readme.txt learn_git.txt
如果你想一次性跟踪所有文件,则可以直接在终端输入git add .
在这里插入图片描述

3.4 提交文件(git commit)

将拟提交的文件纳入暂存区后,运行 git commit 命令即可将文件正式提交至本地仓库,此命令将会一次性会提交暂存区中的所有文件:
git commit -m "wrote a readme and a learn_git file"
-m 后引号中的内容是你的提交说明,下面几行是终端的返回结果。养成每次提交文件时附上变更说明的习惯,以便清楚地把控提交了什么样的修改。
在这里插入图片描述

3.5 查看文件状态(git status)

不确定 Git 是否精准的追踪了修改过的文件?想再次确认文件处于哪种状态?使用 git status 命令查看文件状态。

# 当前仓库里任何文件都没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

# 修改一下文件
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ vim readme.txt

# 当文件有变更,但没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

# git add即可进行跟踪
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git add readme.txt
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it

# 提交到仓库
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git commit -m "wrote something in readme.txt"
[master cc16839] wrote something in readme.txt
 1 file changed, 1 insertion(+)

# 当文件已跟踪且已经提交到仓库时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

3.6 推送文件到远程仓库
在这里插入图片描述

查看:成功推送
在这里插入图片描述

3.7 本地拉取远程仓库最新代码

只需要在本地运行 git pull 命令即可使本地与远端保持代码同步

3.8 代码仓库中操作

可以在远程仓库中直接进行修改,增加文件、文件夹等操作,都会被版本记录下来。
在这里插入图片描述

1.3 直接导入外部已有代码仓库

1 先创建一个代码仓库

URL方式导入github的一个私有仓库:
在这里插入图片描述

私有仓库需要填写github的账号和密码
在这里插入图片描述

导入私有仓库时总是出现找不对账号密码
在这里插入图片描述

导入开源仓库是没问题的:
在这里插入图片描述

2 同步仓库

同步功能仅对开源仓库开放。这意味着与源仓库保持一致,将覆盖导入 CODING 仓库后做出的变更。你可以在仓库设置中修改同步频率或关闭自动同步功能。
在这里插入图片描述

当然,如果你想现在马上立刻就同步也可以点击强制同步按钮。
在这里插入图片描述

3 关联代码仓库

「关联仓库」功能本质上是将访问外部仓库的凭据“暂存”至 CODING,当你使用持续集成 / 部署时,能够直接调用第三方仓库作为代码源,而省去了频繁迁移的繁琐流程。
在这里插入图片描述

关联成功:
在这里插入图片描述

2 本地创建git代码仓库

安装好Git,类似以下操作就行,记得初始化本地git代码仓库

17211@hqc MINGW64 /d/data/Git
$ mkdir git-learning # 创建git学习文件夹

17211@hqc MINGW64 /d/data/Git
$ cd git-learning/ # 进入该文件夹

17211@hqc MINGW64 /d/data/Git/git-learning
$ mkdir git-repository # 创建一个新文件夹作为仓库

17211@hqc MINGW64 /d/data/Git/git-learning
$ cd  git-repository/ 

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository
$ git init # 初始化
Initialized empty Git repository in D:/data/Git/git-learning/git-repository/.git/

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ ls

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ ls -ah # .git文件时隐藏的,得使用这个命令才能看到
./  ../  .git/

3 本地代码仓库克隆Coding代码仓库以进行关联

1 克隆远程仓库代码

可能是访问代码仓库的权限问题,需要填写账户密码
在这里插入图片描述

克隆:
在这里插入图片描述

2 查看

在这里插入图片描述

其实这时已经将本地git仓库和coding仓库关联起来了,可以进行以后的开发推送工作了。

4 本地代码仓库中进行开发

1 本地开发demo

可以新建任何文件进行开发工作,打标签,提交,推送等

2 跟踪文件(git add)

创建或修改文件后调用 git add 命令,将变更的文件添加至本地 Git 仓库的暂存区(Index Stage)。
追踪特定文件时的命令:
git add readme.txt
添加多个文件的命令:
git add readme.txt learn_git.txt
如果你想一次性跟踪所有文件,则可以直接在终端输入git add .
在这里插入图片描述

3 提交文件(git commit)

将拟提交的文件纳入暂存区后,运行 git commit 命令即可将文件正式提交至本地仓库,此命令将会一次性会提交暂存区中的所有文件:
git commit -m "wrote a readme and a learn_git file"
-m 后引号中的内容是你的提交说明,下面几行是终端的返回结果。养成每次提交文件时附上变更说明的习惯,以便清楚地把控提交了什么样的修改。
在这里插入图片描述

4 查看文件状态(git status)

不确定 Git 是否精准的追踪了修改过的文件?想再次确认文件处于哪种状态?使用 git status 命令查看文件状态。

# 当前仓库里任何文件都没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

# 修改一下文件
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ vim readme.txt

# 当文件有变更,但没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

# git add即可进行跟踪
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git add readme.txt
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it

# 提交到仓库
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git commit -m "wrote something in readme.txt"
[master cc16839] wrote something in readme.txt
 1 file changed, 1 insertion(+)

# 当文件已跟踪且已经提交到仓库时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

5 推送文件到远程仓库

在这里插入图片描述

查看:成功推送
在这里插入图片描述

6 本地拉取远程仓库最新代码

只需要在本地运行 git pull 命令即可使本地与远端保持代码同步

7 代码仓库中操作

可以在远程仓库中直接进行修改,增加文件、文件夹等操作,都会被版本记录下来。
在这里插入图片描述

8 版本管理(打标签)

8.1 创建标签

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git branch
  dev
* master

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag v1.0 # 默认给当前分支的最新提交打标签

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git log --pretty=oneline --abbrev-commit # 查看日志,果然打上了标签
0ffd5e4 (HEAD -> master, tag: v1.0, origin/master) fix the conflict2
af66d7e (dev) work done
da2a463 merged fix bug 01
493cddf fix bug 01
59d2eb3 merge with no-ff
f4adb8a add message
33d8453 confilct fixed: and simple
f4d2054 & simple
7bcec3b AND simple
7fe8404 Creating a new branch is quick.
e83baf7 add distributed
9b5d254 write a readme file

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag v0.9 af66d7e # 之前版本的修改忘记打标签了,可以根据ID号再次打上

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -a v0.8 -m 'version 0.8 released' da2a463 # 还可以加入一些信息

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag # 查看现有的标签
v0.8
v0.9
v1.0

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git show v0.9 # 查看指定标签的信息
commit af66d7ebfe2e8fad2a4352e1feed90c51daf38b6 (tag: v0.9, dev)
Author: hqc <21120205@bjtu.edu.cn>
Date:   Mon Sep 26 11:55:12 2022 +0800

    work done

diff --git a/readme.txt b/readme.txt
index 881f8bd..82e9ee0 100644
--- a/readme.txt
+++ b/readme.txt
@@ -2,3 +2,4 @@ Git is a distributed version control system
 Creating a new branch is quick and simple.

 Add message 'No Fast Forward'.
+The work haven't been done.

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git log --pretty=oneline --abbrev-commit 
0ffd5e4 (HEAD -> master, tag: v1.0, origin/master) fix the conflict2
af66d7e (tag: v0.9, dev) work done
da2a463 (tag: v0.8) merged fix bug 01
493cddf fix bug 01
59d2eb3 merge with no-ff
f4adb8a add message
33d8453 confilct fixed: and simple
f4d2054 & simple
7bcec3b AND simple
7fe8404 Creating a new branch is quick.
e83baf7 add distributed
9b5d254 write a readme file

8.2 标签相关操作

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -d v0.8 # 删除本地打错的标签
Deleted tag 'v0.8' (was db889a4)

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin v1.0 # 将某个标签推送到远程
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lesserror/git-repository-lab.git
 * [new tag]         v1.0 -> v1.0

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin --tags # 一次性推送所有还没推送到远程的本地标签
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lesserror/git-repository-lab.git
 * [new tag]         v0.9 -> v0.9

# 远程标签删除需要以下两步
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -d v0.9 # 1 删除本地标签
Deleted tag 'v0.9' (was af66d7e)

17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin :refs/tags/v0.9 # 2 从远程删除
To github.com:lesserror/git-repository-lab.git
 - [deleted]         v0.9

5 本地推送到Coding仓库

git push就行
在这里插入图片描述

查看:成功推送
在这里插入图片描述

6 创建制品仓库

制品管理-制品仓库-创建制品仓库
在这里插入图片描述

其实就相当于一个镜像仓库,建完之后里面是空的
有一个操作指引
在这里插入图片描述

7 Coding代码仓库构建计划制作镜像制品并推送到制品仓库

将准备好的代码仓库构建到制品仓库

1 选择docker推送模板

在这里插入图片描述

模板中还有 推送并部署到kubernetes 这个模板,以后试试
在这里插入图片描述

2 配置相关信息

在这里插入图片描述

3 手动配置构建流程(jenkinsfile)

在这里插入图片描述

一些环境变量之类的配置,还不大懂,直接保存

4 立即构建

点击立即构建按钮会跳出下面这个:
在这里插入图片描述

这个版本可以自己修改,比如改成 v0.0.1

5 构建成功

在这里插入图片描述

制品已经推送到了制品仓库

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐