CI/CD 代写|计算机代写

 Gitlab CI/CD 代写案例


Gitlab CI/CD assignment.

 

This assignment has three parts.

 

● The first part is to setup your own runner (which you should have already done)

● The second part is to create a pipeline job that runs on the dev branch. It will then create a table of contents, add the file to the repo, push the results back the prod branch in the git repository.

● The final part is to create a deployment job that will copy the html files over to your server on ceclnx01.

Step 1: Install runner

Follow the instructions to setup a runner for the project cse470gUID

 

Step 1a: Setup Branch

Create a new branch called html-dev.

To create a series of dummy files, run this script ONCE inside your working tree to create a series of HTML files in your branch. (you only need run this once)

 

Step 2:

Create a bash script that creates a single TableOfContents file that contains a list of all html files in the branch. The output should be a valid HTML5 file. See my example for what the output should look like. This file will be a single html file that contains a list of links to all html files in the branch.  Call this file makeTOC.sh.  Call the output toc.html.

 

 

Step 3:

 

Now create your pipeline code. This code will:

● run only on the html-dev branch

● The PIPELINE code will Checkout the dev branch and then create a new release branch (Called html-prod) FROM the dev branch.

○ It is important that all new work be done in the html-prod branch. If we modify the dev branch from the cicd script, this will then cause the pipeline to run again which will cause the cicd script to update the dev branch which will cause the pipeline to run which will cause the cicd script to update the dev branch which will…. You get the idea.

● In the html-prod branch:

● run the makeTOC.sh script

● commit and push the resulting toc.html file to the repo. (Again, pushing to the html-prod branch)

● Here is the issue.

○ In the runner, the pipeline checks out the project using the https protocol and a special token that is created by the pipeline.

○ This token provides READ ONLY access to the repository.  

○ In order to modify the repository you will need to replace this https remote (remote refers to the gitlab remote repository) with a ssh based remote that provides read and write access to the gitlab repository.  

○ However as you know using ssh to access the gitlab repository means the program needs to have access to your ssh key.  

○ Use the instructions in the module to understand how to inject your ssh private key into your pipeline.  

○ Once the private key is injected into the pipeline, then you can use the normal git commands to interact with working copy.  

○ The command to replace the remote is "git remote set-url origin <URL>"

 

Don't forget to use a before_script tag to add git (along with openssh-client and ssh-keygen and other needed packages) using the "apt install" statement.

 

Overview of Steps: (This is not complete list of steps, just major steps)

1. Create the bash script to create the file toc.html. This should create a valid html5 document that has links to all the html files in the repository.

2. Configure your ssh keys in both gitlab and in your pipeline

3. Create a build job that will

a. ONLY runs on the dev branch.

i. This is critical in that this job will be modifying the git repo. If you were to programmatically modify the dev branch then you create an infinite loop since this modification would trigger the pipeline to run.  This job must create a new branch called release and store the new toc file in the release branch. Since this job (the step 2 job) does not run on the release branch the pipeline will not be in an endless loop

b. change the git remote to use the git@... url

c. create a new branch called release from the dev branch

d. inside this new release branch run the script to create the toc.html file

e. commit and push the release branch.

i. Again, since we are pushing the release branch this pipeline job should not trigger.

f. Here is PART of my pipeline commands that I used to create a new, fresh release branch from the dev branch.

● - git checkout html-dev

● - git pull

● - (git push origin --delete html-prod || echo "OK")

● - (git branch -D html-prod || echo "ok")

● - git checkout -b html-prod

● In this I create a new, fresh release branch every time.  I put the command to delete the remote branch (git push origin --delete html-prod) in the parenthesis so that if the remote branch does not exist, then when the git push command fails, the overall command sequence does not fail (since echo always works).

Step 3:

Add a pipeline stage that will that will use scp to copy the html-prod branch files to ceclnx01. The destination on ceclnx01 should be ~/public_html/cse470g/cicd/

 

This assumes you still have the before_script tasks that install the needed files and the private keys.  The public key associated with the private key used in the pipeline needs to be installed in the authorized_keys file on ceclnx01.

 

In this job use scp to copy all the files from the release branch over to ceclnx01 to the directory public_html/cse470g/cicd

 

 

Submit to canvas two links:

1) a link to your gitlab repository

2) A link to the files on ceclnx01.

 

 

 

Note: You will get a ssh host key checking failed when using ssh to connect to gitlab. to fix this put these lines in your before_script pipeline

 

 - echo "Host *" > ~/.ssh/config

  - echo "StrictHostKeyChecking no" >> ~/.ssh/config

  - chmod 400 ~/.ssh/config

 

 


咨询 Alpha 小助手,获取更多课业帮助