Skip to content

Refactor dockerfile #10

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 3 commits into from
Nov 6, 2021
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
14 changes: 7 additions & 7 deletions 10/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions 11/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
16 changes: 8 additions & 8 deletions 12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:latest
FROM ubuntu:20.04

ENV VERSION 12

Expand All @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions 6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions 7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN echo "--- Clang-format version ---"
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN clang-format --version
RUN echo "--- Clang-tidy version ---"
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions 8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions 9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
14 changes: 7 additions & 7 deletions Dockerfile-ubuntu.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
&& apt-get -y install $tools \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version

RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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))

# 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)

.DEFAULT_GOAL := help


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

build-nc: ## Build a docker image without caching
docker build --no-cache -t $(APP_NAME) -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

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
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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/latest)
![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)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/10)
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/9)
Expand All @@ -17,7 +17,7 @@


* [clang-tools:all](https://github.com/shenxianpeng/clang-tools/blob/master/all/Dockerfile) (supports all versions of the below tags)
* [clang-tools:latest](https://github.com/shenxianpeng/clang-tools/blob/master/12/Dockerfile) (v12)
* [clang-tools:12](https://github.com/shenxianpeng/clang-tools/blob/master/12/Dockerfile)
* [clang-tools:11](https://github.com/shenxianpeng/clang-tools/blob/master/11/Dockerfile)
* [clang-tools:10](https://github.com/shenxianpeng/clang-tools/blob/master/10/Dockerfile)
* [clang-tools:9](https://github.com/shenxianpeng/clang-tools/blob/master/9/Dockerfile)
Expand All @@ -27,10 +27,10 @@

## How to use this image

### Create a `Dockerfile` in your project
### Create a [`Dockerfile`](demo/Dockerfile) in your project

```Dockerfile
FROM xianpengshen/clang-tools
FROM xianpengshen/clang-tools:12

WORKDIR /usr/src/app

Expand Down Expand Up @@ -64,17 +64,17 @@ $ docker run clang-tools clang-tidy helloworld.c \
If a simple source code, you may find it inconvenient to write a complete `Dockerfile`. In such cases, you can run by using the Docker image directly.

```bash
docker run -v $PWD:/src xianpengshen/clang-tools clang-format -i helloworld.c
docker run -v $PWD:/src xianpengshen/clang-tools clang-tidy helloworld.c \
docker run -v $PWD:/src xianpengshen/clang-tools:12 clang-format -i helloworld.c
docker run -v $PWD:/src xianpengshen/clang-tools:12 clang-tidy helloworld.c \
-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-cplusplus-*,clang-analyzer-*,cppcoreguidelines-*
```

### Run `Dockerfile` with specific verion
### Build `Dockerfile` with specific verion

If you want to provide dynamic versions of clang-tools

```Dockerfile
ARG TAG=latest
ARG TAG=12
FROM xianpengshen/clang-tools:$TAG

WORKDIR /usr/src/app
Expand All @@ -84,17 +84,6 @@ COPY . .
CMD [ "" ]
```

Use the latest verion of clang-tools.

```bash
$ docker build -t mylinter .
Sending build context to Docker daemon 157.7kB
Step 1/13 : ARG TAG=latest
Step 2/13 : FROM xianpengshen/clang-tools:$TAG
latest: Pulling from xianpengshen/clang-tools
Status: Downloaded newer image for xianpengshen/clang-tools:latest
```

Use specific version of clang-tools by passing `--build-arg`

```bash
Expand Down
16 changes: 8 additions & 8 deletions all/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:latest
FROM ubuntu:20.04

ARG DEFAULT_VERSION=12
ENV VERSION="12 11 10 9 8 7 6.0"
Expand All @@ -9,13 +9,13 @@ RUN apt-get update \
apt-get -y install $tools; done \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
RUN ln -s /usr/bin/clang-format-$DEFAULT_VERSION /usr/bin/clang-format \
&& echo "--- Clang-format version ---" \
&& clang-format --version \
&& ln -s /usr/bin/clang-tidy-$DEFAULT_VERSION /usr/bin/clang-tidy \
&& echo "--- Clang-tidy version ---" \
&& clang-tidy --version \

RUN ln -s /usr/bin/clang-format-$DEFAULT_VERSION /usr/bin/clang-format
RUN echo "--- Clang-format version ---"
RUN clang-format --version
RUN ln -s /usr/bin/clang-tidy-$DEFAULT_VERSION /usr/bin/clang-tidy
RUN echo "--- Clang-tidy version ---"
RUN clang-tidy --version
WORKDIR /src

CMD [""]
7 changes: 7 additions & 0 deletions demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM xianpengshen/clang-tools:12

WORKDIR /usr/src/app

COPY . .

CMD [ "" ]
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions deploy.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# You have to define the values in {}
APP_NAME=clang-tools
APP_TAGS=all 12 11 10 9 8 7 6
DOCKER_HUB=xianpengshen
DOCKER_PKG=ghcr.io/shenxianpeng