Skip to content

Commit f78da21

Browse files
committed
refactor into bash scripts
1 parent dd743ee commit f78da21

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

.circleci/config.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ jobs:
1414
- checkout
1515
- run:
1616
name: Build Docker image
17-
command: |
18-
git describe --tags --always > version
19-
docker build -t bids/${CIRCLE_PROJECT_REPONAME,,} .
20-
mkdir -p ${HOME}/docker
21-
docker save "bids/${CIRCLE_PROJECT_REPONAME,,}" > ~/docker/image.tar
22-
# persist guessed branch so we can use it in deploy/tag
23-
BRANCH=$(git branch --contains tags/${CIRCLE_TAG})
24-
echo -n ${BRANCH} > ~/docker/branch
17+
command: bash build_docker.sh
2518
no_output_timeout: 30m # MCR is a large download
2619
- persist_to_workspace:
2720
root: /home/circleci
@@ -51,23 +44,8 @@ jobs:
5144
- run: docker load -i /tmp/workspace/docker/image.tar
5245
- run:
5346
name: Publish Docker image
54-
command: |
55-
if [[ -n "${CIRCLE_TAG}" ]]; then
56-
echo "${DOCKER_PASS}" | docker login --username "${DOCKER_USER}" --password-stdin
57-
# tag should always be X.Y.Z[-variant]
58-
docker tag bids/${CIRCLE_PROJECT_REPONAME,,} bids/${CIRCLE_PROJECT_REPONAME,,}:${CIRCLE_TAG}
59-
docker push bids/${CIRCLE_PROJECT_REPONAME,,}:${CIRCLE_TAG}
60-
# also publish tag for the corresponding matlab release version, which is the name of the current branch
61-
docker tag bids/${CIRCLE_PROJECT_REPONAME,,} bids/${CIRCLE_PROJECT_REPONAME,,}:${BRANCH}
62-
docker push bids/${CIRCLE_PROJECT_REPONAME,,}:${BRANCH}
63-
BRANCH=$(cat /tmp/workspace/docker/branch)
64-
# update major tag X.Y[-variant] to the latest in this branch
65-
MAJOR_TAG=$(echo "${CIRCLE_TAG}" | sed -rn 's#([[:digit:]]+).([[:digit:]]+).([[:digit:]]+)(.*)#\1.\2\4#p')
66-
if [[ -n "${MAJOR_TAG}" ]] ; then
67-
docker tag bids/${CIRCLE_PROJECT_REPONAME,,} bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}
68-
docker push bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}
69-
fi
70-
fi
47+
command: push_docker.sh
48+
7149
workflows:
7250
build-test-deploy:
7351
jobs:

build_docker.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
3+
# used to build the Docker image for a project in circle CI
4+
5+
git describe --tags --always > version
6+
docker build -t "bids/${CIRCLE_PROJECT_REPONAME,,}" .
7+
mkdir -p ${HOME}/docker
8+
docker save "bids/${CIRCLE_PROJECT_REPONAME,,}" > ~/docker/image.tar
9+
# persist guessed branch so we can use it in deploy/tag
10+
BRANCH=$(git branch --contains tags/${CIRCLE_TAG})
11+
echo -n "${BRANCH}" > ~/docker/branch

push_docker.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /bin/bash
2+
3+
# used to push the Docker image for a project in circle CI
4+
5+
if [[ -n "${CIRCLE_TAG}" ]]; then
6+
7+
echo "${DOCKER_PASS}" | docker login --username "${DOCKER_USER}" --password-stdin
8+
9+
# tag should always be X.Y.Z[-variant]
10+
docker tag "bids/${CIRCLE_PROJECT_REPONAME,,}" "bids/${CIRCLE_PROJECT_REPONAME,,}:${CIRCLE_TAG}"
11+
docker push "bids/${CIRCLE_PROJECT_REPONAME,,}:${CIRCLE_TAG}"
12+
13+
# also publish tag for the corresponding matlab release version, which is the name of the current branch
14+
docker "tag bids/${CIRCLE_PROJECT_REPONAME,,}" "bids/${CIRCLE_PROJECT_REPONAME,,}:${BRANCH}"
15+
docker push "bids/${CIRCLE_PROJECT_REPONAME,,}:${BRANCH}"
16+
BRANCH=$(cat /tmp/workspace/docker/branch)
17+
18+
# update major tag X.Y[-variant] to the latest in this branch
19+
MAJOR_TAG=$(echo "${CIRCLE_TAG}" | sed -rn 's#([[:digit:]]+).([[:digit:]]+).([[:digit:]]+)(.*)#\1.\2\4#p')
20+
if [[ -n "${MAJOR_TAG}" ]] ; then
21+
docker tag "bids/${CIRCLE_PROJECT_REPONAME,,}" "bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}"
22+
docker push "bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}"
23+
fi
24+
25+
fi

0 commit comments

Comments
 (0)