This paper describes the automatic construction process of a C++ program, which involves: 1. Making basic images suitable for C++ simple programs. 2. Compile, build, and publish using CICD. In this process, email notification is involved.
The example in this paper is of practical significance in simple applications, that is, heavy tools like Jenkins are not used. If we trust off-the-shelf free private services, we can migrate the automation work to the public network; otherwise, we can build local area network services or use public cloud to build.
Technical summary
- Download the original image
- In the container of the original image, add the necessary files, such as linkers, dynamic libraries
- Re-create the image and submit it to the remote repository.
- Different compilers depend on dynamic libraries, and the linker is different. It is recommended to mirror the library, and the host machine.
- Note: different programs depend on different dynamic libraries, which are used on the host
ldd
Command to view details.
To make the mirror
Download the original image
Note: the source code is C++, using C++11 features, select Alpine, its C library is not glibc. Select BusyBox 64. Execute directly on 64-bit systems:
docker pull busybox
Copy the code
You get a 64-bit version. Running the busybox.
docker run --name -it bar busybox sh
Copy the code
Copy files
Built on Ubuntu 1604 64bit. The subject program is:
ldd test
linux-vdso.so.1 => (0x00007ffe173f3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f506d62a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f506d2a8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f506cf9e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f506cd88000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f506c9be000)
/lib64/ld-linux-x86-64.so.2 (0x0000558004458000)
Copy the code
Container execution:
mkdir -p /lib64 /lib/x86_64-linux-gnu/ /usr/lib/gcc/x86_64-linux-gnu/5
date > /etc/version
Copy the code
Host machine execution:
2 bar:/lib64 docker cp /lib/x86_64-linux-gnu/ld-2.23.so bar:/lib/x86_64-linux-gnu/ docker cp /lib/x86_64-linux-gnu/libpthread.so.0 bar:/lib/x86_64-linux-gnu/ docker cp So bar:/lib/x86_64-linux-gnu/ docker cp-a /usr/lib/x86_64-linux-gnu/libstdc++.so.6 bar:/lib/x86_64-linux-gnu/ docker cp -a /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21 bar:/lib/x86_64-linux-gnu/ docker cp -a /lib/x86_64-linux-gnu/libm.so.6 Bar :/lib/x86_64-linux-gnu/ docker cp -a /lib/x86_64-linux-gnu/libm-2.23.so bar:/lib/x86_64-linux-gnu/ docker cp -a 6 bar:/lib/x86_64-linux-gnu/ libc.so.6 bar:/lib/x86_64-linux-gnu/ libc-2.23.so bar:/lib/x86_64-linux-gnu/ docker cp -a /lib/x86_64-linux-gnu/libgcc_s.so.1 bar:/lib/x86_64-linux-gnu/ docker cp -a /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so bar:/usr/lib/gcc/x86_64-linux-gnu/5/Copy the code
Recreate the base image on the host:
docker commit bar registry.cn-hangzhou.aliyuncs.com/latelee/busybox:rt64
Copy the code
Validation:
#A window:
docker run -it --rm --name footest registry.cn-hangzhou.aliyuncs.com/latelee/busybox:rt64 sh
#Two Windows:
docker cp test footest:/
#A window that is a container executes:
/test
Copy the code
After verification is correct, upload:
docker push registry.cn-hangzhou.aliyuncs.com/latelee/busybox:rt64
Copy the code
use
The image is based on the Ubuntu 16.04 64-bit runtime library, GCC version 5.4, because BusyBox does not come with the required dynamic libraries and linkers. When compiling C++ programs, it is best to use the same version of the compiler, and if you use a different version of the library, you may need to make an extra one. Of course, if it’s too much trouble, you can use an Ubuntu image, but it’s bulky, so there’s a trade-off.
After compiling, assuming you have obtained the test program, copy it to the image. Dockerfile can refer to the following contents:
From registry.cn-hangzhou.aliyuncs.com/latelee/busybox:rt64
LABEL maintainer="Late Lee"
COPY test /
COPY config.yaml /
CMD ["/test"]
Copy the code
Then make the image, upload it to the warehouse, and finish.
CICD configuration
The above steps can be automated. Host the C++ code on github, and use github’s own Actions to execute the CI script and complete the required operations in the script. The full script is as follows:
name: C/C++ CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: Ubuntu 16.04
steps:
- uses: actions/checkout@v2
- name: make
run: | make -C test/ -f Makefile_bin -j cp test/a.out test - name: ls
run: ls * -lh
- name: Publish to ali Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: registry.cn-hangzhou.aliyuncs.com/latelee/ci_test:latest
username: The ${{ secrets.DOCKER_USER }}
password: The ${{ secrets.DOCKER_PASSWORD }}
registry: registry.cn-hangzhou.aliyuncs.com
dockerfile: Dockerfile
Copy the code
Using ubuntu-16.04, use the official Actions /checkout to download the code, then compile it, and use the existing push solution elgohr/ publish-docker-github-Action to specify the repository name, address, account password, etc. When the code is submitted to the warehouse, it is automatically compiled, built and uploaded to ali Cloud warehouse. Note that for security reasons, the account and password use secrets, need to be set in the warehouse.
Engineering warehouse
Provide for subsequent collation.