|
1 | 1 | version: 2.1 |
2 | | -orbs: |
3 | | - slack: circleci/slack@4.12.5 |
4 | | - aws-ecr: circleci/aws-ecr@8.2.1 |
5 | | -jobs: |
6 | | - build: |
| 2 | +executors: |
| 3 | + docker-executor: |
7 | 4 | docker: |
8 | | - - image: cimg/openjdk:17.0.0 |
9 | | - - image: docker:17.05.0-ce-git |
10 | | - working_directory: ~/repo |
| 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-bulk-processor/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-bulk-processor:$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-bulk-processor:$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 |
11 | 43 | environment: |
12 | | - # Customize the JVM maximum heap limit |
13 | 44 | JVM_OPTS: -Xmx512m |
14 | 45 | TERM: dumb |
| 46 | + |
15 | 47 | steps: |
16 | 48 | - checkout |
17 | | - - setup_remote_docker |
18 | | -# - slack/notify: |
19 | | -# event: fail |
20 | | -# mentions: '@here' |
21 | | -# template: basic_fail_1 |
22 | | -# - slack/notify: |
23 | | -# event: pass |
24 | | -# template: basic_success_1 |
25 | | - - run: ./gradlew clean bootJar |
26 | | - - aws-ecr/build-and-push-image: |
27 | | - aws-access-key-id: AWS_ACCESS_KEY_ID |
28 | | - aws-secret-access-key: AWS_SECRET_ACCESS_KEY |
29 | | - extra-build-args: '--compress' |
30 | | - push-image: true |
31 | | - region: "$REGION" |
32 | | - registry-id: AWS_REGISTRY_ID |
33 | | - repo: phee-bulk-processor |
34 | | - repo-scan-on-push: true |
35 | | - role-arn: arn:aws:iam::419830066942:role/CustomAdmin |
36 | | - tag: latest |
37 | | - # - run: ./gradlew cucumberCli |
38 | | - # run tests! Slack Success/Fail Notification Step |
39 | | - #- run: ./gradlew test |
| 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-bulk-processor: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-bulk-processor:latest |
| 69 | + |
40 | 70 | workflows: |
41 | | - build_and_push_image: |
| 71 | + version: 2 |
| 72 | + build-and-push: |
42 | 73 | jobs: |
43 | | - - build: |
| 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: |
44 | 81 | context: |
45 | | - - AWS |
46 | | - - slack |
| 82 | + - DOCKER |
| 83 | + |
0 commit comments