Skip to content

Commit 5f1e74a

Browse files
authored
Merge pull request #10 from shenxianpeng/refactor-dockerfile
Refactor dockerfile
2 parents ba3db81 + a8d9c68 commit 5f1e74a

15 files changed

+150
-84
lines changed

10/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

11/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

12/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:latest
1+
FROM ubuntu:20.04
22

33
ENV VERSION 12
44

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

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

6/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

7/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN echo "--- Clang-format version ---"
13-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
14-
RUN clang-format --version
15-
RUN echo "--- Clang-tidy version ---"
16-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

8/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

9/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

Dockerfile-ubuntu.template

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN tools="clang-format-$VERSION clang-tidy-$VERSION" \
77
&& apt-get -y install $tools \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
WORKDIR /src
10+
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format \
11+
&& echo "--- Clang-format version ---" \
12+
&& clang-format --version \
13+
&& ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy \
14+
&& echo "--- Clang-tidy version ---" \
15+
&& clang-tidy --version
1116

12-
RUN ln -s /usr/bin/clang-format-"$VERSION" /usr/bin/clang-format
13-
RUN echo "--- Clang-format version ---"
14-
RUN clang-format --version
15-
RUN ln -s /usr/bin/clang-tidy-"$VERSION" /usr/bin/clang-tidy
16-
RUN echo "--- Clang-tidy version ---"
17-
RUN clang-tidy --version
17+
WORKDIR /src
1818

1919
CMD [""]

Makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# import deploy config
2+
# You can change the default deploy config with `make cnf="deploy_special.env" release`
3+
dpl ?= deploy.env
4+
include $(dpl)
5+
export $(shell sed 's/=.*//' $(dpl))
6+
7+
# HELP
8+
# This will output the help for each task
9+
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
10+
.PHONY: help
11+
12+
help: ## This help.
13+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
14+
15+
.DEFAULT_GOAL := help
16+
17+
18+
# DOCKER TASKS
19+
build: ## Build a docker image
20+
docker build -t $(APP_NAME) -f $(FILE) .
21+
22+
build-nc: ## Build a docker image without caching
23+
docker build --no-cache -t $(APP_NAME) -f $(FILE) .
24+
25+
build-all-nc: ## Build all docker images without caching
26+
for TAG in $(APP_TAGS) ; do \
27+
docker build --no-cache -t $(APP_NAME):$$TAG -f $$TAG/Dockerfile . ; \
28+
done
29+
30+
release: build-nc publish ## Release and publish a docker image to registry
31+
32+
release-all: build-all-nc docker-login docker-tag-all docker-push-all ## Release and publish all images to registry
33+
34+
publish: docker-login docker-tag docker-push ## Publish a docker image to registry
35+
36+
publish-all: docker-login docker-tag-all docker-push-all ## Publish all docker images to registry
37+
38+
docker-push: ## Docker push a docker image to registry
39+
docker push $(DOCKER_HUB)/$(APP_NAME):$(TAG)
40+
41+
docker-push-all: ## Docker push all docker images to registry
42+
for TAG in $(APP_TAGS) ; do \
43+
echo "docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ... " ; \
44+
docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
45+
done
46+
47+
docker-tag: ## Docker image create a tag
48+
docker tag $(APP_NAME):$(TAG) $(DOCKER_HUB)/$(APP_NAME):$(TAG)
49+
50+
docker-tag-all: ## Docker image create all tags
51+
for TAG in $(APP_TAGS) ; do \
52+
docker tag $(APP_NAME):$$TAG $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
53+
done
54+
55+
docker-login: ## Login to docker hub
56+
docker login
57+
58+
version: ## Output the all support versions
59+
@echo $(APP_TAGS)
60+
61+
# Test Makefile syntax.
62+
test:
63+
for TAG in $(APP_TAGS) ; do \
64+
echo "testing $$TAG" ; \
65+
done

README.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Supported tags
99
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/all)
10-
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/latest)
10+
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/12)
1111
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/11)
1212
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/10)
1313
![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/xianpengshen/clang-tools/9)
@@ -17,7 +17,7 @@
1717

1818

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

2828
## How to use this image
2929

30-
### Create a `Dockerfile` in your project
30+
### Create a [`Dockerfile`](demo/Dockerfile) in your project
3131

3232
```Dockerfile
33-
FROM xianpengshen/clang-tools
33+
FROM xianpengshen/clang-tools:12
3434

3535
WORKDIR /usr/src/app
3636

@@ -64,17 +64,17 @@ $ docker run clang-tools clang-tidy helloworld.c \
6464
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.
6565

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

72-
### Run `Dockerfile` with specific verion
72+
### Build `Dockerfile` with specific verion
7373

7474
If you want to provide dynamic versions of clang-tools
7575

7676
```Dockerfile
77-
ARG TAG=latest
77+
ARG TAG=12
7878
FROM xianpengshen/clang-tools:$TAG
7979

8080
WORKDIR /usr/src/app
@@ -84,17 +84,6 @@ COPY . .
8484
CMD [ "" ]
8585
```
8686

87-
Use the latest verion of clang-tools.
88-
89-
```bash
90-
$ docker build -t mylinter .
91-
Sending build context to Docker daemon 157.7kB
92-
Step 1/13 : ARG TAG=latest
93-
Step 2/13 : FROM xianpengshen/clang-tools:$TAG
94-
latest: Pulling from xianpengshen/clang-tools
95-
Status: Downloaded newer image for xianpengshen/clang-tools:latest
96-
```
97-
9887
Use specific version of clang-tools by passing `--build-arg`
9988

10089
```bash

all/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:latest
1+
FROM ubuntu:20.04
22

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

12-
WORKDIR /src
12+
RUN ln -s /usr/bin/clang-format-$DEFAULT_VERSION /usr/bin/clang-format \
13+
&& echo "--- Clang-format version ---" \
14+
&& clang-format --version \
15+
&& ln -s /usr/bin/clang-tidy-$DEFAULT_VERSION /usr/bin/clang-tidy \
16+
&& echo "--- Clang-tidy version ---" \
17+
&& clang-tidy --version \
1318

14-
RUN ln -s /usr/bin/clang-format-$DEFAULT_VERSION /usr/bin/clang-format
15-
RUN echo "--- Clang-format version ---"
16-
RUN clang-format --version
17-
RUN ln -s /usr/bin/clang-tidy-$DEFAULT_VERSION /usr/bin/clang-tidy
18-
RUN echo "--- Clang-tidy version ---"
19-
RUN clang-tidy --version
19+
WORKDIR /src
2020

2121
CMD [""]

demo/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM xianpengshen/clang-tools:12
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY . .
6+
7+
CMD [ "" ]
File renamed without changes.
File renamed without changes.

deploy.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# You have to define the values in {}
2+
APP_NAME=clang-tools
3+
APP_TAGS=all 12 11 10 9 8 7 6
4+
DOCKER_HUB=xianpengshen
5+
DOCKER_PKG=ghcr.io/shenxianpeng

0 commit comments

Comments
 (0)