Skip to content

Commit 6fd9f8d

Browse files
somanath21Somanath Hugar
and
Somanath Hugar
authored
#GOV-527 Build and Push Docker Image to Docker-Hub (#58)
* CircieCI to build and push docker image to dockerhub upon github tag release and latest * remove imagetag from latest build --------- Co-authored-by: Somanath Hugar <[email protected]>
1 parent f5e7a49 commit 6fd9f8d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.circleci/config.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
version: 2.1
2+
executors:
3+
docker-executor:
4+
docker:
5+
- image: circleci/openjdk:17-buster-node-browsers-legacy
6+
7+
jobs:
8+
build_and_push_tag_image:
9+
executor: docker-executor
10+
environment:
11+
JVM_OPTS: -Xmx512m
12+
TERM: dumb
13+
GITHUB_TOKEN: ${GITHUB_TOKEN} # Add the GitHub token as an environment variable
14+
15+
steps:
16+
- checkout
17+
- setup_remote_docker:
18+
version: 20.10.14
19+
- run:
20+
name: Build and Push Docker tag Image
21+
command: |
22+
# Set environment variables
23+
IMAGE_TAG=$CIRCLE_TAG
24+
25+
# Check if the Docker image with the same tag already exists in Docker Hub
26+
if curl -s -f -u "$DOCKERHUB_USERNAME":"$DOCKERHUB_PASSWORD" "https://hub.docker.com/v2/repositories/openmf/ph-ee-operations-web/tags/$IMAGE_TAG" > /dev/null; then
27+
echo "Skipping the build and push as the tag $IMAGE_TAG already exists in Docker Hub."
28+
exit 0
29+
fi
30+
31+
# Build and tag the Docker image
32+
./gradlew bootJar
33+
docker build -t "openmf/ph-ee-operations-web:$IMAGE_TAG" .
34+
35+
# Push the Docker image to Docker Hub
36+
docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD"
37+
docker push "openmf/ph-ee-operations-web:$IMAGE_TAG"
38+
39+
# when: always # The job will be executed even if there's no match for the tag filter
40+
41+
build_and_push_latest_image:
42+
executor: docker-executor
43+
environment:
44+
JVM_OPTS: -Xmx512m
45+
TERM: dumb
46+
47+
steps:
48+
- checkout
49+
# Install Docker to build and push the image
50+
- setup_remote_docker:
51+
version: 20.10.14
52+
53+
# Build the Docker image
54+
- run:
55+
name: Build Docker image
56+
command: |
57+
./gradlew bootJar
58+
docker build -t openmf/ph-ee-operations-web:latest .
59+
60+
# Log in to DockerHub using environment variables
61+
- run:
62+
name: Login to DockerHub
63+
command: echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
64+
65+
# Push the Docker image to DockerHub
66+
- run:
67+
name: Push Docker image to DockerHub
68+
command: docker push openmf/ph-ee-operations-web:latest
69+
70+
workflows:
71+
version: 2
72+
build-and-push:
73+
jobs:
74+
- build_and_push_tag_image:
75+
filters:
76+
tags:
77+
only: /^v\d+\.\d+\.\d+$/ # Match tags in the format v1.2.3
78+
context:
79+
- DOCKER
80+
- build_and_push_latest_image:
81+
context:
82+
- DOCKER
83+

0 commit comments

Comments
 (0)