Skip to content

Commit a8d9c68

Browse files
committed
#9 Refactor Makefile and update README.md
1 parent 90a5c66 commit a8d9c68

File tree

7 files changed

+50
-49
lines changed

7 files changed

+50
-49
lines changed

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: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ dpl ?= deploy.env
44
include $(dpl)
55
export $(shell sed 's/=.*//' $(dpl))
66

7-
TAGS := all 12 11 10 9 8 7 6
8-
97
# HELP
108
# This will output the help for each task
119
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@@ -18,44 +16,50 @@ help: ## This help.
1816

1917

2018
# DOCKER TASKS
21-
build: ## Build specific docker image
19+
build: ## Build a docker image
2220
docker build -t $(APP_NAME) -f $(FILE) .
2321

24-
build-nc: ## Build specific docker image without caching
22+
build-nc: ## Build a docker image without caching
2523
docker build --no-cache -t $(APP_NAME) -f $(FILE) .
2624

2725
build-all-nc: ## Build all docker images without caching
28-
for VERSION in $(TAGS) ; do \
29-
docker build --no-cache -t $(APP_NAME):$$VERSION -f $$VERSION/Dockerfile . ; \
26+
for TAG in $(APP_TAGS) ; do \
27+
docker build --no-cache -t $(APP_NAME):$$TAG -f $$TAG/Dockerfile . ; \
3028
done
3129

32-
# release: build-nc publish ## Release and publish a docker image to registory
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
3335

34-
release-all: build-all-nc publish-all ## Release and publish all docker images to registory
36+
publish-all: docker-login docker-tag-all docker-push-all ## Publish all docker images to registry
3537

36-
publish-all: docker-login docker-push-all ## Publish all versions
38+
docker-push: ## Docker push a docker image to registry
39+
docker push $(DOCKER_HUB)/$(APP_NAME):$(TAG)
3740

38-
# Publish all docker images to registory
39-
docker-push-all: docker-tag-all
40-
for TAG in $(TAGS) ; do \
41+
docker-push-all: ## Docker push all docker images to registry
42+
for TAG in $(APP_TAGS) ; do \
4143
echo "docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ... " ; \
4244
docker push $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
4345
done
4446

45-
# Generate docker image tags
46-
docker-tag-all:
47-
for TAG in $(TAGS) ; do \
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 \
4852
docker tag $(APP_NAME):$$TAG $(DOCKER_HUB)/$(APP_NAME):$$TAG ; \
4953
done
5054

51-
# Login to docker hub
52-
docker-login:
55+
docker-login: ## Login to docker hub
5356
docker login
5457

55-
test:
56-
for TAG in $(TAGS) ; do \
57-
echo "testing $$TAG" ; \
58-
done
59-
6058
version: ## Output the all support versions
61-
@echo $(TAGS)
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

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# You have to define the values in {}
22
APP_NAME=clang-tools
3+
APP_TAGS=all 12 11 10 9 8 7 6
34
DOCKER_HUB=xianpengshen
45
DOCKER_PKG=ghcr.io/shenxianpeng

0 commit comments

Comments
 (0)