Skip to content

Commit

Permalink
✨ Add github action to push on master merge
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information
vincepri committed Aug 28, 2019
1 parent 80572d3 commit f9133ae
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
Expand Down
46 changes: 23 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -144,40 +142,42 @@ 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.
docker manifest create --amend $(CONTROLLER_IMG):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(TAG)~g")
@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
## --------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion cmd/example-provider/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f9133ae

Please sign in to comment.