diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66e01c02..bac78882 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,8 @@ env: # Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run # a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether # credentials have been provided before trying to run steps that need them. - DOCKER_USR: ${{ secrets.DOCKER_USR }} + CONTRIB_DOCKER_USR: ${{ secrets.CONTRIB_DOCKER_USR }} + XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }} AWS_USR: ${{ secrets.AWS_USR }} jobs: @@ -299,14 +300,22 @@ jobs: - name: Login to Docker uses: docker/login-action@v1 - if: env.DOCKER_USR != '' + if: env.CONTRIB_DOCKER_USR != '' with: - username: ${{ secrets.DOCKER_USR }} - password: ${{ secrets.DOCKER_PSW }} + username: ${{ secrets.CONTRIB_DOCKER_USR }} + password: ${{ secrets.CONTRIB_DOCKER_PSW }} + + - name: Login to Upbound + uses: docker/login-action@v1 + if: env.XPKG_ACCESS_ID != '' + with: + registry: xpkg.upbound.io + username: ${{ secrets.XPKG_ACCESS_ID }} + password: ${{ secrets.XPKG_TOKEN }} - name: Publish Artifacts to S3 and Docker Hub run: make -j2 publish BRANCH_NAME=${GITHUB_REF##*/} - if: env.AWS_USR != '' && env.DOCKER_USR != '' + if: env.AWS_USR != '' && env.CONTRIB_DOCKER_USR != '' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }} @@ -315,7 +324,7 @@ jobs: DOCS_GIT_PSW: ${{ secrets.UPBOUND_BOT_GITHUB_PSW }} - name: Promote Artifacts in S3 and Docker Hub - if: github.ref == 'refs/heads/master' && env.AWS_USR != '' && env.DOCKER_USR != '' + if: github.ref == 'refs/heads/master' && env.AWS_USR != '' && env.CONTRIB_DOCKER_USR != '' run: make -j2 promote env: BRANCH_NAME: master diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index d576fb38..659d700c 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -12,10 +12,13 @@ on: default: 'alpha' env: + # Common versions + GO_VERSION: '1.18' + # Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run # a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether # credentials have been provided before trying to run steps that need them. - DOCKER_USR: ${{ secrets.DOCKER_USR }} + CONTRIB_DOCKER_USR: ${{ secrets.CONTRIB_DOCKER_USR }} AWS_USR: ${{ secrets.AWS_USR }} jobs: @@ -33,13 +36,13 @@ jobs: - name: Login to Docker uses: docker/login-action@v1 - if: env.DOCKER_USR != '' + if: env.CONTRIB_DOCKER_USR != '' with: - username: ${{ secrets.DOCKER_USR }} - password: ${{ secrets.DOCKER_PSW }} + username: ${{ secrets.CONTRIB_DOCKER_USR }} + password: ${{ secrets.CONTRIB_DOCKER_PSW }} - name: Promote Artifacts in S3 and Docker Hub - if: env.AWS_USR != '' && env.DOCKER_USR != '' + if: env.AWS_USR != '' && env.CONTRIB_DOCKER_USR != '' run: make -j2 promote BRANCH_NAME=${GITHUB_REF##*/} env: VERSION: ${{ github.event.inputs.version }} diff --git a/Makefile b/Makefile index c5b0dec6..4de0e5f3 100644 --- a/Makefile +++ b/Makefile @@ -6,26 +6,71 @@ PROJECT_REPO := github.com/crossplane-contrib/$(PROJECT_NAME) PLATFORMS ?= linux_amd64 linux_arm64 -include build/makelib/common.mk +# ==================================================================================== # Setup Output + -include build/makelib/output.mk +# ==================================================================================== # Setup Go + +# Set a sane default so that the nprocs calculation below is less noisy on the initial +# loading of this file NPROCS ?= 1 + +# each of our test suites starts a kube-apiserver and running many test suites in +# parallel can lead to high CPU utilization. by default we reduce the parallelism +# to half the number of CPU cores. GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 ))) + GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/provider GO_LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION) GO_SUBDIRS += cmd pkg apis GO111MODULE = on -include build/makelib/golang.mk +# kind-related versions +KIND_VERSION ?= v0.12.0 +KIND_NODE_IMAGE_TAG ?= v1.23.4 + +# ==================================================================================== # Setup Kubernetes tools + +UP_VERSION = v0.18.0 +UP_CHANNEL = stable -include build/makelib/k8s_tools.mk +# ==================================================================================== # Setup Images -DOCKER_REGISTRY ?= crossplane -IMAGES = $(PROJECT_NAME) $(PROJECT_NAME)-controller --include build/makelib/image.mk +IMAGES = provider-sql +-include build/makelib/imagelight.mk + + +# ==================================================================================== +# Setup XPKG + +XPKG_REG_ORGS ?= xpkg.upbound.io/crossplane-contrib index.docker.io/crossplanecontrib +# NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are +# inferred. +XPKG_REG_ORGS_NO_PROMOTE ?= xpkg.upbound.io/crossplane-contrib +XPKGS = provider-sql +-include build/makelib/xpkg.mk + +# NOTE(hasheddan): we force image building to happen prior to xpkg build so that +# we ensure image is present in daemon. +xpkg.build.provider-sql: do.build.images + +# ==================================================================================== +# Targets + +# run `make help` to see the targets and options + +# We want submodules to be set up the first time `make` is run. +# We manage the build/ folder and its Makefiles as a submodule. +# The first time `make` is run, the includes of build/*.mk files will +# all fail, and this target will be run. The next time, the default as defined +# by the includes will be run instead. fallthrough: submodules @echo Initial setup complete. Running make again . . . @make @@ -44,7 +89,7 @@ e2e.run: test-integration # Run integration tests. test-integration: $(KIND) $(KUBECTL) $(UP) $(HELM3) @$(INFO) running integration tests using kind $(KIND_VERSION) - @$(ROOT_DIR)/cluster/local/integration_tests.sh || $(FAIL) + @KIND_NODE_IMAGE_TAG=${KIND_NODE_IMAGE_TAG} $(ROOT_DIR)/cluster/local/integration_tests.sh || $(FAIL) @$(OK) integration tests passed # Update the submodules, such as the common build scripts. @@ -61,6 +106,11 @@ submodules: go.cachedir: @go env GOCACHE +# NOTE(hasheddan): we must ensure up is installed in tool cache prior to build +# as including the k8s_tools machinery prior to the xpkg machinery sets UP to +# point to tool cache. +build.init: $(UP) + # This is for running out-of-cluster locally, and is for convenience. Running # this make target will print out the command which was used. For more control, # try running the binary directly with different arguments. diff --git a/cluster/images/provider-sql-controller/Dockerfile b/cluster/images/provider-sql-controller/Dockerfile deleted file mode 100644 index eebabe8d..00000000 --- a/cluster/images/provider-sql-controller/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM BASEIMAGE -RUN apk --no-cache add ca-certificates bash - -ARG ARCH -ARG TINI_VERSION - -ADD provider /usr/local/bin/crossplane-sql-provider - -EXPOSE 8080 -USER 1001 -ENTRYPOINT ["crossplane-sql-provider"] diff --git a/cluster/images/provider-sql-controller/Makefile b/cluster/images/provider-sql-controller/Makefile deleted file mode 100755 index 4e4d474f..00000000 --- a/cluster/images/provider-sql-controller/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# ==================================================================================== -# Setup Project - -PLATFORMS := linux_amd64 linux_arm64 -include ../../../build/makelib/common.mk - -# ==================================================================================== -# Options -IMAGE = $(BUILD_REGISTRY)/provider-sql-controller-$(ARCH) -include ../../../build/makelib/image.mk - -# ==================================================================================== -# Targets - -img.build: - @$(INFO) docker build $(IMAGE) - @cp Dockerfile $(IMAGE_TEMP_DIR) || $(FAIL) - @cp $(OUTPUT_DIR)/bin/$(OS)_$(ARCH)/provider $(IMAGE_TEMP_DIR) || $(FAIL) - @cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|BASEIMAGE|$(OSBASEIMAGE)|g' Dockerfile || $(FAIL) - @docker build $(BUILD_ARGS) \ - --build-arg ARCH=$(ARCH) \ - --build-arg TINI_VERSION=$(TINI_VERSION) \ - -t $(IMAGE) \ - $(IMAGE_TEMP_DIR) || $(FAIL) - @$(OK) docker build $(IMAGE) diff --git a/cluster/images/provider-sql/Dockerfile b/cluster/images/provider-sql/Dockerfile index 332e7512..fce23c9c 100644 --- a/cluster/images/provider-sql/Dockerfile +++ b/cluster/images/provider-sql/Dockerfile @@ -1,3 +1,9 @@ -FROM BASEIMAGE +FROM gcr.io/distroless/static@sha256:1f580b0a1922c3e54ae15b0758b5747b260bd99d39d40c2edb3e7f6e2452298b -COPY package.yaml . +ARG TARGETOS +ARG TARGETARCH + +ADD bin/$TARGETOS\_$TARGETARCH/provider /usr/local/bin/crossplane-sql-provider + +USER 65532 +ENTRYPOINT ["crossplane-sql-provider"] diff --git a/cluster/images/provider-sql/Makefile b/cluster/images/provider-sql/Makefile index 734f0ab6..cfe2c3a4 100644 --- a/cluster/images/provider-sql/Makefile +++ b/cluster/images/provider-sql/Makefile @@ -1,28 +1,35 @@ # ==================================================================================== # Setup Project -PLATFORMS := linux_amd64 linux_arm64 include ../../../build/makelib/common.mk # ==================================================================================== # Options -IMAGE = $(BUILD_REGISTRY)/provider-sql-$(ARCH) -OSBASEIMAGE = scratch -include ../../../build/makelib/image.mk + +include ../../../build/makelib/imagelight.mk # ==================================================================================== # Targets img.build: @$(INFO) docker build $(IMAGE) + @$(MAKE) BUILD_ARGS="--load" img.build.shared + @$(OK) docker build $(IMAGE) + +img.publish: + @$(INFO) Skipping image publish for $(IMAGE) + @echo Publish is deferred to xpkg machinery + @$(OK) Image publish skipped for $(IMAGE) + +img.build.shared: @cp Dockerfile $(IMAGE_TEMP_DIR) || $(FAIL) - @cp -R ../../../package $(IMAGE_TEMP_DIR) || $(FAIL) - @cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|BASEIMAGE|$(OSBASEIMAGE)|g' Dockerfile || $(FAIL) - @cd $(IMAGE_TEMP_DIR) && $(SED_CMD) 's|VERSION|$(VERSION)|g' package/crossplane.yaml || $(FAIL) - @cd $(IMAGE_TEMP_DIR) && find package -type f -name '*.yaml' -exec cat {} >> 'package.yaml' \; -exec printf '\n---\n' \; || $(FAIL) - @docker build $(BUILD_ARGS) \ - --build-arg ARCH=$(ARCH) \ - --build-arg TINI_VERSION=$(TINI_VERSION) \ + @cp -r $(OUTPUT_DIR)/bin/ $(IMAGE_TEMP_DIR)/bin || $(FAIL) + @docker buildx build $(BUILD_ARGS) \ + --platform $(IMAGE_PLATFORMS) \ -t $(IMAGE) \ $(IMAGE_TEMP_DIR) || $(FAIL) - @$(OK) docker build $(IMAGE) + +img.promote: + @$(INFO) Skipping image promotion from $(FROM_IMAGE) to $(TO_IMAGE) + @echo Promote is deferred to xpkg machinery + @$(OK) Image promotion skipped for $(FROM_IMAGE) to $(TO_IMAGE) diff --git a/cluster/local/integration_tests.sh b/cluster/local/integration_tests.sh index 5f214516..34deabf5 100755 --- a/cluster/local/integration_tests.sh +++ b/cluster/local/integration_tests.sh @@ -41,13 +41,10 @@ eval $(make --no-print-directory -C ${projectdir} build.vars) # ------------------------------ SAFEHOSTARCH="${SAFEHOSTARCH:-amd64}" -BUILD_IMAGE="${BUILD_REGISTRY}/${PROJECT_NAME}-${SAFEHOSTARCH}" -PACKAGE_IMAGE="crossplane.io/inttests/${PROJECT_NAME}:${VERSION}" -CONTROLLER_IMAGE="${BUILD_REGISTRY}/${PROJECT_NAME}-controller-${SAFEHOSTARCH}" +CONTROLLER_IMAGE="${BUILD_REGISTRY}/${PROJECT_NAME}-${SAFEHOSTARCH}" version_tag="$(cat ${projectdir}/_output/version)" # tag as latest version to load into kind cluster -PACKAGE_CONTROLLER_IMAGE="${DOCKER_REGISTRY}/${PROJECT_NAME}-controller:${VERSION}" K8S_CLUSTER="${K8S_CLUSTER:-${BUILD_REGISTRY}-inttests}" CROSSPLANE_NAMESPACE="crossplane-system" @@ -69,12 +66,11 @@ echo_step "setting up local package cache" CACHE_PATH="${projectdir}/.work/inttest-package-cache" mkdir -p "${CACHE_PATH}" echo "created cache dir at ${CACHE_PATH}" -docker tag "${BUILD_IMAGE}" "${PACKAGE_IMAGE}" -"${UP}" xpkg xp-extract --from-daemon "${PACKAGE_IMAGE}" -o "${CACHE_PATH}/${PACKAGE_NAME}.gz" && chmod 644 "${CACHE_PATH}/${PACKAGE_NAME}.gz" - +"${UP}" alpha xpkg xp-extract --from-xpkg "${OUTPUT_DIR}"/xpkg/"${HOSTOS}"_"${SAFEHOSTARCH}"/"${PACKAGE_NAME}"-"${VERSION}".xpkg -o "${CACHE_PATH}/${PACKAGE_NAME}.gz" && chmod 644 "${CACHE_PATH}/${PACKAGE_NAME}.gz" # create kind cluster with extra mounts -echo_step "creating k8s cluster using kind" +KIND_NODE_IMAGE="kindest/node:${KIND_NODE_IMAGE_TAG}" +echo_step "creating k8s cluster using kind ${KIND_VERSION} and node image ${KIND_NODE_IMAGE}" KIND_CONFIG="$( cat <