Skip to content

Commit a031fcd

Browse files
committed
Docker Image - CircleCi Automatic Push
1 parent 8ef6a5b commit a031fcd

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

.circleci/config.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,32 @@ jobs:
3131

3232
- run:
3333
name: Run Tests
34-
command: carton exec prove -lv
34+
command: carton exec prove -lv
35+
36+
- setup_remote_docker
37+
38+
- run:
39+
name: Install Docker client
40+
when: on_success
41+
command: |
42+
if [ "${CIRCLE_BRANCH}" == "circle-ci" ]; then
43+
set -x
44+
VER="17.03.0-ce"
45+
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
46+
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
47+
mv /tmp/docker/* /usr/bin
48+
else
49+
echo "Not master branch so no docker required"
50+
fi
51+
52+
- run:
53+
name: Build and Push Docker Image
54+
when: on_success
55+
shell: /bin/bash
56+
command: |
57+
if [ "${CIRCLE_BRANCH}" == "circle-ci" ]; then
58+
docker login -u ${DOCKER_LOGIN} -p ${DOCKER_PASSWORD}
59+
make deploy_ci push
60+
else
61+
echo "Not master branch, So no push to DockerHub"
62+
fi

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ RELEASE_VERSION ?= latest
1010
LOCAL_IMAGE := $(NAME):$(RELEASE_VERSION)
1111
REMOTE_IMAGE := $(NAMESPACE)/$(LOCAL_IMAGE)
1212

13+
CIRLE_SHA1 ?= ''
14+
REMOTE_IMAGE_CI := $(NAMESPACE)/$(NAME):$(CIRCLE_SHA1)
15+
1316
# Environment General Settings
1417
ENVIRONMENT ?= devel
1518
SECRETS_URL ?= 'https://www.dropbox.com/s/p9x87ffn19rdr0c/secrets.mk.gpg'
@@ -40,6 +43,7 @@ endif
4043

4144
all: test update ## Test, Build and Push Docker Image to the Registry
4245
update: build push ## Build and Push Docker Image to the Registry
46+
deploy_ci: build push_ci
4347

4448
build: ## Build docker image with name LOCAL_IMAGE (NAME:RELEASE_VERSION).
4549
docker build -f $(THISDIR_PATH)/Dockerfile -t $(LOCAL_IMAGE) $(PROJECT_PATH)
@@ -92,6 +96,10 @@ tag: ## Tag IMAGE_NAME
9296
push: tag ## Push to the docker registry
9397
docker push $(REMOTE_IMAGE)
9498

99+
push_ci:
100+
docker tag $(LOCAL_IMAGE) $(REMOTE_IMAGE_CI)
101+
docker push $(REMOTE_IMAGE_CI)
102+
95103
pull: ## Pull the docker from the Registry
96104
docker pull $(REMOTE_IMAGE)
97105

0 commit comments

Comments
 (0)