diff --git a/.circleci/config.yml b/.circleci/config.yml index 73e683e8..b60d5dbe 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,32 +59,16 @@ jobs: paths: - SyncGitRepos.jar - docker_build_dry_run_circle: + docker_build_dry_run: executor: docker-executor steps: - checkout - setup_remote_docker - attach_workspace: at: ~/git-sync - - run: docker build -f docker/CircleCI.Dockerfile . - docker_build_dry_run_drone: - executor: docker-executor - steps: - - checkout - - setup_remote_docker - - attach_workspace: - at: ~/git-sync - - run: docker build -f docker/Drone.Dockerfile . - docker_build_dry_run_vela: - executor: docker-executor - steps: - - checkout - - setup_remote_docker - - attach_workspace: - at: ~/git-sync - - run: docker build -f docker/Vela.Dockerfile . + - run: docker build -f docker/Dockerfile . - publish_circle: + publish: executor: docker-executor steps: - checkout @@ -93,26 +77,21 @@ jobs: at: ~/git-sync - run: | TAG=${CIRCLE_SHA1:0:8} - docker build -t devatherock/git-sync:$TAG -f docker/CircleCI.Dockerfile . - docker tag devatherock/git-sync:$TAG devatherock/git-sync:latest - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - docker push devatherock/git-sync:$TAG - docker push devatherock/git-sync:latest - publish_drone: - executor: docker-executor - steps: - - checkout - - setup_remote_docker - - attach_workspace: - at: ~/git-sync - - run: | - TAG=${CIRCLE_SHA1:0:8} - docker build -t devatherock/drone-git-sync:$TAG -f docker/Drone.Dockerfile . + docker build -t devatherock/drone-git-sync:$TAG -f docker/Dockerfile . docker tag devatherock/drone-git-sync:$TAG devatherock/drone-git-sync:latest + docker tag devatherock/drone-git-sync:$TAG devatherock/vela-git-sync:$TAG + docker tag devatherock/drone-git-sync:$TAG devatherock/vela-git-sync:latest + docker tag devatherock/drone-git-sync:$TAG devatherock/git-sync:$TAG + docker tag devatherock/drone-git-sync:$TAG devatherock/git-sync:latest docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD docker push devatherock/drone-git-sync:$TAG docker push devatherock/drone-git-sync:latest - publish_vela: + docker push devatherock/vela-git-sync:$TAG + docker push devatherock/vela-git-sync:latest + docker push devatherock/git-sync:$TAG + docker push devatherock/git-sync:latest + + publish_release: executor: docker-executor steps: - checkout @@ -120,12 +99,16 @@ jobs: - attach_workspace: at: ~/git-sync - run: | - TAG=${CIRCLE_SHA1:0:8} - docker build -t devatherock/vela-git-sync:$TAG -f docker/Vela.Dockerfile . - docker tag devatherock/vela-git-sync:$TAG devatherock/vela-git-sync:latest + TAG=${CIRCLE_TAG#v} + DEV_TAG=${CIRCLE_SHA1:0:8} docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD + docker pull devatherock/drone-git-sync:$DEV_TAG + docker tag devatherock/drone-git-sync:$DEV_TAG devatherock/drone-git-sync:$TAG + docker tag devatherock/drone-git-sync:$TAG devatherock/vela-git-sync:$TAG + docker tag devatherock/drone-git-sync:$TAG devatherock/git-sync:$TAG + docker push devatherock/drone-git-sync:$TAG docker push devatherock/vela-git-sync:$TAG - docker push devatherock/vela-git-sync:latest + docker push devatherock/git-sync:$TAG notify: docker: @@ -160,29 +143,33 @@ workflows: only: master requires: - test - - publish_circle: + - publish: context: - docker-credentials requires: - groovy_script_to_jar - - publish_drone: + - notify: context: - docker-credentials + - slack-webhook requires: - - groovy_script_to_jar - - publish_vela: + - publish + release: + jobs: + - publish_release: context: - docker-credentials - requires: - - groovy_script_to_jar + filters: + branches: + only: non-existent-branch + tags: + only: /^v[0-9\.]+$/ - notify: context: - docker-credentials - slack-webhook requires: - - publish_circle - - publish_drone - - publish_vela + - publish_release pr_check: jobs: - test: @@ -199,18 +186,8 @@ workflows: ignore: master requires: - test - - docker_build_dry_run_circle: - context: - - docker-credentials - requires: - - groovy_script_to_jar - - docker_build_dry_run_drone: - context: - - docker-credentials - requires: - - groovy_script_to_jar - - docker_build_dry_run_vela: + - docker_build_dry_run: context: - docker-credentials requires: - - groovy_script_to_jar + - groovy_script_to_jar \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c2f9e2c..b13530e1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Changed - test([#9](https://github.com/devatherock/git-sync/issues/9)): Added unit tests +- feat([#5](https://github.com/devatherock/git-sync/issues/5)): Used one dockerfile to simplify build and release ## [1.0.7] - 2021-01-16 ### Changed diff --git a/docker/CircleCI.Dockerfile b/docker/CircleCI.Dockerfile deleted file mode 100755 index 4fc1297c..00000000 --- a/docker/CircleCI.Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM openjdk:8-jre-alpine - -MAINTAINER 'Devaprasadh.Xavier ' - -ENV PLUGIN_TARGET_BRANCH master -ENV PLUGIN_DEBUG false - -ADD SyncGitRepos.jar /scripts/SyncGitRepos.jar -ADD docker/circle-entry-point.sh /scripts/entry-point.sh - -# Install git - Set the user as root for apk -USER root -RUN apk --update add git openssh - -ENTRYPOINT sh /scripts/entry-point.sh \ No newline at end of file diff --git a/docker/Drone.Dockerfile b/docker/Dockerfile old mode 100755 new mode 100644 similarity index 54% rename from docker/Drone.Dockerfile rename to docker/Dockerfile index 4c6e4f68..d14fc747 --- a/docker/Drone.Dockerfile +++ b/docker/Dockerfile @@ -1,15 +1,12 @@ FROM openjdk:8-jre-alpine -MAINTAINER 'Devaprasadh.Xavier ' - -ENV PLUGIN_TARGET_BRANCH master -ENV PLUGIN_DEBUG false - -ADD SyncGitRepos.jar /scripts/SyncGitRepos.jar -ADD docker/drone-entry-point.sh /scripts/entry-point.sh +LABEL maintainer="devatherock@gmail.com>" # Install git - Set the user as root for apk USER root RUN apk --update add git openssh +ADD SyncGitRepos.jar /scripts/SyncGitRepos.jar +ADD docker/entry-point.sh /scripts/entry-point.sh + ENTRYPOINT sh /scripts/entry-point.sh \ No newline at end of file diff --git a/docker/Vela.Dockerfile b/docker/Vela.Dockerfile deleted file mode 100644 index 8de25d1e..00000000 --- a/docker/Vela.Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM openjdk:8-jre-alpine - -MAINTAINER 'Devaprasadh.Xavier ' - -ENV PARAMETER_TARGET_BRANCH master -ENV PARAMETER_DEBUG false - -ADD SyncGitRepos.jar /scripts/SyncGitRepos.jar -ADD docker/vela-entry-point.sh /scripts/entry-point.sh - -# Install git - Set the user as root for apk -USER root -RUN apk --update add git openssh - -ENTRYPOINT sh /scripts/entry-point.sh \ No newline at end of file diff --git a/docker/circle-entry-point.sh b/docker/circle-entry-point.sh deleted file mode 100755 index bcfa065b..00000000 --- a/docker/circle-entry-point.sh +++ /dev/null @@ -1,2 +0,0 @@ -java -jar /scripts/SyncGitRepos.jar -tr "$PLUGIN_TARGET_REPO" -tb "$PLUGIN_TARGET_BRANCH" -sc "$PLUGIN_START_COMMIT" \ - --debug $PLUGIN_DEBUG -n "$CIRCLE_USERNAME" -t "$GIT_SYNC_TOKEN" \ No newline at end of file diff --git a/docker/drone-entry-point.sh b/docker/drone-entry-point.sh deleted file mode 100755 index 8402ae7e..00000000 --- a/docker/drone-entry-point.sh +++ /dev/null @@ -1,2 +0,0 @@ -java -jar /scripts/SyncGitRepos.jar -tr "$PLUGIN_TARGET_REPO" -tb "$PLUGIN_TARGET_BRANCH" -sc "$PLUGIN_START_COMMIT" \ - --debug $PLUGIN_DEBUG -n "$DRONE_COMMIT_AUTHOR" -e "$DRONE_COMMIT_AUTHOR_EMAIL" -t "$GIT_SYNC_TOKEN" \ No newline at end of file diff --git a/docker/entry-point.sh b/docker/entry-point.sh new file mode 100644 index 00000000..cea6c4c6 --- /dev/null +++ b/docker/entry-point.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +TARGET_BRANCH=master +if [ ! -z "$PLUGIN_TARGET_BRANCH" ]; then + TARGET_BRANCH=$PLUGIN_TARGET_BRANCH +elif [ ! -z "$PARAMETER_TARGET_BRANCH" ]; then + TARGET_BRANCH=$PARAMETER_TARGET_BRANCH +fi + +ENABLE_DEBUG=false +if [ "$PLUGIN_DEBUG" = "true" ] || [ "$PARAMETER_DEBUG" = "true" ]; then + ENABLE_DEBUG=true +fi + +if [ ! -z "$PLUGIN_TARGET_REPO" ]; then + TARGET_REPO=$PLUGIN_TARGET_REPO +elif [ ! -z "$PARAMETER_TARGET_REPO" ]; then + TARGET_REPO=$PARAMETER_TARGET_REPO +fi + +if [ ! -z "$PLUGIN_START_COMMIT" ]; then + START_COMMIT=$PLUGIN_START_COMMIT +elif [ ! -z "$PARAMETER_START_COMMIT" ]; then + START_COMMIT=$PARAMETER_START_COMMIT +fi + +if [ ! -z "$DRONE_COMMIT_AUTHOR" ]; then + USERNAME=$DRONE_COMMIT_AUTHOR +elif [ ! -z "$BUILD_AUTHOR" ]; then + USERNAME=$BUILD_AUTHOR +elif [ ! -z "$CIRCLE_USERNAME" ]; then + USERNAME=$CIRCLE_USERNAME +fi + +if [ ! -z "$DRONE_COMMIT_AUTHOR_EMAIL" ]; then + EMAIL=$DRONE_COMMIT_AUTHOR_EMAIL +elif [ ! -z "$BUILD_AUTHOR_EMAIL" ]; then + EMAIL=$BUILD_AUTHOR_EMAIL +fi + +ALL_OPTS="-tb $TARGET_BRANCH --debug $ENABLE_DEBUG -t $GIT_SYNC_TOKEN" + +if [ ! -z "$TARGET_REPO" ]; then + ALL_OPTS="$ALL_OPTS -tr $TARGET_REPO" +fi + +if [ ! -z "$START_COMMIT" ]; then + ALL_OPTS="$ALL_OPTS -sc $START_COMMIT" +fi + +if [ ! -z "$USERNAME" ]; then + ALL_OPTS="$ALL_OPTS -n $USERNAME" +fi + +if [ ! -z "$EMAIL" ]; then + ALL_OPTS="$ALL_OPTS -e $EMAIL" +fi + +java -jar /scripts/SyncGitRepos.jar $ALL_OPTS \ No newline at end of file diff --git a/docker/vela-entry-point.sh b/docker/vela-entry-point.sh deleted file mode 100644 index 46beae95..00000000 --- a/docker/vela-entry-point.sh +++ /dev/null @@ -1,4 +0,0 @@ -java -jar /scripts/SyncGitRepos.jar -tr "$PARAMETER_TARGET_REPO" \ - -tb "$PARAMETER_TARGET_BRANCH" -sc "$PARAMETER_START_COMMIT" \ - --debug $PARAMETER_DEBUG -n "$BUILD_AUTHOR" -e "$BUILD_AUTHOR_EMAIL" \ - -t "$GIT_SYNC_TOKEN" \ No newline at end of file