diff --git a/11/alpine-3.14/Dockerfile b/11-alpine-3.14/Dockerfile similarity index 100% rename from 11/alpine-3.14/Dockerfile rename to 11-alpine-3.14/Dockerfile diff --git a/12/alpine-edge/Dockerfile b/12-alpine-edge/Dockerfile similarity index 100% rename from 12/alpine-edge/Dockerfile rename to 12-alpine-edge/Dockerfile diff --git a/13/Dockerfile b/13/Dockerfile new file mode 100644 index 0000000..cb53397 --- /dev/null +++ b/13/Dockerfile @@ -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 [""] diff --git a/Makefile b/Makefile index 32ca0d0..16ccdf1 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file +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" diff --git a/README.md b/README.md index d08cb41..3785579 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) diff --git a/deploy.env b/deploy.env deleted file mode 100644 index ab9715c..0000000 --- a/deploy.env +++ /dev/null @@ -1,5 +0,0 @@ -# You have to define the values in {} -APP_NAME=clang-tools -APP_TAGS=all 12 12-alpine-edge 11 11-alpine-3.14 10 9 8 7 6 -DOCKER_HUB=xianpengshen -DOCKER_PKG=ghcr.io/shenxianpeng