From 97a7ec10eb3136a2a7cb660c051bd2a288c63fff Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 01:48:27 +0200 Subject: [PATCH 01/13] New ci flow Run tests for every commit Run tests -> build for every branch Run tests -> build -> publish for every tag --- .circleci/config.yml | 102 ++++++++++++++++++++++++++++--------------- Dockerfile-ci | 6 +++ 2 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 Dockerfile-ci diff --git a/.circleci/config.yml b/.circleci/config.yml index 820edfb..161c3fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2 jobs: - build: + test: docker: - image: circleci/openjdk:11 - image: mongo:4 @@ -16,21 +16,14 @@ jobs: keys: - gradle-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "build.gradle" }} - - restore_cache: - keys: - - gradle-build-caches-{{ .Environment.CACHE_VERSION }}-{{ .Revision }} - - run: - name: Restoring Gradle Build Caches - command: | - [ -d ~/gradle-build-caches ] && - [ -n "$(ls -A ~/gradle-build-caches)" ] && - rm -rf ~/.gradle/caches/build-cache-* && - mv ~/gradle-build-caches/* ~/.gradle/caches/ || true + name: Run tests + environment: + MONGODB_ADDR: 127.0.0.1 + command: ./gradlew test - - run: - name: Downloading Dependencies - command: ./gradlew --max-workers 2 downloadDependencies + - store_test_results: + path: ./build/test-results/ - save_cache: paths: @@ -42,37 +35,55 @@ jobs: - ~/.gradle/caches/ key: gradle-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "build.gradle" }} + build: + docker: + - image: circleci/openjdk:8 + steps: + - checkout + + - restore_cache: + keys: + - gradle-wrapper-{{ .Environment.CACHE_VERSION }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} + + - restore_cache: + keys: + - gradle-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "build.gradle" }} + - run: name: Build Project command: ./gradlew --max-workers 2 --continue clean shadowJar -x test --info - - run: - name: Run tests - environment: - MONGODB_PORT_27017_TCP_ADDR: 127.0.0.1 - command: ./gradlew test - - store_artifacts: path: ./build/libs/glicko-rater-1.0.jar prefix: jar - - store_test_results: - path: ./build/test-results/ + - persist_to_workspace: + root: ./artifacts + paths: ./build/libs/glicko-rater-1.0.jar - - run: - name: Collecting Gradle Build Caches - command: | - mkdir -p ~/gradle-build-caches && - [ -d ~/.gradle/caches ] && - [ -n "$(ls -Ad ~/.gradle/caches/build-cache-* 2>/dev/null)" ] && - mv ~/.gradle/caches/build-cache-* ~/gradle-build-caches || true - when: always + - save_cache: + paths: + - ~/.gradle/wrapper/ + key: gradle-wrapper-{{ .Environment.CACHE_VERSION }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - save_cache: paths: - - ~/gradle-build-caches - key: gradle-build-caches-{{ .Environment.CACHE_VERSION }}-{{ .Revision }} - when: always + - ~/.gradle/caches/ + key: gradle-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "build.gradle" }} + + publish: + docker: + - image: cibuilds/github:0.10 + + steps: + - attach_workspace: + at: ./artifacts + + - run: + name: "Publish Release on GitHub" + command: | + VERSION=$(git describe --tags) + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/ - setup_remote_docker: docker_layer_caching: true @@ -80,6 +91,27 @@ jobs: - run: name: Build and push docker image command: | - docker build --tag desp/glickorater:${CIRCLE_SHA1} . + VERSION=$(git describe --tags) + docker build --tag desp/glickorater:${VERSION} Dockerfile-ci echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker push desp/glickorater:${CIRCLE_SHA1} + docker push desp/glickorater:${VERSION} + +workflows: + version: 2 + main: + jobs: + - test + - build: + requires: + - test + filters: + tags: + only: /.*/ + - publish: + requires: + - build + filters: + branches: + ignore: /.*/ + tags: + only: /.*/ diff --git a/Dockerfile-ci b/Dockerfile-ci new file mode 100644 index 0000000..78a0499 --- /dev/null +++ b/Dockerfile-ci @@ -0,0 +1,6 @@ +FROM anapsix/alpine-java:8 +WORKDIR /app + +ADD ./artifacts/glicko-rater-*.jar /app + +CMD java -jar glicko-rater-*.jar From e244896570d346f3aab91793b8eef92978b4c330 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 01:53:12 +0200 Subject: [PATCH 02/13] Bump openjdk version for build as well --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 161c3fe..231581c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: build: docker: - - image: circleci/openjdk:8 + - image: circleci/openjdk:11 steps: - checkout From 9aab8b9dde7799b36fc14487882a7612e1c5d4c3 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 01:59:53 +0200 Subject: [PATCH 03/13] Attach to workspace --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 231581c..032531a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,6 +41,9 @@ jobs: steps: - checkout + - attach_workspace: + at: ./artifacts + - restore_cache: keys: - gradle-wrapper-{{ .Environment.CACHE_VERSION }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} From c66ddce22bb81ea4e0f1c66c2497f1a689acf63f Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:07:16 +0200 Subject: [PATCH 04/13] Attempt another path for workspace storage --- .circleci/config.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 032531a..8abd09e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,9 +41,6 @@ jobs: steps: - checkout - - attach_workspace: - at: ./artifacts - - restore_cache: keys: - gradle-wrapper-{{ .Environment.CACHE_VERSION }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} @@ -61,7 +58,7 @@ jobs: prefix: jar - persist_to_workspace: - root: ./artifacts + root: ./build/libs paths: ./build/libs/glicko-rater-1.0.jar - save_cache: @@ -80,13 +77,13 @@ jobs: steps: - attach_workspace: - at: ./artifacts + at: ./build/libs - run: name: "Publish Release on GitHub" command: | VERSION=$(git describe --tags) - ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/ + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./build/libs - setup_remote_docker: docker_layer_caching: true From f5c523cb3ab864d64079a47c0656ee3d6085ff1c Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:11:55 +0200 Subject: [PATCH 05/13] Forgot to change paths for artifacts --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8abd09e..c508cee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,7 +59,7 @@ jobs: - persist_to_workspace: root: ./build/libs - paths: ./build/libs/glicko-rater-1.0.jar + paths: glicko-rater-1.0.jar - save_cache: paths: From 8ccc6d88bc7725e60bc4b41e98097cdd3edddb39 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:17:15 +0200 Subject: [PATCH 06/13] Enable release for master branch --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c508cee..c2fb80c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -112,6 +112,6 @@ workflows: - build filters: branches: - ignore: /.*/ + only: master tags: only: /.*/ From b6186214a7b0c0f00da5f5f0d731f8c113135e9c Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:21:15 +0200 Subject: [PATCH 07/13] Check out code before release --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c2fb80c..a85ff07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,6 +76,8 @@ jobs: - image: cibuilds/github:0.10 steps: + - checkout + - attach_workspace: at: ./build/libs From 77e946371a2bb9a91ef99eca2741b352a22d3720 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:31:31 +0200 Subject: [PATCH 08/13] Publish to github in separate step --- .circleci/config.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a85ff07..88bd68f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ jobs: test: docker: - image: circleci/openjdk:11 - - image: mongo:4 + - image: circleci/mongo:4.1-ram steps: - checkout @@ -37,7 +37,7 @@ jobs: build: docker: - - image: circleci/openjdk:11 + - image: circleci/docker:11 steps: - checkout @@ -71,7 +71,7 @@ jobs: - ~/.gradle/caches/ key: gradle-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "build.gradle" }} - publish: + publish-to-github: docker: - image: cibuilds/github:0.10 @@ -87,6 +87,16 @@ jobs: VERSION=$(git describe --tags) ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./build/libs + publish-to-docker-hub: + docker: + - image: cibuilds/docker:18.06.1 + + steps: + - checkout + + - attach_workspace: + at: ./build/libs + - setup_remote_docker: docker_layer_caching: true @@ -109,7 +119,15 @@ workflows: filters: tags: only: /.*/ - - publish: + - publish-to-github: + requires: + - build + filters: + branches: + only: master + tags: + only: /.*/ + - publish-to-docker-hub: requires: - build filters: From c6aba7783872fa4374244377442a30072ecc4099 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:34:37 +0200 Subject: [PATCH 09/13] Build and testt in parallel --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 88bd68f..5ac2f90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -114,14 +114,13 @@ workflows: jobs: - test - build: - requires: - - test filters: tags: only: /.*/ - publish-to-github: requires: - build + - test filters: branches: only: master @@ -130,6 +129,7 @@ workflows: - publish-to-docker-hub: requires: - build + - test filters: branches: only: master From 52ed7301bde8733c08d3ff9c216f65bf05a979ad Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:36:36 +0200 Subject: [PATCH 10/13] Revert to official mongo image --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ac2f90..3e6b5aa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ jobs: test: docker: - image: circleci/openjdk:11 - - image: circleci/mongo:4.1-ram + - image: mongo:4 steps: - checkout From 061de66a15238683e913e160fc0d073b583460e8 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:37:51 +0200 Subject: [PATCH 11/13] Fix accidental typo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e6b5aa..c659845 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: build: docker: - - image: circleci/docker:11 + - image: circleci/openjdk:11 steps: - checkout From e0980bb7c9fbf25c242eaa2c6a014e5913a56fdb Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:41:57 +0200 Subject: [PATCH 12/13] Don't need custom Dockerfile for ci any more --- .circleci/config.yml | 2 +- Dockerfile-ci | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 Dockerfile-ci diff --git a/.circleci/config.yml b/.circleci/config.yml index c659845..5fcd3c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -104,7 +104,7 @@ jobs: name: Build and push docker image command: | VERSION=$(git describe --tags) - docker build --tag desp/glickorater:${VERSION} Dockerfile-ci + docker build --tag desp/glickorater:${VERSION} . echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker push desp/glickorater:${VERSION} diff --git a/Dockerfile-ci b/Dockerfile-ci deleted file mode 100644 index 78a0499..0000000 --- a/Dockerfile-ci +++ /dev/null @@ -1,6 +0,0 @@ -FROM anapsix/alpine-java:8 -WORKDIR /app - -ADD ./artifacts/glicko-rater-*.jar /app - -CMD java -jar glicko-rater-*.jar From a74586b213488dc976eabbe7572e6599831bff10 Mon Sep 17 00:00:00 2001 From: Vegar Sechmann Molvig Date: Sat, 6 Oct 2018 02:51:55 +0200 Subject: [PATCH 13/13] Change to official jre 11 image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index aca4061..aa5b88c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM anapsix/alpine-java:8 +FROM openjdk:11-jre-slim WORKDIR /app ADD ./build/libs/glicko-rater-*.jar /app