-
Notifications
You must be signed in to change notification settings - Fork 18
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: Use docker or podman to build and run #88
Changes from 3 commits
35d998f
ecb0eb9
1bc49b8
55d2b04
0d6723c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,16 @@ LDFLAGS += -X github.com/konveyor/${BINNAME}/cmd/version.gitCommit=${GIT_COMMIT} | |
LDFLAGS += -X github.com/konveyor/${BINNAME}/cmd/version.gitTreeState=${GIT_DIRTY} | ||
LDFLAGS += -extldflags "-static" | ||
|
||
# Setting container tool | ||
DOCKER_CMD := $(shell command -v docker 2> /dev/null) | ||
PODMAN_CMD := $(shell command -v podman 2> /dev/null) | ||
|
||
ifdef DOCKER_CMD | ||
CONTAINER_TOOL = 'docker' | ||
else ifdef PODMAN_CMD | ||
CONTAINER_TOOL = 'podman' | ||
endif | ||
|
||
# HELP | ||
# This will output the help for each task | ||
.PHONY: help | ||
|
@@ -190,21 +200,43 @@ info: ## Get version info | |
@echo "Git Commit: ${GIT_COMMIT}" | ||
@echo "Git Tree State: ${GIT_DIRTY}" | ||
|
||
# -- Docker -- | ||
# -- Container Image -- | ||
|
||
.PHONY: cbuild | ||
cbuild: ## Build docker image | ||
docker build -t ${REGISTRYNS}/${BINNAME}-builder:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --target build_base --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} . | ||
docker build -t ${REGISTRYNS}/${BINNAME}:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --cache-from ${REGISTRYNS}/${BINNAME}:latest --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} . | ||
docker tag ${REGISTRYNS}/${BINNAME}-builder:${VERSION} ${REGISTRYNS}/${BINNAME}-builder:latest | ||
docker tag ${REGISTRYNS}/${BINNAME}:${VERSION} ${REGISTRYNS}/${BINNAME}:latest | ||
cbuild: ## Build container image | ||
ifndef CONTAINER_TOOL | ||
$(error No container tool (docker, podman) found in your environment. Please, install one) | ||
endif | ||
|
||
@echo "Building image with $(CONTAINER_TOOL)" | ||
|
||
${CONTAINER_TOOL} build -t ${REGISTRYNS}/${BINNAME}-builder:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --target build_base --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} . | ||
${CONTAINER_TOOL} build -t ${REGISTRYNS}/${BINNAME}:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --cache-from ${REGISTRYNS}/${BINNAME}:latest --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} . | ||
${CONTAINER_TOOL} tag ${REGISTRYNS}/${BINNAME}-builder:${VERSION} ${REGISTRYNS}/${BINNAME}-builder:latest | ||
${CONTAINER_TOOL} tag ${REGISTRYNS}/${BINNAME}:${VERSION} ${REGISTRYNS}/${BINNAME}:latest | ||
|
||
.PHONY: cpush | ||
cpush: ## Push docker image | ||
cpush: ## Push container image | ||
ifndef CONTAINER_TOOL | ||
$(error No container tool (docker, podman) found in your environment. Please, install one) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line needs a tab space at start There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
endif | ||
|
||
@echo "Pushing image with $(CONTAINER_TOOL)" | ||
|
||
# To help with reusing layers and hence speeding up build | ||
docker push ${REGISTRYNS}/${BINNAME}-builder:${VERSION} | ||
docker push ${REGISTRYNS}/${BINNAME}:${VERSION} | ||
${CONTAINER_TOOL} push ${REGISTRYNS}/${BINNAME}-builder:${VERSION} | ||
${CONTAINER_TOOL} push ${REGISTRYNS}/${BINNAME}:${VERSION} | ||
|
||
.PHONY: crun | ||
crun: ## Run docker image | ||
docker run --rm -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}/:/workspace ${REGISTRYNS}/${BINNAME}:${VERSION} | ||
crun: ## Run container image | ||
ifndef CONTAINER_TOOL | ||
$(error No container tool (docker, podman) found in your environment. Please, install one) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line needs a tab space at start There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
endif | ||
|
||
@echo "Running image with $(CONTAINER_TOOL)" | ||
|
||
ifdef DOCKER_CMD | ||
${CONTAINER_TOOL} run --rm -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}/:/workspace ${REGISTRYNS}/${BINNAME}:${VERSION} | ||
else | ||
${CONTAINER_TOOL} run --rm -it -p 8080:8080 --network=bridge ${REGISTRYNS}/${BINNAME}:${VERSION} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rmarting Do we need to run with -it flag for it to work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we don't. I use it normally but TBH for this use case it could be not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to remove it, since the api container will be running in non interactive mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense. Done! |
||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line needs a tab space at start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!