Skip to content

Commit

Permalink
add reusable build function
Browse files Browse the repository at this point in the history
  • Loading branch information
zainasir committed Jan 6, 2025
1 parent de221ac commit fdb6583
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ defaults: &defaults
- image: circleci/node:15.2.1-browsers

version: 2
commands:
build_push_image:
parameters:
push:
description: Push image to DockerHub
type: string
default: "false"
steps:
- run:
name: Build cBioPortal docker image
environment:
DOCKER_REPO: cbioportal/cbioportal-dev
command: |
export DOCKER_TAG=$CIRCLE_SHA1
URL="https://hub.docker.com/v2/repositories/cbioportal/cbioportal-dev/tags/$DOCKER_TAG-web-shenandoah"
TAG_FOUND=$(curl -s $URL | jq -r .name)
if [ $TAG_FOUND = "$DOCKER_TAG-web-shenandoah" ]; then
echo "Image already exists. Skipping build step!"
exit 0
fi
cd cbioportal-test
./scripts/build-push-image.sh --src=/tmp/repos/cbioportal --push=<<parameters.push>> --skip_web_and_data=true
EXISTS=$(docker inspect --type=image $DOCKER_REPO:$DOCKER_TAG-web-shenandoah > /dev/null; echo $?)
if [ $EXISTS -eq 0 ]; then
echo "Build succeeded!"
else
echo "Build failed!"
exit 1
fi
jobs:
build_backend:
docker:
Expand Down Expand Up @@ -263,50 +293,26 @@ jobs:
image: ubuntu-2204:2024.08.1
resource_class: medium
working_directory: /tmp/repos
parameters:
push:
description: Push image to Docker Hub
type: boolean
default: false
steps:
- attach_workspace:
at: /tmp/repos
- checkout:
path: /tmp/repos/cbioportal
- run:
name: Build cBioPortal docker image
environment:
DOCKER_REPO: cbioportal/cbioportal-dev
command: |
export DOCKER_TAG=$CIRCLE_SHA1
URL="https://hub.docker.com/v2/repositories/cbioportal/cbioportal-dev/tags/$DOCKER_TAG-web-shenandoah"
TAG_FOUND=$(curl -s $URL | jq -r .name)
if [ $TAG_FOUND = "$DOCKER_TAG-web-shenandoah" ]; then
echo "Image already exists. Skipping build step!"
exit 0
fi
cd cbioportal-test
./scripts/build-push-image.sh --src=/tmp/repos/cbioportal --push=false --skip_web_and_data=true
EXISTS=$(docker manifest inspect $DOCKER_REPO:$DOCKER_TAG-web-shenandoah > /dev/null; echo $?)
if [ $EXISTS -eq 0 ]; then
echo "Build succeeded!"
else
echo "Build failed!"
exit 1
fi
- build_push_image:
push: "false"

push_image:
machine:
image: ubuntu-2204:2024.08.1
resource_class: medium
steps:
- run:
name: Log in to Docker
command: |
export DOCKER_TAG=$CIRCLE_SHA1-web-shenandoah
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- run:
name: Push cBioPortal image to Docker Hub
environment:
DOCKER_REPO: cbioportal/cbioportal-dev
command: |
export DOCKER_TAG=$CIRCLE_SHA1-web-shenandoah
docker image push cbioportal/cbioportal-dev:$DOCKER_TAG
- build_push_image:
push: "true"

run_api_tests:
machine:
Expand Down

0 comments on commit fdb6583

Please sign in to comment.