Skip to content

Commit

Permalink
Adding readmyhuborb
Browse files Browse the repository at this point in the history
  • Loading branch information
matfax committed Aug 29, 2018
1 parent 286cb54 commit 0ac8c0d
Showing 1 changed file with 117 additions and 8 deletions.
125 changes: 117 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,106 @@ docker_version_params: &docker_version_params
type: string
default: stable

readmyhub_version_params: &readmyhub_version_params
version:
description: "Version of the readmyhub Docker image"
type: string
default: stable
file:
description: "Path to the README.md file"
type: string
default: "README.md"
organization:
description: "Docker Hub organization or user name"
type: string
default: ""
repository:
description: "Docker Hub repository name"
type: string
default: ""

readmyhub_update_params: &readmyhub_update_params
derive_repo:
description: "Enable to automatically derive the Docker Hub repository from the GitHub repository"
type: boolean
default: true

orbs:
readmyhuborb:
executors:
default:
parameters:
<<: *readmyhub_version_params
docker:
- image: gofunky/readmyhub:<< parameters.version >>-git
working_directory: /data
environment:
README_PATH: /data/<< parameters.file >>
IFS: "/"
DOCKERHUB_ORG: << parameters.organization >>
DOCKERHUB_REPO: << parameters.repository >>
commands:
update:
parameters:
<<: *readmyhub_update_params
steps:
- checkout
- run:
name: Check DOCKER_USR
command: |
if [ -z "$DOCKER_USR" ]; then
echo "ERROR: DOCKER_USR is not set!"
exit 127
fi
- run:
name: Check DOCKER_PWD
command: |
if [ -z "$DOCKER_PWD" ]; then
echo "ERROR: DOCKER_PWD is not set!"
exit 127
fi
- when:
condition: << parameters.derive_repo >>
steps:
- run:
name: Update README
command: |
set -f
URL=`git remote get-url origin`
URL=`echo "$URL" | sed -e "s/^https:\/\///" -e "s/\.git//" | sed -e "s/^git@//"`
URL=`echo "$URL" | sed -r 's/github.com:/github.com\//g'`
set -- $URL
DOCKERHUB_ORG=$2
DOCKERHUB_REPO=$3
export DOCKERHUB_USR=${DOCKER_USR}
export DOCKERHUB_PWD=${DOCKER_PWD}
node /app/index.js
set +f
- unless:
condition: << parameters.derive_repo >>
steps:
- run:
name: Update README
command: |
export DOCKERHUB_USR=${DOCKER_USR}
export DOCKERHUB_PWD=${DOCKER_PWD}
node /app/index.js
jobs:
update:
description: "Push the given README.md to the Docker Hub"
executor:
name: default
version: << parameters.version >>
file: << parameters.file >>
organization: << parameters.organization >>
repository: << parameters.repository >>
parameters:
<<: *readmyhub_version_params
<<: *readmyhub_update_params
steps:
- update:
derive_repo: << parameters.derive_repo >>

dockerorb:
executors:
default:
Expand Down Expand Up @@ -133,7 +232,7 @@ orbs:
- run:
name: Build Docker image with arguments and labels
command: |
test ./env/load.sh -f && source ./env/load.sh
ls ./env/load.sh >> /dev/null 2>&1 && source ./env/load.sh
buildarg=""
args="<< parameters.args >><<# parameters.add_labels >>,BUILD_DATE=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"`,VCS_REF=`git rev-parse --short HEAD`<</ parameters.add_labels >>"
for arg in $args; do
Expand All @@ -149,7 +248,7 @@ orbs:
- run:
name: Build Docker image without arguments and with labels
command: |
test ./env/load.sh -f && source ./env/load.sh
ls ./env/load.sh >> /dev/null 2>&1 && source ./env/load.sh
docker build <<# parameters.add_labels >>--build-arg BUILD_DATE=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` --build-arg VCS_REF=`git rev-parse --short HEAD` <</ parameters.add_labels >>--cache-from=<< parameters.base_tag >> -f << parameters.file >> -t << parameters.base_tag >> << parameters.path >>
- when:
condition: << parameters.cache >>
Expand All @@ -174,7 +273,7 @@ orbs:
- run:
name: Add Docker tags
command: |
test ./env/load.sh -f && source ./env/load.sh
ls ./env/load.sh >> /dev/null 2>&1 && source ./env/load.sh
tags="<< parameters.tags >>"
for tag in $tags; do
docker tag << parameters.base_tag >> "$tag"
Expand Down Expand Up @@ -207,7 +306,7 @@ orbs:
- deploy:
name: Push application Docker image
command: |
test ./env/load.sh -f && source ./env/load.sh
ls ./env/load.sh >> /dev/null 2>&1 && source ./env/load.sh
tags="<< parameters.tags >>"
for tag in $tags; do
docker push "$tag"
Expand Down Expand Up @@ -326,18 +425,28 @@ readmyhub_job: &readmyhub_job
cp -v README.md tests/README.md
login: docker login -u $DOCKER_USR -p $DOCKER_PWD

master_filter: &master_filter
filters:
branches:
only:
- master

version: 2.1
workflows:
readme:
jobs:
- readmyhuborb/update:
name: readme
<<: *master_filter
version: 1.1.0
context: docker-hub
build_latest:
jobs:
- dockerorb/build_test_push:
name: build_latest
<<: *readmyhub_job
tags: "gofunky/readmyhub:latest"
filters:
branches:
only:
- master
<<: *master_filter
- dockerorb/build_test_push:
name: build_git
<<: *readmyhub_job
Expand Down

0 comments on commit 0ac8c0d

Please sign in to comment.