Skip to content

Commit d21c86f

Browse files
authored
Build and test images on the PRs (#22)
* Build images on the PRs * this work? * will this? * schema * schema * schema * schema * fix * enhance * exclude * final
1 parent 24cedd5 commit d21c86f

File tree

2 files changed

+115
-74
lines changed

2 files changed

+115
-74
lines changed

.circleci/config.yml

Lines changed: 99 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,112 @@
1-
defaults: &defaults
2-
machine:
3-
services:
4-
- docker
5-
steps:
6-
- checkout
7-
- run:
8-
name: "Setup required directories"
9-
command: |
10-
mkdir -p /tmp/apache-cloudstack
11-
mkdir -p /tmp/.m2
12-
- restore_cache:
13-
key: repo-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-m2
14-
- run:
15-
name: "Build Docker image"
16-
command: make ${TAG}
17-
- run:
18-
name: "Test Docker image"
19-
command: |
20-
if [ "${TAG}" = "centos6" ]; then exit 0; fi
21-
docker run \
22-
--volume /tmp/apache-cloudstack:/mnt/build \
23-
--volume /tmp/.m2:/root/.m2 \
24-
--rm \
25-
${IMAGE}:${TAG} \
26-
--git-remote https://github.com/apache/cloudstack.git \
27-
--git-ref refs/heads/master \
28-
--remove-first \
29-
${PARAMS}
30-
- save_cache:
31-
key: repo-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-m2
32-
paths:
33-
- /tmp/.m2
1+
version: 2.1
342

35-
version: 2
363
jobs:
37-
centos6:
38-
<<: *defaults
39-
environment:
40-
IMAGE: khos2ow/cloudstack-rpm-builder
41-
TAG: centos6
42-
PARAMS: --distribution centos63
4+
test:
5+
parameters:
6+
tag:
7+
type: string
8+
ref:
9+
type: string
10+
param:
11+
type: string
12+
docker:
13+
- image: circleci/buildpack-deps:stretch
14+
steps:
15+
- checkout
16+
- setup_remote_docker
17+
- run:
18+
name: "Setup required directories"
19+
command: |
20+
mkdir -p /tmp/apache-cloudstack
21+
mkdir -p /tmp/.m2
22+
- restore_cache:
23+
key: repo-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-m2
24+
- run:
25+
name: "Build Docker image"
26+
command: make <<parameters.tag>>
27+
- run:
28+
name: "Test Docker image"
29+
command: |
30+
docker run \
31+
--volume /tmp/apache-cloudstack:/mnt/build \
32+
--volume /tmp/.m2:/root/.m2 \
33+
--rm \
34+
khos2ow/cloudstack-rpm-builder:<<parameters.tag>> \
35+
--git-remote https://github.com/apache/cloudstack.git \
36+
--git-ref <<parameters.ref>> \
37+
--remove-first \
38+
<<parameters.param>>
39+
- save_cache:
40+
key: repo-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-m2
41+
paths:
42+
- /tmp/.m2
4343

44-
centos7:
45-
<<: *defaults
46-
environment:
47-
IMAGE: khos2ow/cloudstack-rpm-builder
48-
TAG: centos7
49-
PARAMS: --distribution centos7
50-
51-
latest:
52-
<<: *defaults
53-
environment:
54-
IMAGE: khos2ow/cloudstack-rpm-builder
55-
TAG: centos7
56-
PARAMS: --distribution centos7
44+
push:
45+
parameters:
46+
tag:
47+
type: string
48+
docker:
49+
- image: circleci/buildpack-deps:stretch
50+
steps:
51+
- checkout
52+
- setup_remote_docker
53+
- run:
54+
name: Push docker image
55+
command: |
56+
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
57+
DOCKER_TAG=<<parameters.tag>> make <<parameters.tag>> push
5758
5859
workflows:
5960
version: 2
61+
test:
62+
jobs:
63+
- test:
64+
name: test-centos6
65+
tag: centos6
66+
ref: refs/heads/4.13
67+
param: --distribution centos63
68+
filters:
69+
branches:
70+
ignore: master
71+
72+
- test:
73+
name: test-centos7
74+
tag: centos7
75+
ref: refs/heads/4.13
76+
param: --distribution centos7
77+
filters:
78+
branches:
79+
ignore: master
80+
81+
- test:
82+
name: test-latest
83+
tag: centos7
84+
ref: refs/heads/4.13
85+
param: --distribution centos7
86+
filters:
87+
branches:
88+
ignore: master
89+
6090
build:
6191
jobs:
62-
- centos6:
92+
- push:
93+
name: push-centos6
94+
tag: centos6
6395
filters:
64-
tags:
65-
only: /v.*/
96+
branches:
97+
only: master
6698

67-
- centos7:
99+
- push:
100+
name: push-centos7
101+
tag: centos7
68102
filters:
69-
tags:
70-
only: /v.*/
103+
branches:
104+
only: master
105+
ignore: /.*/
71106

72-
- latest:
107+
- push:
108+
name: push-latest
109+
tag: latest
73110
filters:
74-
tags:
75-
only: /v.*/
111+
branches:
112+
only: master

Makefile

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
.PHONY: all centos6 centos7 latest
19-
20-
# Build docker tag based on provided info
21-
#
22-
# $1: tag_name
23-
# $2: directory_name
24-
define build_tag
25-
docker build -t khos2ow/cloudstack-rpm-builder:$(1) $(2)
26-
endef
18+
DOCKER_IMAGE := khos2ow/cloudstack-rpm-builder
19+
DOCKER_TAG :=
2720

21+
.PHONY: all
2822
all: centos6 centos7 latest
2923

24+
.PHONY: centos6
25+
centos6: DOCKER_TAG := centos6
3026
centos6:
31-
$(call build_tag,centos6,centos6)
27+
docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file centos6/Dockerfile centos6/
3228

29+
.PHONY: centos7
30+
centos7: DOCKER_TAG := centos7
3331
centos7:
34-
$(call build_tag,centos7,centos7)
32+
docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file centos7/Dockerfile centos7/
3533

34+
.PHONY: latest
35+
latest: DOCKER_TAG := latest
3636
latest:
37-
$(call build_tag,latest,centos7)
37+
docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file centos7/Dockerfile centos7/
38+
39+
.PHONY: push
40+
push:
41+
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)

0 commit comments

Comments
 (0)