Skip to content

Commit

Permalink
CircieCI to build and push docker image to dockerhub upon github tag …
Browse files Browse the repository at this point in the history
…release and latest (#39)

Co-authored-by: Somanath Hugar <[email protected]>
  • Loading branch information
somanath21 and Somanath Hugar authored Aug 1, 2023
1 parent 18e1d02 commit a7630e9
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ jobs:
executor: docker-executor
environment:
JVM_OPTS: -Xmx512m
TERM: dumb
TERM: dumb
GITHUB_TOKEN: ${GITHUB_TOKEN} # Add the GitHub token as an environment variable

steps:
- checkout
# Install Docker to build and push the image
- setup_remote_docker:
version: 20.10.14

# Build the Docker image
- run:
name: Build Docker image
name: Build and Push Docker tag Image
command: |
./gradlew bootJar
docker build -t openmf/ph-ee-connector-ams-mifos:${CIRCLE_TAG} .
# Set environment variables
IMAGE_TAG=$CIRCLE_TAG
# Log in to DockerHub using environment variables
- run:
name: Login to DockerHub
command: echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
# Check if the Docker image with the same tag already exists in Docker Hub
if curl -s -f -u "$DOCKERHUB_USERNAME":"$DOCKERHUB_PASSWORD" "https://hub.docker.com/v2/repositories/openmf/ph-ee-connector-ams-mifos/tags/$IMAGE_TAG" > /dev/null; then
echo "Skipping the build and push as the tag $IMAGE_TAG already exists in Docker Hub."
exit 0
fi
# Push the Docker image to DockerHub
- run:
name: Push Docker image to DockerHub
command: docker push openmf/ph-ee-connector-ams-mifos:${CIRCLE_TAG}
# Build and tag the Docker image
./gradlew bootJar
docker build -t "openmf/ph-ee-connector-ams-mifos:$IMAGE_TAG" .
# Push the Docker image to Docker Hub
docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD"
docker push "openmf/ph-ee-connector-ams-mifos:$IMAGE_TAG"
# when: always # The job will be executed even if there's no match for the tag filter

build_and_push_latest_image:
executor: docker-executor
environment:
Expand All @@ -50,6 +54,7 @@ jobs:
- run:
name: Build Docker image
command: |
IMAGE_TAG=$CIRCLE_TAG
./gradlew bootJar
docker build -t openmf/ph-ee-connector-ams-mifos:latest .
Expand All @@ -65,15 +70,15 @@ jobs:

workflows:
version: 2
build_and_push:
build-and-push:
jobs:
- build_and_push_tag_image:
filters:
tags:
only: /^v\d+\.\d+\.\d+$/ # This regex will match tags in the format 'vX.X.X', e.g., v1.2.3
only: /^v\d+\.\d+\.\d+$/ # Match tags in the format v1.2.3
context:
- DOCKER

- DOCKER
- build_and_push_latest_image:
context:
- DOCKER
- DOCKER

0 comments on commit a7630e9

Please sign in to comment.