Skip to content

Commit

Permalink
build hygiene (kubernetes#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qing Hao authored and GitHub Enterprise committed Jul 9, 2019
1 parent c53daa9 commit f7ea317
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 117 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ install:
- docker info

before_script:
# - make deps lint
- make init
- make docker-login

script:
# - make fmt test coverage openresty image
- make fmt openresty image
- make docker-binary
- make image:all

after_success:
- test "$TRAVIS_EVENT_TYPE" != "pull_request" && make release || echo "success"
- test "$TRAVIS_EVENT_TYPE" != "pull_request" && make image:release || echo "success"
26 changes: 7 additions & 19 deletions Configfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
GIT_REMOTE_URL = $(shell git config --get remote.origin.url)
DOCKER_SERVER ?= hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com
DOCKER_USERNAME ?=
DOCKER_PASSWORD ?=
IMAGE_DESCRIPTION = IBM Cloud Private management-ingrss image
IMAGE_NAME = icp-management-ingress
IMAGE_REPO ?= hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com/ibmcom
RELEASE_TAG ?= latest
ARCH = $(shell uname -m)
DOCKER_FLAG =
OPENRESTY_VERSION ?= 1.13.6.2
IMAGE_DESCRIPTION = IBM Cloud Private management-ingress image
IMAGE_VENDOR=IBM
IMAGE_SUMMARY=$(IMAGE_DESCRIPTION)

ifeq ($(ARCH), x86_64)
IMAGE_NAME_ARCH = $(IMAGE_NAME)-amd64
else
IMAGE_NAME_ARCH = $(IMAGE_NAME)-$(ARCH)
endif

MANIFEST_VERSION ?= v0.7.0

OPENRESTY_VERSION ?= 1.13.6.2
RELEASE_TAG ?= latest
DOCKER_REGISTRY ?= hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com
DOCKER_NAMESPACE ?= ibmcom
DOCKER_USER ?=
DOCKER_PASS ?=
GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ docker-binary:
CGO_ENABLED=0 go build -a -installsuffix cgo -v -i -o rootfs/icp-management-ingress github.ibm.com/IBMPrivateCloud/icp-management-ingress/cmd/nginx
strip rootfs/icp-management-ingress

image:: docker-binary

test:
@./build/test.sh

Expand Down
149 changes: 57 additions & 92 deletions Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,109 +18,74 @@
# created with the command `bx cr token-add --description "" --non-expiring --readwrite`
###############################################################################

.DEFAULT_GOAL=image
.DEFAULT_GOAL=image:all

BASE_IMAGE?=local/openresty:$(OPENRESTY_VERSION)
BASE_IMAGE_RHEL?=hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com/ibmcom/openresty:$(OPENRESTY_VERSION)-rhel
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_REMOTE_URL = $(shell git config --get remote.origin.url)
GITHUB_USER := $(shell echo $(GITHUB_USER) | sed 's/@/%40/g')
GITHUB_TOKEN ?=

.PHONY: docker-login
docker-login:
ifndef $(and DOCKER_USERNAME, DOCKER_PASSWORD)
$(error DOCKER_USERNAME and DOCKER_PASSWORD must be defined, required for goal (docker-login))
endif
@docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD) $(DOCKER_SERVER)
WORKING_CHANGES := $(shell git status --porcelain)
BUILD_DATE := $(shell date +%m/%d@%H:%M:%S)
VCS_REF := $(if $(WORKING_CHANGES),$(GIT_COMMIT)-$(BUILD_DATE),$(GIT_COMMIT))
APP_VERSION ?= $(if $(shell cat VERSION 2> /dev/null),$(shell cat VERSION 2> /dev/null),0.0.1)

.PHONY: app-version
app-version:
$(eval WORKING_CHANGES := $(shell git status --porcelain))
$(eval BUILD_DATE := $(shell date +%m/%d@%H:%M:%S))
$(eval GIT_COMMIT := $(shell git rev-parse --short HEAD))
$(eval VCS_REF := $(if $(WORKING_CHANGES),$(GIT_COMMIT)-$(BUILD_DATE),$(GIT_COMMIT)))
$(eval APP_VERSION ?= $(if $(shell cat VERSION 2> /dev/null),$(shell cat VERSION 2> /dev/null),0.0.1))
$(eval IMAGE_VERSION ?= $(APP_VERSION)-$(GIT_COMMIT))
@echo "App: $(IMAGE_NAME_ARCH) $(IMAGE_VERSION)"
BASE_IMAGE_NAME = openresty
BASE_IMAGE_TAG = $(OPENRESTY_VERSION)
BASE_IMAGE_DOCKER_FILE = docker/openresty/$(OPENRESTY_VERSION)/alpine/Dockerfile$(DOCKER_FILE_SUFFIX)

.PHONY: check-env
check-env:
ifndef IMAGE_REPO
$(error IMAGE_REPO is undefined)
endif
ifndef IMAGE_NAME
$(error IMAGE_NAME is undefined)
endif
IMAGE_NAME ?= icp-management-ingress
IMAGE_VERSION ?= $(APP_VERSION)-$(GIT_COMMIT)
RELEASE_TAG ?= latest

ifneq ($(ARCH), x86_64)
$(eval DOCKER_FILE_SUFFIX = .$(ARCH))
@echo "DOCKER_FILE_SUFFIX: $(DOCKER_FILE_SUFFIX)"
endif
DOCKER_IMAGE = $(IMAGE_NAME)
DOCKER_IMAGE_ARCH = $(DOCKER_IMAGE)-$(BUILD_HARNESS_ARCH)
DOCKER_BUILD_TAG = $(IMAGE_VERSION)
DOCKER_TAG = $(RELEASE_TAG)
DOCKER_FILE ?= Dockerfile$(DOCKER_FILE_SUFFIX)
DOCKER_BUILD_OPTS = --build-arg "VCS_REF=$(VCS_REF)" --build-arg "VCS_URL=$(GIT_REMOTE_URL)" --build-arg "IMAGE_NAME=$(IMAGE_NAME)-$(BUILD_HARNESS_ARCH)" --build-arg "IMAGE_DESCRIPTION=$(IMAGE_DESCRIPTION)" --build-arg "ARCH_TYPE=$(BUILD_HARNESS_ARCH)"

.PHONY: openresty
openresty: check-env
docker build -t $(BASE_IMAGE) \
$(DOCKER_FLAG) -f docker/openresty/$(OPENRESTY_VERSION)/alpine/Dockerfile$(DOCKER_FILE_SUFFIX) .
# travis doesn't have rhel build machine, build it in local rhel.
# docker build -t $(BASE_IMAGE_RHEL) \
# $(DOCKER_FLAG) -f docker/openresty/$(OPENRESTY_VERSION)/rhel/Dockerfile$(DOCKER_FILE_SUFFIX) .
.PHONY: init\:
init::
@mkdir -p variables
ifndef GITHUB_USER
$(info GITHUB_USER not defined)
exit -1
endif
$(info Using GITHUB_USER=$(GITHUB_USER))
ifndef GITHUB_TOKEN
$(info GITHUB_TOKEN not defined)
exit -1
endif

.PHONY: image
image:: check-env app-version
sed -i 's|BASE_IMAGE|$(BASE_IMAGE)|g' Dockerfile$(DOCKER_FILE_SUFFIX)
docker build -t $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) \
--build-arg "VCS_REF=$(VCS_REF)" \
--build-arg "VCS_URL=$(GIT_REMOTE_URL)" \
--build-arg "IMAGE_NAME=$(IMAGE_NAME_ARCH)" \
--build-arg "IMAGE_DESCRIPTION=$(IMAGE_DESCRIPTION)" $(DOCKER_FLAG) -f Dockerfile$(DOCKER_FILE_SUFFIX) .
#ifeq ($(ARCH), x86_64)
# sed -i 's|BASE_IMAGE|$(BASE_IMAGE_RHEL)|g' Dockerfile.rhel
# docker build -t $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION)-rhel \
# --build-arg "VCS_REF=$(VCS_REF)" \
# --build-arg "VCS_URL=$(GIT_REMOTE_URL)" \
# --build-arg "IMAGE_NAME=$(IMAGE_NAME_ARCH)" \
# --build-arg "IMAGE_DESCRIPTION=$(IMAGE_DESCRIPTION)" $(DOCKER_FLAG) -f Dockerfile.rhel .
#endif
-include $(shell curl -fso .build-harness -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3.raw" "https://raw.github.ibm.com/ICP-DevOps/build-harness/master/templates/Makefile.build-harness"; echo .build-harness)

.PHONY: push
push: check-env app-version
docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION)
#ifeq ($(ARCH), x86_64)
# docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION)-rhel
#endif
.PHONY: docker-login
docker-login::
@$(SELF) -s docker:login

.PHONY: release
release: check-env app-version
docker tag $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)
docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)
ifeq ($(ARCH), x86_64)
docker tag $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)-rhel
docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)-rhel
endif
.PHONY: image\:all
image\:all: %image\:all: %image\:info %image\:build %image\:tag

.PHONY: show-labels
show-labels: app-version
@docker inspect $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) --format='{{json .Config.Labels}}' | tr , '\n' | tr -d '{' | tr -d '}'
.PHONY: image\:build
image\:build: %image\:build:
@echo "Building openresty image"
@$(SELF) -s docker:build DOCKER_IMAGE=$(BASE_IMAGE_NAME) DOCKER_BUILD_TAG=$(BASE_IMAGE_TAG) DOCKER_FILE=$(BASE_IMAGE_DOCKER_FILE)
@echo "Building icp-management-ingress image"
sed -i 's|BASE_IMAGE|$(BASE_IMAGE_NAME):$(BASE_IMAGE_TAG)|g' Dockerfile$(DOCKER_FILE_SUFFIX)
@$(SELF) -s docker:build

.PHONY: manifest-tool
manifest-tool::
ifeq ($(ARCH), x86_64)
$(eval MANIFEST_TOOL_NAME = manifest-tool-linux-amd64)
else
$(eval MANIFEST_TOOL_NAME = manifest-tool-linux-$(ARCH))
endif
sudo curl -sSL -o /usr/local/bin/manifest-tool https://github.com/estesp/manifest-tool/releases/download/$(MANIFEST_VERSION)/$(MANIFEST_TOOL_NAME)
sudo chmod +x /usr/local/bin/manifest-tool
.PHONY: image\:info
image\:info: %image\:info:
@$(SELF) -s docker:info

.PHONY: s390x-fix
s390x-fix::
manifest-tool inspect $(IMAGE_NAME_S390X) \
|| (docker pull $(DEFAULT_S390X_IMAGE) \
&& docker tag $(DEFAULT_S390X_IMAGE) $(IMAGE_NAME_S390X) \
&& docker push $(IMAGE_NAME_S390X))
.PHONY: image\:tag
image\:tag: %image\:tag:
@$(SELF) -s docker:tag-arch

multi-arch:: s390x-fix
cp manifest.yaml /tmp/manifest.yaml
sed -i -e "s|__RELEASE_TAG__|$(RELEASE_TAG)|g" -e "s|__IMAGE_NAME__|$(IMAGE_NAME)|g" -e "s|__IMAGE_REPO__|$(IMAGE_REPO)|g" /tmp/manifest.yaml
manifest-tool push from-spec /tmp/manifest.yaml
.PHONY: image\:push
image\:push: %image\:push:
@$(SELF) -s docker:push-arch

.PHONY: clean
clean::
@echo "Cleaning up generated files"
.PHONY: image\:release
image\:release: %image\:release: %image\:push

0 comments on commit f7ea317

Please sign in to comment.