Skip to content

Commit f6f2b4e

Browse files
authored
Merge pull request #104 from web-push-libs/circleci
Circleci
2 parents 785f9b5 + d026d0c commit f6f2b4e

File tree

2 files changed

+88
-12
lines changed

2 files changed

+88
-12
lines changed

.circleci/config.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# These environment variables must be set in CircleCI UI
2+
#
3+
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
4+
# DOCKER_USER - login info for docker hub
5+
# DOCKER_PASS
6+
#
7+
version: 2
8+
jobs:
9+
build:
10+
docker:
11+
- image: docker:18.02.0-ce
12+
working_directory: /dockerflow
13+
steps:
14+
# workaround circleci's fallback git's "object not found" error w/ tag
15+
# builds
16+
- run:
17+
name: Install Docker build dependencies
18+
command: apk add --no-cache openssh-client git
19+
20+
- checkout
21+
- setup_remote_docker
22+
23+
- run:
24+
name: Build Docker image
25+
command: docker build -t app:build .
26+
27+
# save the built docker container into CircleCI's cache. This is
28+
# required since Workflows do not have the same remote docker instance.
29+
- run:
30+
name: docker save app:build
31+
command: mkdir -p /cache; docker save -o /cache/docker.tar "app:build"
32+
- save_cache:
33+
key: v1-{{ .Branch }}-{{ .Environment.CIRCLE_TAG }}-{{ epoch }}
34+
paths:
35+
- /cache/docker.tar
36+
37+
deploy:
38+
docker:
39+
- image: docker:18.02.0-ce
40+
steps:
41+
- setup_remote_docker
42+
- restore_cache:
43+
key: v1-{{.Branch}}
44+
- run:
45+
name: Restore Docker image cache
46+
command: docker load -i /cache/docker.tar
47+
48+
- run:
49+
name: Deploy to Dockerhub
50+
command: |
51+
if [ "${CIRCLE_BRANCH}" == "master" ]; then
52+
DOCKER_TAG="latest"
53+
fi
54+
55+
if echo "${CIRCLE_BRANCH}" | grep '^feature\..*' > /dev/null; then
56+
DOCKER_TAG="${CIRCLE_BRANCH}"
57+
fi
58+
59+
if [ -n "${CIRCLE_TAG}" ]; then
60+
DOCKER_TAG="$CIRCLE_TAG"
61+
fi
62+
63+
if [ -n "${DOCKER_TAG}" ]; then
64+
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
65+
echo ${DOCKERHUB_REPO}:${DOCKER_TAG}
66+
docker tag app:build ${DOCKERHUB_REPO}:${DOCKER_TAG}
67+
docker images
68+
docker push "${DOCKERHUB_REPO}:${DOCKER_TAG}"
69+
else
70+
echo "Not pushing to dockerhub for tag=${CIRCLE_TAG} branch=${CIRCLE_BRANCH}"
71+
fi
72+
73+
workflows:
74+
version: 2
75+
build-deploy:
76+
jobs:
77+
- build:
78+
filters:
79+
tags:
80+
only: /.*/
81+
82+
- deploy:
83+
requires:
84+
- build
85+
filters:
86+
tags:
87+
only: /.*/
88+

circle.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)