Skip to content

Commit

Permalink
Refactor docker/* targets in Makefile (#1028)
Browse files Browse the repository at this point in the history
* Refactor docker/* targets in Makefile

Signed-off-by: Gábor Lipták <[email protected]>

* Add sync help

Signed-off-by: Gábor Lipták <[email protected]>

---------

Signed-off-by: Gábor Lipták <[email protected]>
  • Loading branch information
gliptak authored Mar 13, 2024
1 parent bb48f38 commit c473e2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
docker version -f '{{.Server.Experimental}}'
- name: build_docker
run: make build_prod_images
run: make build
78 changes: 40 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ help: ## Display this help
# This recipe builds and pushes images for production. Note: RELEASE_TAG must be set
#
.PHONY: cloudbuild
cloudbuild: require_release_tag push_prod_images ## Build and push images
cloudbuild: require_release_tag push ## Build and push images

.PHONY: require_release_tag
require_release_tag:
Expand All @@ -43,78 +43,80 @@ endif
#
# These recipes build all the top-level docker images

build_%_image:
build/image/%:
@# if TAG is 'latest', the two -t arguments are equivalent and do the same thing
docker build $(BUILD_ARG) -t ${REGISTRY}/$(IMAGE_NAME) -t ${REGISTRY}/$(IMAGE_NAME):$(TAG) -f $(DOCKERFILE) $(DIR)

#
# These recipes build the sandbox images.
#
build_%_sandbox:
build/sandbox/%:
@# if TAG is 'latest', the two -t arguments are equivalent and do the same thing
docker build -t ${REGISTRY}/$(IMAGE_NAME) -t ${REGISTRY}/$(IMAGE_NAME):$(TAG) -f $(DOCKERFILE) $(DIR)

build_analysis_image: DIR=$(PREFIX)
build_analysis_image: DOCKERFILE=$(PREFIX)/cmd/analyze/Dockerfile
build_analysis_image: IMAGE_NAME=analysis
build/image/analysis: DIR=$(PREFIX)
build/image/analysis: DOCKERFILE=$(PREFIX)/cmd/analyze/Dockerfile
build/image/analysis: IMAGE_NAME=analysis

build_scheduler_image: DIR=$(PREFIX)
build_scheduler_image: DOCKERFILE=$(PREFIX)/cmd/scheduler/Dockerfile
build_scheduler_image: IMAGE_NAME=scheduler
build/image/scheduler: DIR=$(PREFIX)
build/image/scheduler: DOCKERFILE=$(PREFIX)/cmd/scheduler/Dockerfile
build/image/scheduler: IMAGE_NAME=scheduler

build_static_analysis_sandbox: DIR=$(PREFIX)
build_static_analysis_sandbox: DOCKERFILE=$(SANDBOX_DIR)/staticanalysis/Dockerfile
build_static_analysis_sandbox: IMAGE_NAME=static-analysis
build/sandbox/static_analysis: DIR=$(PREFIX)
build/sandbox/static_analysis: DOCKERFILE=$(SANDBOX_DIR)/staticanalysis/Dockerfile
build/sandbox/static_analysis: IMAGE_NAME=static-analysis

build_dynamic_analysis_sandbox: DIR=$(SANDBOX_DIR)/dynamicanalysis
build_dynamic_analysis_sandbox: DOCKERFILE=$(SANDBOX_DIR)/dynamicanalysis/Dockerfile
build_dynamic_analysis_sandbox: IMAGE_NAME=dynamic-analysis
build/sandbox/dynamic_analysis: DIR=$(SANDBOX_DIR)/dynamicanalysis
build/sandbox/dynamic_analysis: DOCKERFILE=$(SANDBOX_DIR)/dynamicanalysis/Dockerfile
build/sandbox/dynamic_analysis: IMAGE_NAME=dynamic-analysis

.PHONY: build_prod_images
build_prod_images: build_dynamic_analysis_sandbox build_static_analysis_sandbox build_analysis_image build_scheduler_image ## Build images
.PHONY: build
build: build/sandbox/dynamic_analysis build/sandbox/static_analysis build/image/analysis build/image/scheduler ## Build images

#
# Builds then pushes analysis and sandbox images
#

push_%:
push/image/%:
docker push --all-tags ${REGISTRY}/$(IMAGE_NAME)

push_analysis_image: IMAGE_NAME=analysis
push_analysis_image: build_analysis_image
push/sandbox/%:
docker push --all-tags ${REGISTRY}/$(IMAGE_NAME)

push_scheduler_image: IMAGE_NAME=scheduler
push_scheduler_image: build_scheduler_image
push/image/analysis: IMAGE_NAME=analysis
push/image/analysis: build/image/analysis

push_dynamic_analysis_sandbox: IMAGE_NAME=dynamic-analysis
push_dynamic_analysis_sandbox: build_dynamic_analysis_sandbox
push/image/scheduler: IMAGE_NAME=scheduler
push/image/scheduler: build/image/scheduler

push_static_analysis_sandbox: IMAGE_NAME=static-analysis
push_static_analysis_sandbox: build_static_analysis_sandbox
push/sandbox/dynamic_analysis: IMAGE_NAME=dynamic-analysis
push/sandbox/dynamic_analysis: build/sandbox/dynamic_analysis

.PHONY: push_prod_sandboxes
push_prod_sandboxes: push_dynamic_analysis_sandbox push_static_analysis_sandbox
push/sandbox/static_analysis: IMAGE_NAME=static-analysis
push/sandbox/static_analysis: build/sandbox/static_analysis

.PHONY: push_prod_images
push_prod_images: push_prod_sandboxes push_analysis_image push_scheduler_image ## Push production images
.PHONY: push/prod_sandboxes
push/prod_sandboxes: push/sandbox/dynamic_analysis push/sandbox/static_analysis

.PHONY: push
push: push/prod_sandboxes push/image/analysis push/image/scheduler ## Push production images

#
# These update (sync) locally built sandbox images from Docker to
# podman. In order to use locally built sandbox images for analysis,
# pass '-nopull' to scripts/run_analysis.sh
#
sync_%_sandbox:
sync/sandbox/%:
docker save ${REGISTRY}/${IMAGE_NAME}:$(TAG) | sudo podman load

sync_dynamic_analysis_sandbox: IMAGE_NAME=dynamic-analysis
sync_dynamic_analysis_sandbox: build_dynamic_analysis_sandbox
sync/sandbox/dynamic_analysis: IMAGE_NAME=dynamic-analysis
sync/sandbox/dynamic_analysis: build/sandbox/dynamic_analysis

sync_static_analysis_sandbox: IMAGE_NAME=static-analysis
sync_static_analysis_sandbox: build_static_analysis_sandbox
sync/sandbox/static_analysis: IMAGE_NAME=static-analysis
sync/sandbox/static_analysis: build/sandbox/static_analysis

.PHONY: sync_prod_sandboxes
sync_prod_sandboxes: sync_dynamic_analysis_sandbox sync_static_analysis_sandbox
.PHONY: sync
sync: sync/sandbox/dynamic_analysis sync/sandbox/static_analysis ## Sync prod sandboxes


#
Expand Down Expand Up @@ -175,7 +177,7 @@ e2e_test_logs_analysis:

.PHONY: build_e2e_test_images
build_e2e_test_images: TAG=test
build_e2e_test_images: sync_prod_sandboxes build_analysis_image build_scheduler_image
build_e2e_test_images: sync build/image/analysis build/image/scheduler



Expand Down

0 comments on commit c473e2d

Please sign in to comment.