|
1 | 1 | .DEFAULT_GOAL := help
|
2 | 2 |
|
| 3 | +# To customize the version of the image, consider setting the value of the |
| 4 | +# APP_VERSION variable. For example, to use the current git revision as a |
| 5 | +# version, use: |
| 6 | +# |
| 7 | +# APP_VERSION:=$(shell git rev-parse HEAD) |
| 8 | +# |
| 9 | +# At the command line this would read, for example: |
| 10 | +# |
| 11 | +# make \ |
| 12 | +# APP_VERSION=$(git rev-parse HEAD) \ |
| 13 | +# CONTAINERIZER=podman \ |
| 14 | +# ci_build_dockerimage_distroless |
| 15 | + |
| 16 | +# Make the image builder customizable so that we can use alternatives such as |
| 17 | +# podman to build these images. |
| 18 | +# |
| 19 | +# For example, in order to build the distroless image with podman, one can run |
| 20 | +# |
| 21 | +# make APP_VERSION=4.0.0 CONTAINERIZER=podman ci_build_dockerimage_distroless |
| 22 | +CONTAINERIZER:=docker |
| 23 | + |
| 24 | +# The latest available version of Alpine from https://hub.docker.com/_/golang |
| 25 | +ALPINE_VERSION:=3.20 |
| 26 | + |
| 27 | +# The latest release version of go to address security vulnerabilities. |
| 28 | +# See the latest version available at: https://hub.docker.com/_/golang |
| 29 | +GIMME_GO_VERSION:=1.22.5 |
| 30 | + |
| 31 | +# Should one wish to have the agent image be deployed from a custom artifact |
| 32 | +# registry such as the Google Artifact Registry (GAR), one may want to |
| 33 | +# customize this tag prefix appropriately. |
| 34 | +IMAGE_TAG_PREFIX:="optimizely/agent" |
| 35 | + |
3 | 36 | ci_build_static_binary: ## build static binary
|
4 | 37 | CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(GOBIN)/$(TARGET) cmd/optimizely/main.go
|
5 | 38 |
|
6 | 39 | ci_build_dockerimage: ## build minimal docker image of optimizely
|
7 |
| - docker build \ |
| 40 | + $(CONTAINERIZER) build \ |
8 | 41 | -f scripts/dockerfiles/Dockerfile.static \
|
9 |
| - -t optimizely/agent:${APP_VERSION} \ |
10 |
| - -t optimizely/agent:latest \ |
| 42 | + -t "${IMAGE_TAG_PREFIX}:${APP_VERSION}" \ |
| 43 | + -t "${IMAGE_TAG_PREFIX}:latest" \ |
11 | 44 | --build-arg GO_VERSION=${GIMME_GO_VERSION:.x=} \
|
12 | 45 | .
|
13 | 46 |
|
14 | 47 | ci_build_dockerimage_alpine: ## build alpine docker image of optimizely
|
15 |
| - docker build \ |
| 48 | + $(CONTAINERIZER) build \ |
16 | 49 | -f scripts/dockerfiles/Dockerfile.alpine \
|
17 |
| - -t optimizely/agent:${APP_VERSION}-alpine \ |
18 |
| - -t optimizely/agent:alpine \ |
| 50 | + -t "${IMAGE_TAG_PREFIX}:${APP_VERSION}-alpine" \ |
| 51 | + -t "${IMAGE_TAG_PREFIX}:alpine" \ |
19 | 52 | --build-arg GO_VERSION=${GIMME_GO_VERSION:.x=} \
|
| 53 | + --build-arg ALPINE_VERSION=${ALPINE_VERSION:.x=} \ |
20 | 54 | .
|
| 55 | + |
| 56 | +# Distroless images are tiny, have small attack surface, and security-oriented |
| 57 | +# deployments may consider using them. |
| 58 | +# |
| 59 | +# For more information about distroless, please see: |
| 60 | +# https://github.com/GoogleContainerTools/distroless |
| 61 | +ci_build_dockerimage_distroless: ## build distroless image of optimizely |
| 62 | + $(CONTAINERIZER) build \ |
| 63 | + -f scripts/dockerfiles/Dockerfile.distroless \ |
| 64 | + -t "${IMAGE_TAG_PREFIX}:${APP_VERSION}-distroless" \ |
| 65 | + -t "${IMAGE_TAG_PREFIX}:distroless" \ |
| 66 | + --build-arg GO_VERSION=${GIMME_GO_VERSION:.x=} \ |
| 67 | + . |
| 68 | + |
| 69 | +# PHONY target to build all of the above container images. |
| 70 | +_ci_build_dockerimage_all: ci_build_dockerimage ci_build_dockerimage_alpine ci_build_dockerimage_distroless |
| 71 | +ci_build_dockerimage_all: _ci_build_dockerimage_all ## build all container images |
| 72 | + |
| 73 | +push_image: ## push container image |
| 74 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:${APP_VERSION}" |
| 75 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:latest" |
| 76 | + |
| 77 | +push_image_alpine: ## push alpine container image |
| 78 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:${APP_VERSION}-alpine" |
| 79 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:alpine" |
| 80 | + |
| 81 | +push_image_distroless: ## push distroless container image |
| 82 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:${APP_VERSION}-distroless" |
| 83 | + $(CONTAINERIZER) push "${IMAGE_TAG_PREFIX}:distroless" |
| 84 | + |
| 85 | +push_all_images: push_image push_image_alpine push_image_distroless ## push all container images |
0 commit comments