-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add makefile improvements for use in actions workflow
- Loading branch information
Showing
1 changed file
with
40 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,57 @@ | ||
PROJECT_NAME = $(notdir $(PWD)) | ||
VERSION = $(shell sed -rn "s/__version__ = '(.*)'/\1/p" rundeck_exporter.py) | ||
AUTHOR = phsmith | ||
PROJECT = $(notdir $(PWD)) | ||
IMAGE_NAME = rundeck-exporter | ||
IMAGE_VERSION = $(or ${VERSION}, latest) | ||
DOCKER_IMAGE_TAG = $(AUTHOR)/$(IMAGE_NAME) | ||
GHCR_IMAGE_TAG = ghcr.io/$(AUTHOR)/$(PROJECT)/$(IMAGE_NAME) | ||
|
||
.SILENT: push | ||
default: docker-build | ||
|
||
default: build | ||
|
||
build: | ||
docker-build: | ||
docker run --rm -i hadolint/hadolint:latest < Dockerfile | ||
|
||
docker build \ | ||
--rm \ | ||
--network host \ | ||
--tag="$(PROJECT_NAME):$(VERSION)" \ | ||
docker pull $(GHCR_IMAGE_TAG) || true | ||
|
||
DOCKER_BUILDKIT=1 docker build \ | ||
--cache-from=$(GHCR_IMAGE_TAG) \ | ||
--cache-from=$(DOCKER_IMAGE_TAG) \ | ||
--build-arg BUILDKIT_INLINE_CACHE=1 \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
--build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg VERSION="$(VERSION)" . | ||
--build-arg VERSION="$(IMAGE_VERSION)" \ | ||
--tag=$(IMAGE_NAME) . | ||
|
||
docker tag $(IMAGE_NAME) $(DOCKER_IMAGE_TAG):$(IMAGE_VERSION) | ||
docker tag $(IMAGE_NAME) $(GHCR_IMAGE_TAG):$(IMAGE_VERSION) | ||
|
||
docker-push: | ||
@echo "$(DOCKER_HUB_TOKEN)" | docker login -u $(AUTHOR) --password-stdin | ||
docker push $(DOCKER_IMAGE_TAG):$(IMAGE_VERSION) | ||
|
||
ghcr-push: | ||
@echo "$(GITHUB_TOKEN)" | docker login ghcr.io -u $(AUTHOR) --password-stdin | ||
docker push $(GHCR_IMAGE_TAG):$(IMAGE_VERSION) | ||
|
||
push-all: | ||
make -j2 docker-push ghcr-push | ||
|
||
clean: | ||
docker rmi --force $(PROJECT_NAME):$(VERSION) | ||
@docker rmi --force `docker images | awk '/$(IMAGE_NAME)/ {print $3}'` &> /dev/null || true | ||
@echo "> Project Docker images cleaned up." | ||
|
||
push: | ||
git-push: | ||
[ -z "$(git status --short --untracked-files=no)" ] && (echo -e "\nNeed to commit changes before push.\n"; exit 1) | ||
git tag -d latest | ||
git tag latest | ||
git push origin :latest | ||
git tag "v$(VERSION)" | ||
git tag "v$(IMAGE_VERSION)" | ||
git push --all | ||
|
||
debug: | ||
docker run --rm -it $(PROJECT_NAME):$(VERSION) /bin/sh | ||
docker run --rm -it --name=$(IMAGE_NAME) --entrypoint=/bin/sh $(IMAGE_NAME) | ||
|
||
docker-compose-up: | ||
docker compose -f examples/docker-compose/docker-compose.yml up --build -d | ||
|
||
run: | ||
docker run --rm $(PROJECT_NAME):$(VERSION) \ | ||
--host 0.0.0.0 \ | ||
--rundeck.skip_ssl | ||
docker-compose-down: | ||
docker compose -f examples/docker-compose/docker-compose.yml down |