This is the fourth day of my participation in Gwen Challenge

Set up the warehouse

Set the SSH key

Push the project

Code review

According to the menu

Build to compile

Do not use a template. Select Create image and push SWR repository to create an image. After the image is created, it will be automatically uploaded to the image repository

The contents of the Dockerfile required for this build are as follows:

# base mirror FROM Python:3.68.# MAINTAINER information MAINTAINER WangScaler@163.Com # ADD code to code folder ADD / /wangscaler # Set up code folder is the working directory WORKDIR /wangscaler # install support RUN CD /wangscaler && ls RUN ls RUN PIP  install --user -r /wangscaler/requirements.txt -i https://pypi.doubanio.com/simple/# RUN python createlicens.py to compile your own script02:42:ad:12:01:02Py RUN python -m compileall -b build/ # RUN PWD && ls CMD ["python"."build/server.pyc"]
Copy the code

The deployment of

Configure password login on the deployed machine

Gets a long-running Docker Login directive

steps

Obtain the mirror warehouse access address and area project name.

Log in to the administrative console, click your username in the upper right corner, and click My Credentials.

In the list of items in API Credentials, look for the item corresponding to the current zone.

As shown in the figure below, the corresponding project of “Huabei-Beijing I” is “CN-North-1”.

The IP address of the mirror depot is SWR. Area project name myHuaweicloud.com, for example, the IP address of the mirror depot of North China Ranger 1 is swr.cn-1.Myhuaweicloud.com.

Obtain the AK/SK access key.

  • The Access Key is Access Key ID/Secret Access Key (AK/SK). It is a group of Key pairs used to verify the identity of the visitor who invokes the API to initiate a request. The function is similar to that of a password. If you have an AK/SK, you can use it without obtaining it again.

Log in to the administrative console, click your username in the upper right corner, and click My Credentials. In the navigation tree on the left, choose Access Key and click Add Access Key. Enter the login password of the current user and verify the password through email or mobile phone.

  • Note: If an email address or mobile phone number is not specified when a user is created in the unified identity authentication service, the user only needs to verify the login password.

Click OK to download the access key, which contains AK and SK.

  • Note: To prevent access key leakage, you are advised to save it in a secure location.

Log in to a Linux computer and run the following command to obtain the login key.

printf "*$AK*" | openssl dgst -binary -sha256 -hmac "*$SK*" | od -An -vtx1 | sed 's/[ \n]//g' | sed 'N; s/\n//'
Copy the code

AK and AK and AK and SK are the AK/SK obtained by 2.

Concatenate the Docker login directive using the following format.

Docker login -u [domain name]@[AK] -p [login key]Copy the code

In the command output, the area project name and mirror warehouse address are obtained from 1, AK is obtained from 2, and the login key is 3.

Conclusion:

Generate login keys on centos based on AK and SK

printf "NO2PHzzzzSPCX" | openssl dgst -binary -sha256 -hmac "IJVZuW2zzzzzSlFNZFt7LjhtA3" | od -An -vtx1 | sed 's/[ \n]//g' | sed 'N; s/\n//'
Copy the code

The login

docker login -u cn-north-4@NO2PHzzzzSPCX -p 15489d25d17222222222222727c45ebb17262ba0e3xxxxxxxxxxeb69415b914a48eb7 swr.cn-north-4.myhuaweicloud.com
Copy the code

Pull the mirror

// All addresses are false
docker pull swr.cn-north-4.myhuaweicloud.com/xxx/xxx:v11.
Copy the code

The deployment of the mirror

Stop the containers that already exist on the deployment machine

Delete an existing container on the deployment machine

Delete an existing image from the deployment machine

Logging In to the Image Repository

Pull the mirror

Run the mirror

Build a continuous delivery pipeline

Automate code inspection, build the project image, publish to the repository, pull the image on the deployment machine, and run the project image

Preset pipeline task Mission statement
Code review Basic assembly line tasks.
Dockefile Build the docker image pipeline task.
The deployment of the mirror Deploy to assembly line tasks on production machines.

Description:

For details about vote, result, and worker, see HE2E DevOps practice flow.

Configure pipelining to chain code reviews, compile build, and automate deployment steps

  • Create and trigger a continuous delivery pipeline
  1. To access the project, click the navigation in the upper part of the page

    Build & Publish > Pipeline

    , into the assembly line service.

    Click New Pipeline and configure the pipeline according to the following table.

    steps Fill in/select suggestions
    The basic information Pipeline name: Code review
    Select a template Create a vm directly without using a template
    Select code source DevCloud source repository: Ziot
  2. Click the icon to delete stage “Publish repository”, click the icon) add “Custom Stage”.

  3. Click the iconIn the right slider box, enter the name Code Check and click Save.

  4. Click Please select a subtask in the phase Code Review.

  5. In the right slider box, select “Code Check” for type, select “XXX” for task, and click “Save”.

In the same way, add the build task “Build Image”. “Compile build” in phase

Build a Docker image and publish it to the mirror repository.

8. After the build phase, add Deployment, add deployment image in this phase, and click Save.

The Pipeline Details page is displayed. Click New Execution to start the pipeline.

The task is successfully executed if the following page is displayed: If the task fails to be executed, check the cause of the failure at the location where the task fails to be executed (for example, if the task fails to be executed in the deployment phase, enter the deployment task and view the deployment logs. For details, see 6 to find the cause of the failure), or refer to the common faults in the Pipeline-Help document.

  • Add quality access control

1. Go to the Pipeline Configuration page of Phoenix-sample-Pipeline task.

2. Click Quality Access Control In Phase Code Check.

In the right pane, click Click Create. Enter CodeCheck access control in the dialog box, turn on CodeCheck problems, set threshold 5, and click save.

3. Select the newly created Code Check Access control from the Access drop-down list and click Save.

4. Save the assembly line and return to the assembly Line Details page. Start the pipelining task, and when the task is executed, it can be seen that the number of code check problems is more than 5, so the pipelining task fails to be executed.

5. Click Configure, change the threshold of Code Check access Control to 15, save the pipeline, and execute the operation. After the task is executed, it can be seen that the pipeline task is successfully executed because the number of code check problems is less than 15.

Update pipeline configuration for continuous delivery pipeline triggered by code changes

Enter the project and click Build & Publish > Pipeline to enter the pipeline service.

Locate the pipeline task “Phoenix-sample-Pipeline” and click the icon in the operation column corresponding to this taskThe Pipeline Configuration page is displayed.

Click the Triggers TAB, select the required branch from the Trigger Branch drop-down list, and click Save.

When the setup is complete, this task is automatically triggered when a code change is committed for the selected branch.

Pipeline configuration advanced functions

Add human audit

DevCloud supports the addition of human audit Settings in pipeline tasks. When a task is completed in a certain stage, it needs human audit to continue.

1. Go to the Pipeline Configuration page of Phoenix-sample-Pipeline task.

2. In Deployment, click Add Task.

In the right slider box, select the type “Pipeline Control”, select “Manual audit”, and select the required auditor in the “Auditor” drop-down list.

The instructions on the page are as follows:

parameter instructions
The reviewer You can set one or more reviewers.
Audit mode All audit means that all must pass any audit to continue, and any audit means that the audit task can continue with any one of the audit list.
The audit time Set the validity period of the audit, the audit is invalid after the overdue, can not be audited.
note Review instructions.

3. Return to the Pipeline Configuration page, drag the task Pipeline Control to the top of Task Deployment, and click Save.

4. Start the assembly line. When “Manual audit” is executed, a pop-up box on the page will indicate that the task needs to be audited.

5, audit personnel into the assembly line tasks

“Phoenix – sample – pipeline”

Details of the page

Click Approve, and the pipeline automatically continues. Click Reject to stop the pipeline.