Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The process of Image compilation in chaos-mesh Development

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Chaos-mesh development of the image compilation process, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Chaosmesh is a lightweight implementation of chaos engineering used in K8S environment, which supports the construction of a variety of chaotic scenarios. It can be deployed through the docker image, but if you want to modify / secondary development, its compilation is not very convenient (you may try..). So here, based on the official approach, it is split into several sub-steps:

The heaviest part is the first step.

And code-related is the second step.

The third step is to generate a deployable image

The following execution directories are all preceded by chaos-mesh/:

Docker environment golang development environment git clone https://github.com/pingcap/chaos-mesh compiles and generates image 1. Basic image

Split out, the basic image generation part is named as independent Dockerfile file: Dockerfile.buildbase

FROM golang:1.14.4-alpine3.12 AS build_baseARG HTTPS_PROXYARG HTTP_PROXYRUN apk add-- no-cache gcc gathers + make bash gitRUN apk add-- update nodejs yarn

It takes about 2 hours to execute the image to generate 2C8G, and the main time is the apk installation process.

Docker build-f Dockerfile.buildbase-t chaosmesh_buildbase:0.1.

Execution process output

Sending build context to Docker daemon 2.267MBStep 1 http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/ 5: FROM golang:1.14.4-alpine3.12 AS build_base-- > 3289bf11c284Step 2 http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/ 5: ARG HTTPS_PROXY-- > Using cache-- > b71cc9152dbaStep 3 ARG HTTP_PROXY 5: ARG HTTP_PROXY-- > Using cache-- > 00340bb53cfbStep 4 ARG HTTP_PROXY 5: RUN apk add-no-cache gcc Gmail + make bash git-> Running in 25a64b772133fetch ARG HTTP_PROXY APKINDEX.tar.gzfetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz(1/24) Installing ncurses-terminfo-base (6.2_p20200523-r0) (2) Installing ncurses-libs (6.2_p20200523-r0) (3) Installing readline (8.0.4-r0) (4) Installing bash (5.0.17-r0) Executing bash-5.0.17-r0.post-install (5) / 24) Installing libgcc (9.3.0-r2) (6) Installing libstdc++ (9.3.0-r2) (7) Installing binutils (2.34-r1) (8) Installing gmp (6.2.0-r0) (9) Installing isl (0.18-r0) (10) Installing libgomp (9.3.0-r2) (11) Installing libatomic (9.3.0-r2) (12) Installing libgphobos (9.3.0- R2) (13Unip 24) Installing mpfr4 (4.0.2-r4) (14Compare 24) Installing mpc1 (1.1.0-r1) (15pm 24) Installing gcc (9.3.0-r2) (16Compare 24) Installing musl-dev (1.1.24-r8) (17Compare 24) Installing libc-dev (0.7.2-r3) (18Compact 24) Installing Gmail + (9.3.0-r2) (19Compact 24) Installing nghttp2-libs (1.41.0-r0) (20 MiB in 24) Installing libcurl (7.69.1-r0) (21 4.3-r0 24) Installing expat (2.2.9-r1) (22 Executing busybox-1.31.1-r16.triggerOK 24) Installing pcre2 (10.35-r0) (23) Installing git (2.26.2-r0) (24) Installing make (4.3-r0) Executing busybox-1.31.1-r16.triggerOK: 218 MiB in 39 packagesRemoving intermediate container 25a64b772133-> 7b35c82ec76aStep 5 Accord 5: RUN apk add-- update nodejs yarn-- > Running in 9b8192793f49fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gzfetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz(1/5) Installing brotli-libs (1.0.7-r5) (2) Installing c-ares (1.16.1-r0) (3) Installing libuv (1.37.0-r0) (4) Installing nodejs (12) .17.0-R0) (5pm 5) Installing yarn (1.22.4-r0) Executing busybox-1.31.1-r16.triggerOK: 253 MiB in 44 packagesRemoving intermediate container 9b8192793f49-> 6ec726d66bc3Successfully built 6ec726d66bc3Successfully tagged chaosmesh_buildbase:0.1

Generate content

# docker images... chaosmesh_buildbase 0.1 6ec726d66bc3 45 seconds ago 625MB2. Image + code collection

Split out, the business image generation part is named as independent Dockerfile file: Dockerfile.buildbinary

New to FROM chaosmesh_buildbase:0.1 as build_baseENV GO111MODULE=onENV GOPROXY= https://goproxy.cn # to deal with package download failure WORKDIR / srcCOPY go.mod. Copy go.sum. Run go mod downloadFROM build_base AS binary_builderARG HTTPS_PROXYARG HTTP_PROXYARG UIARG SWAGGERCOPY. / srcWORKDIR / srcRUN make binary

It takes about half an hour to generate 2C8G by performing the image, and only 2 minutes for subsequent execution.

Docker build-f Dockerfile.buildbinary-t chaosmesh_my:0.1.

Execution process output

Sending build context to Docker daemon 2.268MBStep 1 https://goproxy.cn 15: FROM chaosmesh_buildbase:0.1 as build_base-- > 6ec726d66bc3Step 2 src 15: ENV GO111MODULE=on-- > Using cache-- > 77f7eb612c78Step 3 ENV GOPROXY= 15: ENV GOPROXY= src-- > Running in ff92b4113844Removing intermediate container ff92b4113844-- > faaa5e678ee0Step 4 src 15: WORKDIR / src-- > Running in e677d7457f11Removing intermediate container e677d7457f11-- > a919ebec1df6Step 5 faaa5e678ee0Step 15: COPY go.mod. -> 1651592cc8ebStep 6amp 15: COPY go.sum. -> 6a2c3e26a54aStep 7ARG HTTP_PROXY 15: RUN go mod download-- > Running in f7a15063e33aRemoving intermediate container f7a15063e33a-- > e406d3f23575Step 8Compare 15: FROM build_base AS binary_builder-- > e406d3f23575Step 9Compare 15: ARG HTTPS_PROXY-- > Running in 360b9686a970Removing intermediate container 360b9686a970-- > f7a35aac4e60Step 10Compare 15: ARG HTTP_PROXY-- > Running in 0d53c5bd7bb3Removing intermediate container 0d53c5bd7bb3-- > 242f81bdf7bcStep 11Compare 15: ARG UI-> Running in 9a8a3a6a3aeeRemoving intermediate container 9a8a3a6a3aee-- > 5ec849e5d942Step 12Compare 15: ARG SWAGGER-- -> Running in dd1f9766dfefRemoving intermediate container dd1f9766dfef-- > 646f623900e5Step 13 + 15: COPY. / src-- > 780dcca532a0Step 14 GOARCH= 15: WORKDIR / src-> Running in efe4967d715dRemoving intermediate container efe4967d715d-> 39b9806a50f9Step 15 Running in efe4967d715dRemoving intermediate container efe4967d715d 15: RUN make binary-> Running in ebf1e23916a0GO15VENDOREXPERIMENT= "1" CGO_ENABLED=0 GOOS= "GOARCH="go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5go: found sigs.k8s.io/controller-tools/cmd/controller-gen in sigs.k8s.io/controller-tools v0.2.5/go/bin/controller-gen object: HeaderFile=./hack/boilerplate/boilerplate.generatego.txt paths= "." GO15VENDOREXPERIMENT= "1" CGO_ENABLED=1 GOOS= "" GOARCH= "" go build-ldflags'- s-w-X 'github.com/pingcap/chaos-mesh/pkg/version.buildDate=2020-06-12T09Parade 08Z'-o bin/chaos-daemon. / cmd/chaos-daemon/main.goGO15VENDOREXPERIMENT= "1" CGO_ENABLED=0 GOOS= "GOARCH="go build-ldflags'- s-w-X 'github.com/pingcap/chaos" -mesh/pkg/version.buildDate=2020-06-12T09cmd/controller-manager/*.goGO15VENDOREXPERIMENT= "1" CGO_ENABLED=0 GOOS= "GOARCH="go build-ldflags'- s-w-X 'github.com/pingcap/chaos-mesh/pkg/version.buildDate=2020-06-12T09Partition 08CGO_ENABLED=0 GOOS= 50Z bin/chaosfs. / cmd/chaosfs/*.goGO15VENDOREXPERIMENT=" 1 "CGO_ENABLED=1 GOOS="GOARCH="go build-ldflags'" -s-w-X 'github.com/pingcap/chaos-mesh/pkg/version.buildDate=2020-06-12T09Parc 09Rose 02ZZ'-tags ""-o bin/chaos-dashboard cmd/chaos-dashboard/*.goRemoving intermediate container ebf1e23916a0-> 166906930d82Successfully built 166906930d82Successfully tagged chaosmesh_my:0.1

The image generated by the content is much larger, and there are several intermediate image files.

# docker images...chaosmesh_my 0.1 166906930d82 3 minutes ago 2.67GB f6e5468571fe 9 minutes ago 625MB 6255c2ee2630 20 minutes ago 625MBchaosmesh_buildbase 0.1 6ec726d66bc3 29 minutes ago 625MB

Compare the effect of the official installation image:

# docker images...pingcap/chaos-dashboard latest 763cddd4c303 23 hours ago 57.5MBpingcap/chaos-mesh latest 6e2777640799 42 hours ago 40.6MBpingcap/chaos-daemon Latest af1cb5058c1d 42 hours ago 59.7MB3. Business mirror image

Note: the main body of Dockerfile, from the. / images/ components / Dockerfile of the chaos-mesh project itself, modifies the COPY-from= binary source image.

Chaos-daemon

The business image is named as a separate Dockerfile file: Dockerfile.chaos-daemon

FROM alpine:3.10ARG HTTPS_PROXYARG HTTP_PROXYRUN apk add-- no-cache tzdata iptables ipset stress-ng iproute2COPY-- from=chaosmesh_my:0.1 / src/bin/chaos-daemon / usr/local/bin/chaos-daemon

Perform image generation

Docker build-f Dockerfile.chaos-daemon-t chaos-daemon:my.

Generate content

Chaos-daemon my 72f767fd07a3 15 seconds ago 59.7MBchaos-mesh

The business image is named as a separate Dockerfile file: Dockerfile.chaos-mesh

FROM alpine:3.10ARG HTTPS_PROXYARG HTTP_PROXYRUN apk add tzdata-- no-cacheCOPY-- from=chaosmesh_my:0.1 / src/bin/chaos-controller-manager / usr/local/bin/chaos-controller-manager

Perform image generation

Docker build-f Dockerfile.chaos-mesh-t chaos-mesh:my.

Generate content

Chaos-mesh my 36bf11bc3837 41 seconds ago 40.6MB extended contrast Mirror

The official image is self-generated by vs, which can be easily compared.

Docker history image ID-- no-trunc

Because the Dockerfile is the same, the difference is the binary file of the last copy

After reading the above, have you mastered the method of image compilation process in chaos-mesh development? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report