generated from openMF/ph-ee-start-here
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#GOV-527 Build and Push Docker Image to Docker Hub (#46)
* Added CircleCI to build and push docker imageto docker hub * CircieCI to build and push docker image to dockerhub upon github tag release and latest --------- Co-authored-by: Somanath Hugar <[email protected]>
- Loading branch information
1 parent
bf7a43e
commit 9c8755f
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
version: 2.1 | ||
executors: | ||
docker-executor: | ||
docker: | ||
- image: circleci/openjdk:17-buster-node-browsers-legacy | ||
|
||
jobs: | ||
build_and_push_tag_image: | ||
executor: docker-executor | ||
environment: | ||
JVM_OPTS: -Xmx512m | ||
TERM: dumb | ||
GITHUB_TOKEN: ${GITHUB_TOKEN} # Add the GitHub token as an environment variable | ||
|
||
steps: | ||
- checkout | ||
- setup_remote_docker: | ||
version: 20.10.14 | ||
- run: | ||
name: Build and Push Docker tag Image | ||
command: | | ||
# Set environment variables | ||
IMAGE_TAG=$CIRCLE_TAG | ||
# 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-importer-rdbms/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 | ||
# Build and tag the Docker image | ||
./gradlew bootJar | ||
docker build -t "openmf/ph-ee-importer-rdbms:$IMAGE_TAG" . | ||
# Push the Docker image to Docker Hub | ||
docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD" | ||
docker push "openmf/ph-ee-importer-rdbms:$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: | ||
JVM_OPTS: -Xmx512m | ||
TERM: dumb | ||
|
||
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 | ||
command: | | ||
IMAGE_TAG=$CIRCLE_TAG | ||
./gradlew bootJar | ||
docker build -t openmf/ph-ee-importer-rdbms:latest . | ||
# Log in to DockerHub using environment variables | ||
- run: | ||
name: Login to DockerHub | ||
command: echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin | ||
|
||
# Push the Docker image to DockerHub | ||
- run: | ||
name: Push Docker image to DockerHub | ||
command: docker push openmf/ph-ee-importer-rdbms:latest | ||
|
||
workflows: | ||
version: 2 | ||
build-and-push: | ||
jobs: | ||
- build_and_push_tag_image: | ||
filters: | ||
tags: | ||
only: /^v\d+\.\d+\.\d+$/ # Match tags in the format v1.2.3 | ||
context: | ||
- DOCKER | ||
- build_and_push_latest_image: | ||
context: | ||
- DOCKER | ||
|