diff --git a/.github/workflows/buildtest.yaml b/.github/workflows/buildtest.yaml new file mode 100644 index 0000000..2898c94 --- /dev/null +++ b/.github/workflows/buildtest.yaml @@ -0,0 +1,42 @@ +name: go-build-and-test-amd64 +on: + push: + pull_request: + schedule: + - cron: "0 8 * * 0" # every sunday +jobs: + build: + name: build + strategy: + matrix: + go-version: [1.20.x] + os: [ubuntu-22.04] + goos: [linux] + goarch: [amd64] + runs-on: ${{ matrix.os }} + steps: + - name: set up Go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + - name: check out code into the Go module directory + uses: actions/checkout@v2 + - name: build test for ${{ matrix.goarch }} + env: + GOARCH: ${{ matrix.goarch }} + GOOS: ${{ matrix.goos }} + run: make build + + test: + name: test + runs-on: ubuntu-22.04 + needs: build + steps: + - name: set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + - name: check out code into the Go module directory + uses: actions/checkout@v3 + - name: run unit-test + run: make test diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..fddfae4 --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: "37 4 * * 0" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-22.04 + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ go ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/image-push-master.yaml b/.github/workflows/image-push-master.yaml new file mode 100644 index 0000000..4fa7c8f --- /dev/null +++ b/.github/workflows/image-push-master.yaml @@ -0,0 +1,126 @@ +name: "push images on merge to master" + +env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + +on: + push: + branches: + - master +jobs: + build-and-push-amd64-rdma-cni: + name: image push amd64 + runs-on: ubuntu-22.04 + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64 + tags: | + ${{ env.IMAGE_NAME }}:latest-amd64 + ${{ steps.docker_meta.outputs.tags }}:${{ github.sha }} + file: ./Dockerfile + + build-and-push-arm64-rdma-cni: + name: image push arm64 + runs-on: ubuntu-22.04 + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/arm64 + tags: | + ${{ env.IMAGE_NAME }}:latest-arm64 + file: ./Dockerfile.arm64 + + build-and-push-ppc64le-rdma-cni: + name: image Push ppc64le + runs-on: ubuntu-22.04 + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/ppc64le + tags: | + ${{ env.IMAGE_NAME }}:latest-ppc64le + file: ./Dockerfile.ppc64le + + push-manifest: + runs-on: ubuntu-22.04 + needs: [build-and-push-amd64-rdma-cni,build-and-push-amr64-rdma-cni,build-and-push-ppc64le-rdma-cni] + steps: + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest for multi-arch images + run: | + # pull + docker pull ${{ env.IMAGE_NAME }}:latest-amd64 + docker pull ${{ env.IMAGE_NAME }}:latest-arm64 + docker pull ${{ env.IMAGE_NAME }}:latest-ppc64le + # create + docker manifest create ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:latest-amd64 ${{ env.IMAGE_NAME }}:latest-arm64 ${{ env.IMAGE_NAME }}:latest-ppc64le + # annotate + docker manifest annotate ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:latest-amd64 --arch amd64 + docker manifest annotate ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:latest-arm64 --arch arm64 + docker manifest annotate ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:latest-ppc64le --arch ppc64le + # push + docker manifest push ${{ env.IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.github/workflows/image-push-release.yaml b/.github/workflows/image-push-release.yaml new file mode 100644 index 0000000..ebe663e --- /dev/null +++ b/.github/workflows/image-push-release.yaml @@ -0,0 +1,148 @@ +name: "push images on release" + +env: + IMAGE_NAME: ghcr.io/${{ github.repository }} + +on: + push: + tags: + - v* +jobs: + build-and-push-amd64-rdma-cni: + runs-on: ubuntu-22.04 + name: image push AMD64 + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64 + tags: | + ${{ steps.docker_meta.outputs.tags }}-amd64 + ${{ steps.docker_meta.outputs.tags }}:${{ github.sha }} + file: ./Dockerfile + + build-and-push-arm64-rdma-cni: + runs-on: ubuntu-22.04 + name: image push ARM64 + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/arm64 + tags: | + ${{ steps.docker_meta.outputs.tags }}-arm64 + file: ./Dockerfile.arm64 + + build-and-push-ppc64le-rdma-cni: + runs-on: ubuntu-22.04 + name: image push ppc64le + steps: + - name: check out the repo + uses: actions/checkout@v2 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: login to Docker + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: build and push rdma-cni + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/arm64 + tags: | + ${{ steps.docker_meta.outputs.tags }}-ppc64le + file: ./Dockerfile.ppc64le + + push-manifest: + runs-on: ubuntu-22.04 + needs: [build-and-push-amd64-rdma-cni,build-and-push-amr64-rdma-cni,build-and-push-ppc64le-rdma-cni] + steps: + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.IMAGE_NAME }} + tag-latest: false + + - name: login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: create manifest for multi-arch images + run: | + # pull + docker pull ${{ steps.docker_meta.outputs.tags }}-amd64 + docker pull ${{ steps.docker_meta.outputs.tags }}-arm64 + docker pull ${{ steps.docker_meta.outputs.tags }}-ppc64le + # create + docker manifest create ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 ${{ steps.docker_meta.outputs.tags }}-arm64 ${{ steps.docker_meta.outputs.tags }}-ppc64le + # annotate + docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 --arch amd64 + docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-arm64 --arch arm64 + docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-ppc64le --arch ppc64le + # push + docker manifest push ${{ steps.docker_meta.outputs.tags }} \ No newline at end of file diff --git a/.github/workflows/static-scan.yaml b/.github/workflows/static-scan.yaml new file mode 100644 index 0000000..3c026ba --- /dev/null +++ b/.github/workflows/static-scan.yaml @@ -0,0 +1,33 @@ +name: go-static-analysis +on: [push, pull_request] +jobs: + golangci: + name: Lint + runs-on: ubuntu-22.04 + steps: + - name: set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + - name: checkout PR + uses: actions/checkout@v2 + - name: run make lint + run: make lint + shellcheck: + name: shellcheck + runs-on: ubuntu-22.04 + steps: + - name: checkout PR + uses: actions/checkout@v2 + - name: run ShellCheck + uses: ludeeus/action-shellcheck@master + hadolint: + runs-on: ubuntu-22.04 + name: Hadolint + steps: + - name: checkout PR + uses: actions/checkout@v2 + - name: run Hadolint + uses: brpaz/hadolint-action@v1.2.1 + with: + dockerfile: Dockerfile diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4f97f40..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: go - -go: - - "1.13" - -env: - - IMAGE_NAME=ghcr.io/k8snetworkplumbingwg/rdma-cni - -before_script: - - go get -u github.com/mattn/goveralls - -script: - - make lint - - make test-coverage - - goveralls -coverprofile=rdma-cni.cover -service=travis-ci - - make image - -before_deploy: - - docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS" - -deploy: - # Push image to Dockerhub on merge to master - - provider: script - skip_cleanup: true - script: bash scripts/deploy.sh $IMAGE_NAME latest $TRAVIS_CPU_ARCH - on: - branch: master - # Push image to Dockerhub on tag - - provider: script - skip_cleanup: true - script: bash scripts/deploy.sh $IMAGE_NAME $TRAVIS_TAG $TRAVIS_CPU_ARCH - on: - tags: true - all_branches: true - condition: "$TRAVIS_TAG =~ ^v[0-9].*$" diff --git a/Dockerfile b/Dockerfile index 5e748f1..f068de6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ FROM golang:alpine as builder -ADD . /usr/src/rdma-cni +COPY . /usr/src/rdma-cni ENV HTTP_PROXY $http_proxy ENV HTTPS_PROXY $https_proxy -RUN apk add --update --virtual build-dependencies build-base linux-headers git && \ - cd /usr/src/rdma-cni && \ +WORKDIR /usr/src/rdma-cni +RUN apk add --no-cache --virtual build-dependencies build-base=~0.5 && \ make clean && \ make build -FROM alpine +FROM alpine:3 COPY --from=builder /usr/src/rdma-cni/build/rdma /usr/bin/ WORKDIR / LABEL io.k8s.display-name="RDMA CNI" -ADD ./images/entrypoint.sh / +COPY ./images/entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000..d5c9b69 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,21 @@ +FROM arm64v8/golang:alpine as builder + +COPY . /usr/src/rdma-cni + +ENV HTTP_PROXY $http_proxy +ENV HTTPS_PROXY $https_proxy + +WORKDIR /usr/src/rdma-cni +RUN apk add --no-cache --virtual build-dependencies build-base=~0.5 && \ + make clean && \ + make build + +FROM arm64v8/alpine +COPY --from=builder /usr/src/rdma-cni/build/rdma /usr/bin/ +WORKDIR / + +LABEL io.k8s.display-name="RDMA CNI" + +COPY ./images/entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile.ppc64le b/Dockerfile.ppc64le new file mode 100644 index 0000000..78abc45 --- /dev/null +++ b/Dockerfile.ppc64le @@ -0,0 +1,21 @@ +FROM ppc64le/golang:alpine as builder + +COPY . /usr/src/rdma-cni + +ENV HTTP_PROXY $http_proxy +ENV HTTPS_PROXY $https_proxy + +WORKDIR /usr/src/rdma-cni +RUN apk add --no-cache --virtual build-dependencies build-base=~0.5 && \ + make clean && \ + make build + +FROM ppc64le/alpine +COPY --from=builder /usr/src/rdma-cni/build/rdma /usr/bin/ +WORKDIR / + +LABEL io.k8s.display-name="RDMA CNI" + +COPY ./images/entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Makefile b/Makefile index 557ddc5..de26eff 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,12 @@ BINARY_NAME=rdma PACKAGE=rdma-cni ORG_PATH=github.com/k8snetworkplumbingwg REPO_PATH=$(ORG_PATH)/$(PACKAGE) -GOPATH=$(CURDIR)/.gopath -GOBIN =$(CURDIR)/bin -BUILDDIR=$(CURDIR)/build -BASE=$(GOPATH)/src/$(REPO_PATH) +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +BINDIR =$(PROJECT_DIR)/bin +BUILDDIR=$(PROJECT_DIR)/build GOFILES=$(shell find . -name *.go | grep -vE "(\/vendor\/)|(_test.go)") -PKGS=$(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/")) -TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS)) - -export GOPATH -export GOBIN +PKGS=$(or $(PKG),$(shell cd $(PROJECT_DIR) && go list ./... | grep -v "^$(PACKAGE)/vendor/")) +TESTPKGS = $(shell go list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS)) # Version VERSION?=master @@ -22,8 +18,8 @@ LDFLAGS="-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE # Docker IMAGE_BUILDER?=@docker -IMAGEDIR=$(BASE)/images -DOCKERFILE?=$(CURDIR)/Dockerfile +IMAGEDIR=$(PROJECT_DIR)/images +DOCKERFILE?=$(PROJECT_DIR)/Dockerfile TAG?=ghcr.io/k8snetworkplumbingwg/rdma-cni IMAGE_BUILD_OPTS?= # Accept proxy settings for docker @@ -37,53 +33,55 @@ ifdef HTTPS_PROXY endif IMAGE_BUILD_OPTS += $(DOCKERARGS) +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN := $(shell go env GOPATH)/bin +else +GOBIN := $(shell go env GOBIN) +endif + +TARGET_OS ?= $(shell go env GOOS) +TARGET_ARCH ?= $(shell go env GOARCH) + +# Options for go build command +GO_BUILD_OPTS ?= CGO_ENABLED=0 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) + # Go tools -GO = go -GOLANGCI_LINT = $(GOBIN)/golangci-lint +GOLANGCI_LINT = $(BINDIR)/golangci-lint # golangci-lint version should be updated periodically # we keep it fixed to avoid it from unexpectedly failing on the project # in case of a version bump GOLANGCI_LINT_VER = v1.51.2 -TIMEOUT = 15 +TIMEOUT = 30 Q = $(if $(filter 1,$V),,@) .PHONY: all all: lint build -$(BASE): ; $(info setting GOPATH...) - @mkdir -p $(dir $@) - @ln -sf $(CURDIR) $@ +$(BUILDDIR): ; $(info Creating build directory...) + @cd $(PROJECT_DIR) && mkdir -p $@ -$(GOBIN): - @mkdir -p $@ - -$(BUILDDIR): | $(BASE) ; $(info Creating build directory...) - @cd $(BASE) && mkdir -p $@ +$(BINDIR): ; $(info Creating bin directory...) + @cd $(PROJECT_DIR) && mkdir -p $@ build: $(BUILDDIR)/$(BINARY_NAME) ; $(info Building $(BINARY_NAME)...) @ ## Build executable file $(info Done!) $(BUILDDIR)/$(BINARY_NAME): $(GOFILES) | $(BUILDDIR) - @cd $(BASE)/cmd/$(BINARY_NAME) && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -ldflags $(LDFLAGS) -v + @$(GO_BUILD_OPTS) go build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -ldflags $(LDFLAGS) -v cmd/rdma/main.go # Tools +$(GOLANGCI_LINT): ; $(info building golangci-lint...) + $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BINDIR) $(GOLANGCI_LINT_VER) -$(GOLANGCI_LINT): | $(BASE) ; $(info building golangci-lint...) - $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VER) - -GOVERALLS = $(GOBIN)/goveralls -$(GOBIN)/goveralls: | $(BASE) ; $(info building goveralls...) - $Q go get github.com/mattn/goveralls +GOVERALLS = $(BINDIR)/goveralls +$(BINDIR)/goveralls: ; $(info building goveralls...) + $Q GOBIN=$(BINDIR) go install github.com/mattn/goveralls@v0.0.12 # Tests - .PHONY: lint -lint: | $(BASE) $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint - $Q mkdir -p $(BASE)/test - $Q cd $(BASE) && ret=0 && \ - test -z "$$($(GOLANGCI_LINT) run | tee $(BASE)/test/lint.out)" || ret=1 ; \ - cat $(BASE)/test/lint.out ; rm -rf $(BASE)/test ; \ - exit $$ret +lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint + $Q $(GOLANGCI_LINT) run ./... TEST_TARGETS := test-default test-bench test-short test-verbose test-race .PHONY: $(TEST_TARGETS) test-xml check test tests @@ -93,33 +91,30 @@ test-verbose: ARGS=-v ## Run tests in verbose mode with coverage repo test-race: ARGS=-race ## Run tests with race detector $(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%) $(TEST_TARGETS): test -check test tests: lint | $(BASE) ; $(info running $(NAME:%=% )tests...) @ ## Run tests - $Q cd $(BASE) && $(GO) test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS) +check test tests: ; $(info running $(NAME:%=% )tests...) @ ## Run tests + $Q go test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS) -test-xml: lint | $(BASE) $(GO2XUNIT) ; $(info running $(NAME:%=% )tests...) @ ## Run tests with xUnit output - $Q cd $(BASE) && 2>&1 $(GO) test -timeout 20s -v $(TESTPKGS) | tee test/tests.output +test-xml: | $(GO2XUNIT) ; $(info running $(NAME:%=% )tests...) @ ## Run tests with xUnit output + $Q 2>&1 go test -timeout $(TIMEOUT)s -v $(TESTPKGS) | tee test/tests.output $(GO2XUNIT) -fail -input test/tests.output -output test/tests.xml -COVERAGE_MODE = count +COVERAGE_MODE = set .PHONY: test-coverage test-coverage-tools test-coverage-tools: | $(GOVERALLS) -test-coverage: COVERAGE_DIR := $(CURDIR)/test -test-coverage: test-coverage-tools | $(BASE) ; $(info running coverage tests...) @ ## Run coverage tests - $Q cd $(BASE); $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=rdma-cni.cover ./... +test-coverage: COVERAGE_DIR := $(PROJECT_DIR)/test +test-coverage: test-coverage-tools ; $(info running coverage tests...) @ ## Run coverage tests + $Q go test -covermode=$(COVERAGE_MODE) -coverprofile=rdma-cni.cover ./... # Container image .PHONY: image -image: | $(BASE) ; $(info Building Docker image...) @ ## Build conatiner image - $(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(IMAGE_BUILD_OPTS) - +image: ; $(info Building Docker image...) @ ## Build conatiner image + $(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(PROJECT_DIR) $(IMAGE_BUILD_OPTS) # Misc - .PHONY: clean clean: ; $(info Cleaning...) @ ## Cleanup everything - @$(GO) clean -modcache - @rm -rf $(GOPATH) @rm -rf $(BUILDDIR) + @rm -rf $(BINDIR) @rm -rf test .PHONY: help diff --git a/go.mod b/go.mod index fd33b1a..338f7ca 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/k8snetworkplumbingwg/rdma-cni -go 1.19 +go 1.20 require ( github.com/Mellanox/rdmamap v1.0.0 diff --git a/images/entrypoint.sh b/images/entrypoint.sh index a277e3f..d10e2c7 100755 --- a/images/entrypoint.sh +++ b/images/entrypoint.sh @@ -10,20 +10,20 @@ RDMA_CNI_BIN_FILE="/usr/bin/rdma" # Give help text for parameters. usage() { - /bin/echo -e "This is an entrypoint script for RDMA CNI to overlay its" - /bin/echo -e "binary into location in a filesystem. The binary file will" - /bin/echo -e "be copied to the corresponding directory." - /bin/echo -e "" - /bin/echo -e "./entrypoint.sh" - /bin/echo -e "\t-h --help" - /bin/echo -e "\t--cni-bin-dir=$CNI_BIN_DIR" - /bin/echo -e "\t--rdma-cni-bin-file=$RDMA_CNI_BIN_FILE" + printf "This is an entrypoint script for RDMA CNI to overlay its\n" + printf "binary into location in a filesystem. The binary file will\n" + printf "be copied to the corresponding directory.\n" + printf "\n" + printf "./entrypoint.sh\n" + printf "\t-h --help\n" + printf "\t--cni-bin-dir=%s\n" "$CNI_BIN_DIR" + printf "\t--rdma-cni-bin-file=%s\n" "$RDMA_CNI_BIN_FILE" } # Parse parameters given as arguments to this script. while [ "$1" != "" ]; do - PARAM=`echo $1 | awk -F= '{print $1}'` - VALUE=`echo $1 | awk -F= '{print $2}'` + PARAM=$(echo "$1" | awk -F= '{print $1}') + VALUE=$(echo "$1" | awk -F= '{print $2}') case $PARAM in -h | --help) usage @@ -55,10 +55,11 @@ do done # Copy file into proper place. -cp -f $RDMA_CNI_BIN_FILE $CNI_BIN_DIR +cp -f "$RDMA_CNI_BIN_FILE" "$CNI_BIN_DIR" echo "Entering sleep... (success)" +trap : TERM INT # Sleep forever. # sleep infinity is not available in alpine; instead lets go sleep for ~68 years. Hopefully that's enough sleep -sleep 2147483647 \ No newline at end of file +sleep 2147483647 & wait diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index ad49f1f..0000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -IMAGE_NAME=$1 -VERSION=$2 -CPU_ARCH=$3 -export DOCKER_CLI_EXPERIMENTAL="enabled"; -docker tag $IMAGE_NAME ${IMAGE_NAME}-${CPU_ARCH}:${VERSION} -docker push ${IMAGE_NAME}-${CPU_ARCH}:${VERSION} -docker manifest create ${IMAGE_NAME}:${VERSION} ${IMAGE_NAME}-${CPU_ARCH}:${VERSION} -docker manifest annotate ${IMAGE_NAME}:${VERSION} ${IMAGE_NAME}-${CPU_ARCH}:${VERSION} --arch ${CPU_ARCH} -docker manifest push ${IMAGE_NAME}:${VERSION}