From f9133ae543b8348e344715473ea1f5ec5aa5ea79 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Tue, 27 Aug 2019 09:04:32 -0700 Subject: [PATCH] :sparkles: Add github action to push on master merge Signed-off-by: Vince Prignano --- .github/workflows/main.yml | 33 +++++++++++++++++++++++ Dockerfile | 3 ++- Makefile | 46 ++++++++++++++++----------------- cmd/example-provider/Dockerfile | 3 ++- scripts/ci-integration.sh | 2 +- 5 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000000..691ea5ddf4d0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: + - master + +jobs: + latest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: GCR Setup + uses: actions/gcloud/auth@master + env: + GCLOUD_AUTH: ${{ secrets.GCLOUD_AUTH }} + + - name: GCR Auth + uses: actions/gcloud/cli@master + with: + args: "auth configure-docker -q" + + - name: Build and push container images + uses: actions/gcloud/cli@master + env: + REGISTRY: gcr.io/k8s-staging-cluster-api + with: + entrypoint: /bin/bash + args: | + -c "apt-get -y update && \ + apt-get -y --no-install-recommends install build-essential && \ + make docker-build-all docker-push-all" diff --git a/Dockerfile b/Dockerfile index 00068505d0a0..717bc3f85575 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ # Build the manager binary FROM golang:1.12.9 as builder -ARG ARCH +ENV GOPROXY=https://proxy.golang.org WORKDIR /workspace # Copy the Go Modules manifests @@ -29,6 +29,7 @@ RUN go mod download COPY ./ ./ # Build +ARG ARCH RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ go build -a -ldflags '-extldflags "-static"' \ -o manager . diff --git a/Makefile b/Makefile index 15e765ef70cb..7db136f3a372 100644 --- a/Makefile +++ b/Makefile @@ -46,11 +46,9 @@ GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint # Define Docker related variables. Releases should modify and double check these vars. REGISTRY ?= gcr.io/$(shell gcloud config get-value project) CONTROLLER_IMG ?= $(REGISTRY)/cluster-api-controller -EXAMPLE_PROVIDER_IMG ?= $(REGISTRY)/example-provider-controller TAG ?= dev ARCH ?= amd64 ALL_ARCH = amd64 arm arm64 ppc64le s390x -GOOS ?= linux all: test manager clusterctl @@ -144,33 +142,23 @@ docker-build: ## Build the docker image for controller-manager docker-push: ## Push the docker image docker push $(CONTROLLER_IMG)-$(ARCH):$(TAG) -.PHONY: all-docker-build -all-docker-build: $(addprefix sub-docker-build-,$(ALL_ARCH)) - @echo "updating kustomize image patch file for manager resource" - hack/sed.sh -i.tmp -e 's@image: .*@image: '"$(CONTROLLER_IMG):$(TAG)"'@' ./config/default/manager_image_patch.yaml +## -------------------------------------- +## Docker — All ARCH +## -------------------------------------- -sub-docker-build-%: - $(MAKE) ARCH=$* docker-build +.PHONY: docker-build-all ## Build all the architecture docker images +docker-build-all: $(addprefix docker-build-,$(ALL_ARCH)) -.PHONY:all-push ## Push all the architecture docker images and fat manifest docker image -all-push: all-docker-push docker-push-manifest +docker-build-%: + $(MAKE) ARCH=$* docker-build -.PHONY:all-docker-push ## Push all the architecture docker images -all-docker-push: $(addprefix sub-docker-push-,$(ALL_ARCH)) +.PHONY: docker-push-all ## Push all the architecture docker images +docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) + $(MAKE) docker-push-manifest -sub-docker-push-%: +docker-push-%: $(MAKE) ARCH=$* docker-push -.PHONY: docker-build-ci -docker-build-ci: generate lint-full ## Build the docker image for example provider - docker build --pull --build-arg ARCH=$(ARCH) . -f ./cmd/example-provider/Dockerfile -t $(EXAMPLE_PROVIDER_IMG)-$(ARCH):$(TAG) - @echo "updating kustomize image patch file for ci" - hack/sed.sh -i.tmp -e 's@image: .*@image: '"${EXAMPLE_PROVIDER_IMG}-$(ARCH):$(TAG)"'@' ./config/ci/manager_image_patch.yaml - -.PHONY: docker-push-ci -docker-push-ci: docker-build-ci ## Build the docker image for ci - docker push "$(EXAMPLE_PROVIDER_IMG)-$(ARCH):$(TAG)" - .PHONY: docker-push-manifest docker-push-manifest: ## Push the fat manifest docker image. ## Minimum docker version 18.06.0 is required for creating and pushing manifest images. @@ -178,6 +166,18 @@ docker-push-manifest: ## Push the fat manifest docker image. @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${TAG} ${CONTROLLER_IMG}-$${arch}:${TAG}; done docker manifest push --purge ${CONTROLLER_IMG}:${TAG} +## -------------------------------------- +## Docker - Example Provider +## -------------------------------------- + +EXAMPLE_PROVIDER_IMG ?= $(REGISTRY)/example-provider-controller + +.PHONY: docker-build-example-provider +docker-build-example-provider: generate lint-full ## Build the docker image for example provider + docker build --pull --build-arg ARCH=$(ARCH) . -f ./cmd/example-provider/Dockerfile -t $(EXAMPLE_PROVIDER_IMG)-$(ARCH):$(TAG) + @echo "updating kustomize image patch file for ci" + hack/sed.sh -i.tmp -e 's@image: .*@image: '"${EXAMPLE_PROVIDER_IMG}-$(ARCH):$(TAG)"'@' ./config/ci/manager_image_patch.yaml + ## -------------------------------------- ## Cleanup / Verification ## -------------------------------------- diff --git a/cmd/example-provider/Dockerfile b/cmd/example-provider/Dockerfile index 5a3ff737e4c4..84b4320d1e23 100644 --- a/cmd/example-provider/Dockerfile +++ b/cmd/example-provider/Dockerfile @@ -15,7 +15,7 @@ # Build the manager binary FROM golang:1.12.9 as builder -ARG ARCH +ENV GOPROXY=https://proxy.golang.org WORKDIR /workspace # Copy the Go Modules manifests @@ -29,6 +29,7 @@ RUN go mod download COPY ./ ./ # Build +ARG ARCH=amd64 RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ go build -a -ldflags '-extldflags "-static"' \ -o manager sigs.k8s.io/cluster-api/cmd/example-provider diff --git a/scripts/ci-integration.sh b/scripts/ci-integration.sh index 66c21ee7b19d..950c2640b24f 100755 --- a/scripts/ci-integration.sh +++ b/scripts/ci-integration.sh @@ -58,7 +58,7 @@ build_containers() { export EXAMPLE_PROVIDER_IMG="${EXAMPLE_PROVIDER_REPO}" "${MAKE}" docker-build TAG="${VERSION}" ARCH="${GOARCH}" - "${MAKE}" docker-build-ci TAG="${VERSION}" ARCH="${GOARCH}" + "${MAKE}" docker-build-example-provider TAG="${VERSION}" ARCH="${GOARCH}" } prepare_crd_yaml() {