Skip to content

Commit

Permalink
chore: use buildx to build docker images in e2e (dragonflyoss#1018)
Browse files Browse the repository at this point in the history
* chore: build images concurrency

Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma authored Jan 25, 2022
1 parent 5c2f52e commit 6d11481
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 14 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/compatibility-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ jobs:
mkdir -p /tmp/artifact
go mod vendor
- name: Setup buildx
uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true

- name: Setup Kind
uses: engineerd/[email protected]
with:
Expand All @@ -53,11 +59,9 @@ jobs:

- name: Build images
run: |
hack/gen-buildx.sh
make docker-build docker-build-testing-tools
docker pull dragonflyoss/${{ matrix.module }}:${{ env.DRAGONFLY_STABLE_IMAGE_TAG }}
- name: Prepare kind environment
run: |
make kind-load
kind load docker-image dragonflyoss/${{ matrix.module }}:${{ env.DRAGONFLY_STABLE_IMAGE_TAG }}
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ jobs:
go mod download github.com/go-task/slim-sprig
go install github.com/onsi/ginkgo/v2/[email protected]
mkdir -p /tmp/artifact
go mod vendor
- name: Setup buildx
uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true

- name: Setup Kind
uses: engineerd/[email protected]
Expand All @@ -47,10 +52,10 @@ jobs:
config: ${{ env.KIND_CONFIG_PATH }}

- name: Build images
run: make docker-build docker-build-testing-tools

- name: Prepare kind environment
run: make kind-load
run: |
hack/gen-buildx.sh
make docker-build docker-build-testing-tools
make kind-load
- name: Setup dragonfly
run: |
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ build-manager: build-dirs
./hack/build.sh manager
.PHONY: build-manager

# Build manager console
build-manager-console: build-dirs
@echo "Begin to build manager."
./hack/build.sh manager-console
.PHONY: build-manager-console

# Install cdn
install-cdn:
@echo "Begin to install cdn."
Expand Down Expand Up @@ -304,6 +310,7 @@ help:
@echo "make build-dfget-linux build linux dfget"
@echo "make build-scheduler build scheduler"
@echo "make build-manager build manager"
@echo "make build-manager-console build manager console"
@echo "make install-cdn install CDN"
@echo "make install-dfget install dfget"
@echo "make install-scheduler install scheduler"
Expand Down
11 changes: 9 additions & 2 deletions build/images/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
### Build Base Image

```shell
BASE_IMAGE=dragonflyoss/base:bpftrace-v0.13.0-go-v1.16.6
docker build -t dragonflyoss/base:bpftrace-v0.13.0-go-v1.17.4 -f Dockerfile .
```

### Run Debug Container

```shell
BASE_IMAGE=dragonflyoss/base:bpftrace-v0.13.0-go-v1.17.4

# run debug container
docker run -ti -v /usr/src:/usr/src:ro \
-v /lib/modules/:/lib/modules:ro \
-v /sys/kernel/debug/:/sys/kernel/debug:rw \
Expand All @@ -22,7 +29,7 @@ export GOTAGS="debug"
# gcflags for dlv
export GOGCFLAGS="all=-N -l"
# base image
export BASE_IMAGE=dragonflyoss/base:bpftrace-v0.13.0-go-v1.16.6
export BASE_IMAGE=dragonflyoss/base:bpftrace-v0.13.0-go-v1.17.4

make docker-build
```
Expand Down
3 changes: 2 additions & 1 deletion client/daemon/peer/peertask_piecetask_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ retry:
ptc.Debugf("try get piece task from peer %s, piece num: %d, limit: %d\"", peer.PeerId, request.StartNum, request.Limit)
p, err := poller.getPieceTasksByPeer(span, curPeerPacket, peer, request)
if err == nil {
ptc.Infof("got piece task from peer %s ok, pieces length: %d, totalPiece: %d", peer.PeerId, len(p.PieceInfos), p.TotalPiece)
ptc.Infof("got piece task from peer %s ok, pieces length: %d, totalPiece: %d, content length: %d, piece md5 sign: %s",
peer.PeerId, len(p.PieceInfos), p.TotalPiece, p.ContentLength, p.PieceMd5Sign)
span.SetAttributes(config.AttributeGetPieceCount.Int(len(p.PieceInfos)))
return p, nil
}
Expand Down
2 changes: 1 addition & 1 deletion client/daemon/storage/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (t *localTaskStore) UpdateTask(ctx context.Context, req *UpdateTaskRequest)
t.TotalPieces = req.TotalPieces
t.Debugf("update total pieces: %d", t.TotalPieces)
}
if len(t.PieceMd5Sign) == 0 {
if len(t.PieceMd5Sign) == 0 && len(req.PieceMd5Sign) > 0 {
t.PieceMd5Sign = req.PieceMd5Sign
t.Debugf("update piece md5 sign: %s", t.PieceMd5Sign)
}
Expand Down
14 changes: 14 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ build-manager-docker() {
build-docker ${MANAGER_BINARY_NAME} manager
}

build-manager-console() {
set -x
consoleDir=$(echo $curDir | sed 's#hack#manager/console#')
docker run --workdir=/build \
--rm -v ${consoleDir}:/build node:12-alpine \
sh -c "npm install --loglevel warn --progress false && npm run build"
}

main() {
create-dirs
if [[ "1" == "${USE_DOCKER}" ]]; then
Expand All @@ -120,6 +128,9 @@ main() {
manager)
build-manager-docker
;;
manager-console)
build-manager-console
;;
*)
build-dfget-docker
build-cdn-docker
Expand All @@ -142,6 +153,9 @@ main() {
manager)
build-manager-local
;;
manager-console)
build-manager-console
;;
*)
build-dfget-local
build-cdn-local
Expand Down
3 changes: 1 addition & 2 deletions hack/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ git-submodule() {
}

main() {
git-submodule

case "${1-}" in
cdn)
docker-build cdn
Expand All @@ -54,6 +52,7 @@ main() {
docker-build scheduler
;;
manager)
git-submodule
docker-build manager
esac
}
Expand Down
24 changes: 24 additions & 0 deletions hack/gen-buildx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

components="cdn scheduler manager"

set -x

for c in ${components}; do
file=build/images/"${c}"/Dockerfile
sed -i '1i# syntax=docker/dockerfile:1.3' "${file}"
sed -i "s#RUN make build-$c && make install-$c#RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/go/ export GOPATH=/root/go \&\& make build-$c \&\& make install-$c#" "${file}"
done

# dfdaemon is subcommand, need to update alone
sed -i '1i# syntax=docker/dockerfile:1.3' build/images/dfdaemon/Dockerfile
sed -i "s#RUN make build-dfget && make install-dfget#RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/go/ export GOPATH=/root/go \&\& make build-dfget \&\& make install-dfget#" build/images/dfdaemon/Dockerfile

# buildx need "--load" to export images to docker
sed -i 's/docker build/docker build --load/' hack/docker-build.sh
sed -i 's/docker build/docker build --load/' test/tools/no-content-length/build.sh

# TODO build console in https://github.com/dragonflyoss/console, and build image with github action cache
# remove npm build, use "make build-manager-console" separated
# sed -i '12,18d' build/images/manager/Dockerfile
# sed -i 's#COPY --from=console-builder /build/dist /opt/dragonfly/manager/console/dist#COPY ./manager/console/dist /opt/dragonfly/manager/console/dist#' build/images/manager/Dockerfile
7 changes: 7 additions & 0 deletions test/testdata/charts/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ scheduler:
- name: artifact
hostPath:
path: /tmp/artifact
config:
verbose: true

cdn:
image: d7yio/cdn
Expand All @@ -33,6 +35,8 @@ cdn:
- name: artifact
hostPath:
path: /tmp/artifact
config:
verbose: true

dfdaemon:
image: d7yio/dfdaemon
Expand All @@ -51,6 +55,7 @@ dfdaemon:
config:
verbose: true
pprofPort: 9999
metrics: 127.0.0.1:8888
scheduler:
disableAutoBackSource: true
proxy:
Expand Down Expand Up @@ -84,3 +89,5 @@ manager:
- name: artifact
hostPath:
path: /tmp/artifact
config:
verbose: true

0 comments on commit 6d11481

Please sign in to comment.