Skip to content

Commit 7fb3422

Browse files
committed
add deploy to docker image, just on master merge
1 parent d13408d commit 7fb3422

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ env:
2121

2222
- DEVEL_COVER_OPTIONS="-ignore,^local/"
2323
- PERL_CARTON_PATH=$HOME/local
24+
25+
- DOCKER_IMAGE_NAME=metacpan-api
2426
matrix:
2527
- CPAN_RESOLVER=metadb PERL_CARTON_PATH=$HOME/no-snapshot HARNESS_VERBOSE=1
2628
- CPAN_RESOLVER=snapshot
@@ -83,6 +85,19 @@ after_success:
8385
services:
8486
- docker
8587

88+
## Build and push a docker image in production
89+
deploy:
90+
- provider: script
91+
script:
92+
- deploy/build.sh
93+
on:
94+
branch: master
95+
- provider: script
96+
script:
97+
- deploy/push.sh
98+
on:
99+
branch: master
100+
86101
# caching /local should save about 5 minutes in module install time
87102
cache:
88103
directories:

deploy/build.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
DEPLOY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
source "${DEPLOY_DIR}/vars.sh"
6+
7+
# ## Go to where the docker file is
8+
cd "${DEPLOY_DIR}/.."
9+
10+
## Pull the latest docker file from docker hub if there is one
11+
docker pull "$DOCKER_HUB_NAME" || true
12+
13+
## Issue the build command, adding tags (from CONFIG.sh)
14+
docker build --pull --cache-from "$DOCKER_HUB_NAME" --tag $DOCKER_HUB_NAME --tag $VERSION_TAG .

deploy/push.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
DEPLOY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
source "${DEPLOY_DIR}/vars.sh"
6+
7+
cd "${DEPLOY_DIR}/.."
8+
9+
docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_PASSWD"
10+
11+
docker push "$DOCKER_HUB_NAME"

deploy/vars.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
## Edit this
4+
if [ -z $DOCKER_IMAGE_NAME ]; then
5+
echo "DOCKER_IMAGE_NAME is not defined"
6+
exit 1;
7+
fi
8+
9+
## Should not need to edit this
10+
export DOCKER_HUB_NAME="metacpan/${DOCKER_IMAGE_NAME}"
11+
export VERSION="${TRAVIS_BUILD_NUMBER:-UNKNOWN-BUILD-NUMBER}"
12+
export VERSION_TAG="${DOCKER_HUB_NAME}:${VERSION}"
13+

0 commit comments

Comments
 (0)