Skip to content

Support clang tools v13 and refactor Makefile #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

Merged
merged 4 commits into from
Feb 14, 2022
Merged
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
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions 13/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:20.04

ENV PACKAGE="clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04"

WORKDIR /tmp

RUN apt-get update \
&& apt-get install -y xz-utils wget \
&& wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/$PACKAGE.tar.xz \
&& tar -xvf $PACKAGE.tar.xz \
&& cp $PACKAGE/bin/clang-format /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& cp $PACKAGE/bin/clang-tidy /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version \
&& rm -rf $PACKAGE $PACKAGE.tar.xz \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src

CMD [""]
127 changes: 71 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,67 +1,82 @@
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
export $(shell sed 's/=.*//' $(dpl))
FILE ?= unknow
APP_NAME := clang-tools
DIR_NAME := $(shell dirname $(FILE))
TAG := $(shell basename `dirname $(FILE)`)
IMAGE_NAME ?= $(APP_NAME):$(TAG)
DOCKER_HUB=xianpengshen/$(IMAGE_NAME)
DOCKERFILE ?= $(DIR_NAME)/Dockerfile
CONTAINER_BIN ?= docker

## Image metadatas
GIT_COMMIT_REV ?= $(shell git log -n 1 --pretty=format:'%h')
GIT_SCM_URL ?= $(shell git config --get remote.origin.url)
BUILD_DATE ?= $(shell date --utc '+%Y-%m-%dT%H:%M:%S' 2>/dev/null || gdate --utc '+%Y-%m-%dT%H:%M:%S')

check-file:
ifeq ($(FILE), unknow)
$(error FILE is not set. e.g make build FILE=12/Dockerfile)
else
echo $(FILE)
endif

check-name:
ifeq ($(IMAGE_NAME), .:.)
$(error IMAGE_NAME is not set. e.g make deploy IMAGE_NAME=clang-tools:12)
endif

# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help

help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# help: ## This help.
# @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

help: ## Show this Makefile's help
@echo ""
@echo "Make Docker images for Clang Tools"
@echo ""
@echo 'Usage: make [EXTRA_ARGUMENTS]'
@echo ""
@echo "make build FILE=12/Dockerfile Build image, see the example"
@echo "make publish FILE=12/Dockerfile Build and deploy image to Docker Hub"
@echo "make lint Lint Dockerfile validate inline bash"
@echo "make clean Clean all generate files"
@echo "make prune Clean all images that are not actively used"
@echo ""

.DEFAULT_GOAL := help


# DOCKER TASKS
build: ## Build a docker image
docker build -t $(APP_NAME):$(TAG) -f $(FILE) .

build-nc: ## Build a docker image without caching
# for example: make build-nc FILE=11/alpine-3.14/Dockerfile TAG=11-alpine-3.14
docker build --no-cache -t $(APP_NAME):$(TAG) -f $(FILE) .

build-all-nc: ## Build all docker images without caching
for TAG in $(APP_TAGS) ; do \
docker build --no-cache -t $(APP_NAME):$$TAG -f $$TAG/Dockerfile . ; \
done

release: build-nc publish ## Release and publish a docker image to registry

release-all: build-all-nc docker-login docker-tag-all docker-push-all ## Release and publish all images to registry

publish: docker-login docker-tag docker-push ## Publish a docker image to registry
# for example: make publish FILE=11/alpine-3.14/Dockerfile TAG=11-alpine-3.14

publish-all: docker-login docker-tag-all docker-push-all ## Publish all docker images to registry

docker-push: ## Docker push a docker image to registry
docker push $(DOCKER_HUB)/$(APP_NAME):$(TAG)

docker-push-all: ## Docker push all docker images to registry
for TAG in $(APP_TAGS) ; do \
echo "docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ... " ; \
docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
done

docker-tag: ## Docker image create a tag
docker tag $(APP_NAME):$(TAG) $(DOCKER_HUB)/$(APP_NAME):$(TAG)

docker-tag-all: ## Docker image create all tags
for TAG in $(APP_TAGS) ; do \
docker tag $(APP_NAME):$$TAG $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
done

docker-login: ## Login to docker hub
docker login

version: ## Output the all support versions
@echo $(APP_TAGS)

# Test Makefile syntax.
test:
for TAG in $(APP_TAGS) ; do \
echo "testing $$TAG" ; \
done
build: check-file ## ## Build the Docker Image $(NAME) from $(DOCKERFILE)
@echo "== Building $(IMAGE_NAME) from $(DOCKERFILE)..."
@export DOCKER_BUILDKIT=1
@$(CONTAINER_BIN) build \
-t $(IMAGE_NAME) \
--label "image.source=$(GIT_SCM_URL)" \
--label "image.revision=$(GIT_COMMIT_REV)" \
--label "image.created=$(BUILD_DATE)" \
-f $(DOCKERFILE) \
$(DIR_NAME)
@echo "== Build ✅ image $(IMAGE_NAME) Succeeded."

## This steps expects that you are logged to the Docker registry to push image into
publish: check-name check-file build login ## Tag and push the built image as specified by $(IMAGE_DEPLOY).
@echo "== Deploying $(IMAGE_NAME) to $(DOCKER_HUB)..."
$(CONTAINER_BIN) tag $(IMAGE_NAME) $(DOCKER_HUB)
$(CONTAINER_BIN) push $(DOCKER_HUB)
@echo "== Deploy ✅ $(DOCKER_HUB) Succeeded"

login: ## Docker login
$(CONTAINER_BIN) login --username xianpengshen

prune: ## clean all that is not actively used
@docker system prune -af
@echo "== Clean ✅ all inactively used images Succeeded"

lint: check-file ## Lint the $(DOCKERFILE) content
@echo "== Linting $(DOCKERFILE)..."
@echo "Output Lint results"
@docker run --rm -i hadolint/hadolint hadolint - < $(DOCKERFILE)
@echo "== Lint ✅ Succeeded"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Supported tags
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/all)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/13)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/12-alpine-edge)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/12)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/11-alpine-3.14)
Expand All @@ -18,8 +19,8 @@
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/7)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/6)


* [clang-tools:all](https://github.com/shenxianpeng/clang-tools/blob/master/all/Dockerfile) (supports all versions of the below tags)
* [clang-tools:13](https://github.com/shenxianpeng/clang-tools/blob/master/13/Dockerfile)
* [clang-tools:12-alpine-edge](https://github.com/shenxianpeng/clang-tools/blob/master/12/alpine-edge/Dockerfile)
* [clang-tools:12](https://github.com/shenxianpeng/clang-tools/blob/master/12/Dockerfile)
* [clang-tools:11-alpine-3.14](https://github.com/shenxianpeng/clang-tools/blob/master/11/alpine-3.14/Dockerfile)
Expand Down
5 changes: 0 additions & 5 deletions deploy.env

This file was deleted.