Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduces builder images #590

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ defaults:
name: "Install latest Golang"
command: |
sudo rm -rf /usr/local/go
sudo circleci-install golang 1.15.5
sudo circleci-install golang 1.14.7
docker:
- image: &golang-img cimg/go:1.15.5
- image: &golang-img cimg/go:1.14.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.14.7?

machine-conf: &machine-conf
image: ubuntu-1604:201903-01
skip-e2e-check: &skip-e2e-check
Expand Down
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github/
.circleci/
vendor/
docs/

32 changes: 17 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ GOOS?=$(shell echo $(OS) | awk '{print tolower($$0)}')
GOARCH:=amd64

BUILD_TIME=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GITUNTRACKEDCHANGES:=$(shell git status --porcelain --untracked-files=no)
COMMIT:=$(shell git rev-parse --short HEAD)
ifneq ($(GITUNTRACKEDCHANGES),)
GITUNTRACKEDCHANGES?=$(shell git status --porcelain --untracked-files=no | wc -l)
COMMIT?=$(shell git rev-parse --short HEAD)
ifneq ($(GITUNTRACKEDCHANGES),0)
COMMIT:=$(COMMIT)-dirty
endif

Expand Down Expand Up @@ -230,15 +230,17 @@ export IKE_VERSION
IMG_BUILDER:=docker

## Prefer to use podman
ifneq (, $(shell which podman))
ifneq (, $(shell which podman))
IMG_BUILDER=podman
endif
endif

.PHONY: docker-build
docker-build: GOOS=linux
docker-build: compile ## Builds the docker image
$(call header,"Building docker image $(IKE_IMAGE_NAME)")
docker-build: ## Builds container images
$(call header,"Building image $(IKE_IMAGE_NAME)")
$(IMG_BUILDER) build \
--no-cache \
--network=host \
--label "org.opencontainers.image.title=$(IKE_IMAGE_NAME)" \
--label "org.opencontainers.image.description=Tool enabling developers to safely develop and test on any kubernetes cluster without distracting others." \
--label "org.opencontainers.image.source=https://$(PACKAGE_NAME)" \
Expand All @@ -248,28 +250,29 @@ docker-build: compile ## Builds the docker image
--label "org.opencontainers.image.vendor=Red Hat, Inc." \
--label "org.opencontainers.image.revision=$(COMMIT)" \
--label "org.opencontainers.image.created=$(shell date -u +%F\ %T%z)" \
--network=host \
-t $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(IKE_IMAGE_TAG) \
-f $(BUILD_DIR)/Dockerfile $(PROJECT_DIR)

$(IMG_BUILDER) tag \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(IKE_IMAGE_TAG) \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):latest

.PHONY: docker-push
docker-push: docker-push--latest docker-push-versioned ## Pushes docker images to the registry
docker-push: docker-push--latest docker-push-versioned ## Pushes images to the registry

docker-push-versioned: docker-push--$(IKE_IMAGE_TAG)

docker-push--%:
$(eval image_tag:=$(subst docker-push--,,$@))
$(call header,"Pushing docker image $(image_tag)")
$(call header,"Pushing image $(image_tag)")
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(image_tag)

.PHONY: docker-build-test
docker-build-test: $(BINARY_DIR)/$(TEST_BINARY_NAME)
$(call header,"Building docker image $(IKE_TEST_IMAGE_NAME)")
$(call header,"Building image $(IKE_TEST_IMAGE_NAME)")
$(IMG_BUILDER) build \
--no-cache \
--network=host \
--label "org.opencontainers.image.title=$(IKE_TEST_IMAGE_NAME)" \
--label "org.opencontainers.image.description=Test Services for end-to-end testing of the $(IKE_IMAGE_NAME)" \
--label "org.opencontainers.image.source=https://$(PACKAGE_NAME)" \
Expand All @@ -279,7 +282,6 @@ docker-build-test: $(BINARY_DIR)/$(TEST_BINARY_NAME)
--label "org.opencontainers.image.vendor=Red Hat, Inc." \
--label "org.opencontainers.image.revision=$(COMMIT)" \
--label "org.opencontainers.image.created=$(shell date -u +%F\ %T%z)" \
--network=host \
--tag $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_TEST_IMAGE_NAME):$(IKE_IMAGE_TAG) \
-f $(BUILD_DIR)/DockerfileTest $(PROJECT_DIR)

Expand All @@ -289,13 +291,13 @@ docker-build-test: $(BINARY_DIR)/$(TEST_BINARY_NAME)

.PHONY: docker-push-test
docker-push-test:
$(call header,"Pushing docker image $(IKE_TEST_IMAGE_NAME)")
$(call header,"Pushing image $(IKE_TEST_IMAGE_NAME)")
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_TEST_IMAGE_NAME):$(IKE_IMAGE_TAG)
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_TEST_IMAGE_NAME):latest

.PHONY: docker-build-test-prepared
docker-build-test-prepared:
$(call header,"Building docker image $(IKE_TEST_PREPARED_IMAGE_NAME)")
$(call header,"Building image $(IKE_TEST_PREPARED_IMAGE_NAME)")
$(IMG_BUILDER) build \
--no-cache \
--build-arg=name=$(IKE_TEST_PREPARED_NAME) \
Expand All @@ -318,7 +320,7 @@ docker-build-test-prepared:

.PHONY: docker-push-test-prepared
docker-push-test-prepared:
$(call header,"Pushing docker image $(IKE_TEST_PREPARED_IMAGE_NAME)")
$(call header,"Pushing image $(IKE_TEST_PREPARED_IMAGE_NAME)")
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_TEST_PREPARED_IMAGE_NAME)-$(IKE_TEST_PREPARED_NAME):$(IKE_IMAGE_TAG)
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_TEST_PREPARED_IMAGE_NAME)-$(IKE_TEST_PREPARED_NAME):latest

Expand Down
18 changes: 17 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
FROM registry.access.redhat.com/ubi8/go-toolset:1.14.7 AS builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we require 1.16.x now due to the fs thinggy?


USER 0

RUN mkdir -p /opt/app-root/src/go/github.com/maistra/istio-workspace/

WORKDIR /opt/app-root/src/go/github.com/maistra/istio-workspace/

COPY . .

ENV GOBIN=/opt/app-root/src/go/bin/

## GOROOT needs to be set explictly. see https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525169969
RUN GOROOT=$(go env GOROOT) GOPATH=$(go env GOPATH) PATH="${PATH}:${GOPATH}/bin" make deps tools compile

## Controller image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3

ADD dist/ike /usr/local/bin/ike
COPY --from=builder /opt/app-root/src/go/github.com/maistra/istio-workspace/dist/ike /usr/local/bin/
15 changes: 15 additions & 0 deletions build/DockerfileTest
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
FROM registry.access.redhat.com/ubi8/go-toolset:1.14.7 AS builder

USER 0

RUN mkdir -p /opt/app-root/src/go/github.com/maistra/istio-workspace/

WORKDIR /opt/app-root/src/go/github.com/maistra/istio-workspace/

COPY . .

ENV GOBIN=/opt/app-root/src/go/bin/

## GOROOT needs to be set explictly. see https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525169969
RUN GOROOT=$(go env GOROOT) GOPATH=$(go env GOPATH) PATH="${PATH}:${GOPATH}/bin" make deps tools compile-test-service

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3

ADD dist/test-service /usr/local/bin/test-service
Expand Down