Skip to content

Commit

Permalink
chore: Update build tools and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat committed Feb 21, 2024
1 parent d2fa734 commit 9532035
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 184 deletions.
53 changes: 41 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
name: Release
name: Create a Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
release:
if: contains(github.ref, 'refs/tags/')
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to UHub
uses: docker/login-action@v2
with:
registry: uhub.service.ucloud.cn
username: ${{ secrets.UHUB_USER }}
password: ${{ secrets.UHUB_PASSWORD }}

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3 | sed -e "s/^v//")

- name: Set up go
uses: actions/setup-go@v3
with:
go-version: 1.19.5
go-version: 1.20.5

- name: Build cnivpc
run: DEPLOY=true make cnivpc

- name: Build CNI
run: make build
- name: Build ipamd
run: DEPLOY=true make ipamd

- name: Build ipamctl
run: make build-ipamctl
- name: Build vip-controller
run: DEPLOY=true make vip-controller

- name: Pack
run: zip -r cnivpc.zip ./bin LLICENSE
- name: Package cni
run: >
tar -cv
LICENSE README.md
-C bin/ cnivpc cnivpctl
-C config/ 10-cnivpc.conf
| gzip --best
> 'uk8s-cni-vpc_v${{ steps.get_version.outputs.VERSION }}.tar.gz'
- name: Create release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
draft: true
body: |
## Docker Images
- uhub.service.ucloud.cn/uk8s/cni-vpc-node:${{ steps.get_version.outputs.VERSION }}
- uhub.service.ucloud.cn/uk8s/cni-vpc-ipamd:${{ steps.get_version.outputs.VERSION }}
- uhub.service.ucloud.cn/uk8s/vip-controller:${{ steps.get_version.outputs.VERSION }}
files: |
cnivpc.zip
*.tar.gz
104 changes: 40 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,117 +16,93 @@ CNI_VERSION:=$(shell echo ${CNI_VERSION} | sed -e "s/^v//")
export GOOS=linux
export GO111MODULE=on
export GOARCH=$(TARGETARCH)
export CGO_ENABLED=0

DOCKER_DEPLOY_BUCKET=uhub.service.ucloud.cn/uk8s
DOCKER_TEST_BUCKET=uhub.service.ucloud.cn/wxyz

DOCKER_LABEL:=$(if $(DEPLOY),$(CNI_VERSION),build-$(COMMIT_ID_SHORT))
DOCKER_LABEL:=$(if $(DEPLOY),$(CNI_VERSION),dev-$(COMMIT_ID_SHORT))
DOCKER_LABEL:=$(if $(IMAGE_TAG),$(IMAGE_TAG),$(DOCKER_LABEL))
DOCKER_BUCKET:=$(if $(DEPLOY),$(DOCKER_DEPLOY_BUCKET),$(DOCKER_TEST_BUCKET))

CNIVPC_IMAGE:=$(DOCKER_BUCKET)/cni-vpc-node:$(DOCKER_LABEL)
IPAMD_IMAGE:=$(DOCKER_BUCKET)/cni-vpc-ipamd:$(DOCKER_LABEL)
VIP_CONTROLLER_IMAGE:=$(DOCKER_BUCKET)/vip-controller:$(DOCKER_LABEL)
CNI_VPC_BUILD_IMAGE:=$(DOCKER_BUCKET)/cni-vpc-build:$(DOCKER_LABEL)

DOCKER_CMD:=$(if $(DOCKER_CMD),$(DOCKER_CMD),docker)

DOCKER_BASE_IMAGE:=$(if $(DOCKER_BASE_IMAGE),$(DOCKER_BASE_IMAGE),uhub.service.ucloud.cn/wxyz/cni-vpc-base:1.19.4)

.PHONY: docker-build docker-deploy docker-build-cni docker-base-image deploy-docker-base-image \
check-fmt fmt install-check check version clean generate-grpc \
build build-cni build-ipamd build-ipamctl build-vip-controller \
install-grpc generate-k8s generate-grpc

all: build

build: build-cni build-ipamd build-ipamctl build-vip-controller

build-cni:
go build ${LDFLAGS} -o ./bin/cnivpc ./cmd/cnivpc

build-ipamd:
go build ${LDFLAGS} -o ./bin/cnivpc-ipamd ./cmd/cnivpc-ipamd

build-ipamctl:
go build ${LDFLAGS} -o ./bin/ipamctl ./cmd/ipamctl

build-vip-controller:
go build ${LDFLAGS} -o ./bin/vip-controller ./cmd/vip-controller

docker-build:
${DOCKER_CMD} build -t ${IPAMD_IMAGE} -f dockerfiles/ipamd/Dockerfile .
${DOCKER_CMD} build -t ${VIP_CONTROLLER_IMAGE} -f dockerfiles/vip-controller/Dockerfile .
@echo "Successfully built image: ${IPAMD_IMAGE}"
@echo "Successfully built image: ${VIP_CONTROLLER_IMAGE}"

docker-deploy: docker-build
${DOCKER_CMD} push ${IPAMD_IMAGE}
${DOCKER_CMD} push ${VIP_CONTROLLER_IMAGE}
@echo "Successfully pushed image: ${IPAMD_IMAGE}"
@echo "Successfully pushed image: ${VIP_CONTROLLER_IMAGE}"

# Build cnivpc binary in image, so that the glibc can match the production
# environment.
# If you build cnivpc binary in the latest Linux distribution (Such as Arch),
# the binary might not be able to run in UK8S machine because the glibc version
# in UK8S machine is very old.
# we should use the image "uhub.service.ucloud.cn/wxyz/cni-vpc-base", it is based
# on centos 7 (same as production), and glibc version is properly.
docker-build-cni:
${DOCKER_CMD} build -t ${CNI_VPC_BUILD_IMAGE} -f dockerfiles/cnivpc-build/Dockerfile .
@mkdir -p bin
@bash ./scripts/copy-from-docker-image.sh "${DOCKER_CMD}" "${CNI_VPC_BUILD_IMAGE}" /cnivpc ./bin/cnivpc
@bash ./scripts/copy-from-docker-image.sh "${DOCKER_CMD}" "${CNI_VPC_BUILD_IMAGE}" /ipamctl ./bin/ipamctl
ifdef NODE_IP
scp bin/docker/cnivpc root@${NODE_IP}:/opt/cni/bin/cnivpc
endif

docker-build-base-image:
${DOCKER_CMD} build -t ${DOCKER_BASE_IMAGE} -f dockerfiles/base/Dockerfile .
@echo "Successfully built ${DOCKER_BASE_IMAGE}"

docker-deploy-base-image: docker-base-image
${DOCKER_CMD} push ${DOCKER_BASE_IMAGE}
@echo "Successfully pushed ${DOCKER_BASE_IMAGE}"

all: cnivpc

.PHONY: cnivpc-bin
cnivpc-bin:
CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build ${LDFLAGS} -o ./bin/cnivpc ./cmd/cnivpc
CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build ${LDFLAGS} -o ./bin/cnivpctl ./cmd/cnivpctl

.PHONY: cnivpc
cnivpc: cnivpc-bin
$(DOCKER_CMD) build -t $(CNIVPC_IMAGE) -f dockerfiles/cnivpc/Dockerfile .
$(DOCKER_CMD) push $(CNIVPC_IMAGE)
@echo "Build done: $(CNIVPC_IMAGE)"

.PHONY: ipamd
ipamd:
CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build ${LDFLAGS} -o ./bin/cnivpc-ipamd ./cmd/cnivpc-ipamd
$(DOCKER_CMD) build -t $(IPAMD_IMAGE) -f dockerfiles/ipamd/Dockerfile .
$(DOCKER_CMD) push $(IPAMD_IMAGE)
@echo "Build done: $(IPAMD_IMAGE)"

.PHONY: vip-controller
vip-controller:
CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build ${LDFLAGS} -o ./bin/vip-controller ./cmd/vip-controller
$(DOCKER_CMD) build -t $(VIP_CONTROLLER_IMAGE) -f dockerfiles/vip-controller/Dockerfile .
$(DOCKER_CMD) push $(VIP_CONTROLLER_IMAGE)
@echo "Build done: $(VIP_CONTROLLER_IMAGE)"

.PHONY: fmt
fmt:
@command -v goimports >/dev/null || { echo "ERROR: goimports not installed"; exit 1; }
@exit $(shell find ./* \
-type f \
-name '*.go' \
-print0 | sort -z | xargs -0 -- goimports $(or $(FORMAT_FLAGS),-w) | wc -l | bc)

.PHONY: check-fmt
check-fmt:
@./scripts/check-fmt.sh

.PHONY: install-check
install-check:
@go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
@go install github.com/client9/misspell/cmd/misspell@latest
@go install github.com/gordonklaus/ineffassign@latest
@go install golang.org/x/tools/cmd/goimports@latest

.PHONY: check
check:
@echo "==> check ineffassign"
@ineffassign ./...
@echo "==> check spell"
@find . -type f -name '*.go' | xargs misspell -error
@echo "==> check gocyclo"
@gocyclo -over 70 .
@echo "==> go vet"
@go vet ./...

.PHONY: version
version:
@echo ${CNI_VERSION}

.PHONY: clean
clean:
@rm -rf ./bin

.PHONY: install-grpc
install-grpc:
@go install github.com/golang/protobuf/protoc-gen-go@latest

.PHONY: generate-grpc
generate-grpc:
@command -v protoc >/dev/null || { echo "ERROR: protoc not installed"; exit 1; }
@command -v protoc-gen-go >/dev/null || { echo "ERROR: protoc-gen-go not installed"; exit 1; }
@protoc --go_out=plugins=grpc:./rpc ./rpc/ipamd.proto

.PHONY: generate-k8s
generate-k8s:
@bash hack/update-codegen.sh
40 changes: 0 additions & 40 deletions dockerfiles/base/Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions dockerfiles/cnivpc-build/Dockerfile

This file was deleted.

25 changes: 6 additions & 19 deletions dockerfiles/cnivpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
FROM uhub.service.ucloud.cn/wxyz/cni-vpc-base:1.19.4 AS builder
FROM alpine:latest

WORKDIR /go/src/cni-vpc-uk8s
COPY bin/cnivpc /usr/local/bin/
COPY bin/cnivpctl /usr/local/bin/
COPY scripts/cnivpc-docker-entrypoint.sh /entrypoint.sh
COPY config/10-cnivpc.conf /10-cnivpc.conf

# Configure build with Go modules
ENV GO111MODULE=on
ENV GOPROXY=direct

COPY . ./
RUN make build-cni

FROM uhub.service.ucloud.cn/wxyz/cnivpc-plugin-basic:1.0

RUN mkdir -p /app
RUN mkdir -p /app/cni/bin
RUN mkdir -p /app/cni/net.d

COPY --from=builder /go/src/cni-vpc-uk8s/bin/cnivpc /app/cni/bin/cnivpc
COPY config/10-cnivpc.conf /app/cni/net.d

ENTRYPOINT [ "" ]
ENTRYPOINT [ "/entrypoint.sh" ]
22 changes: 2 additions & 20 deletions dockerfiles/ipamd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
FROM uhub.service.ucloud.cn/wxyz/cni-vpc-base:1.19.4 AS builder
FROM alpine:latest

WORKDIR /go/src/cni-vpc-uk8s

# Configure build with Go modules
ENV GO111MODULE=on
ENV GOPROXY=direct

COPY . ./
RUN make build-ipamd
RUN make build-cni

FROM centos:7.7.1908

RUN mkdir -p /app/
RUN mkdir -p /opt/cni/bin/
RUN mkdir -p /opt/cni/net.d/

COPY --from=builder /go/src/cni-vpc-uk8s/bin/cnivpc-ipamd /usr/local/bin/
COPY --from=builder /go/src/cni-vpc-uk8s/bin/cnivpc /app/
COPY config/10-cnivpc.conf /app/10-cnivpc.conf
COPY bin/cnivpc-ipamd /usr/local/bin/

ENTRYPOINT [ "/usr/local/bin/cnivpc-ipamd" ]
15 changes: 2 additions & 13 deletions dockerfiles/vip-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
FROM uhub.service.ucloud.cn/wxyz/cni-vpc-base:1.19.4 AS builder
FROM alpine:latest

WORKDIR /go/src/cni-vpc-uk8s

# Configure build with Go modules
ENV GO111MODULE=on
ENV GOPROXY=direct

COPY . ./
RUN make build-vip-controller

FROM centos:7.7.1908

COPY --from=builder /go/src/cni-vpc-uk8s/bin/vip-controller /usr/local/bin/
COPY bin/vip-controller /usr/local/bin/

ENTRYPOINT [ "/usr/local/bin/vip-controller" ]
19 changes: 19 additions & 0 deletions scripts/cnivpc-docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

if [[ -d /opt/cni ]]; then
cp -f /usr/local/bin/cnivpc /opt/cni/bin/cnivpc
# cp -f /10-cnivpc.conf /opt/cni/net.d/10-cnivpc.conf
fi

if [[ -d /host-bin ]]; then
cp -f /usr/local/bin/cnivpctl /host-bin/cnivpctl
fi

while true; do
if [[ ! -f "/var/log/cnivpc.log" ]]; then
echo "waitting for cnivpc logs..."
sleep 3
continue
fi
tail -f /var/log/cnivpc.log
done

0 comments on commit 9532035

Please sign in to comment.