https://github.com/ICIJ/datashare
Raw File
Tip revision: 916cddb1d0b8be88e68b78816c5c0b864d221510 authored by Bruno Thomas on 06 March 2020, 08:28:39 UTC
[release] 5.8.19
Tip revision: 916cddb
config.yml
version: 2
jobs:
  build_back:
    docker:
      - image: circleci/openjdk:8-stretch
      - image: docker.elastic.co/elasticsearch/elasticsearch:6.3.0
        environment:
          - "discovery.type=single-node"
          - "cluster.name=datashare"
          - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
        name: elasticsearch
      - image: redis:4.0.1-alpine
        name: redis
      - image: postgres:11.2
        name: postgresql
        environment:
          POSTGRES_USER: test
          POSTGRES_PASSWORD: test
          POSTGRES_DB: test

    working_directory: /tmp/datashare

    environment:
      MAVEN_OPTS: "-Xms512m -Xmx512m -Xss10M"

    dependencies:
      override:

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "pom.xml" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run:
          name: create a bootstrap datashare DB for jooq code generation
          command: |
            sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
            wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
            sudo apt-get update
            sudo apt-get install postgresql-client
            echo "postgresql:5432:test:test:test" > ~/.pgpass && chmod 600 ~/.pgpass
            psql -h postgresql -U test test -c "CREATE DATABASE datashare;"

      - run: mvn validate

      - save_cache:
          paths:
            - ~/.m2
          key: v1-dependencies-{{ checksum "pom.xml" }}

      - run: mvn -pl datashare-api -am install
      - run: mvn -pl datashare-db liquibase:update
      - run: mvn test
      - run: mvn -Dmaven.test.skip=true package

      - persist_to_workspace:
          root: /tmp/datashare
          paths:
            - datashare-dist

  deploy_back:
    docker:
      - image: circleci/openjdk:8-stretch
    working_directory: /tmp
    steps:
      - attach_workspace:
          at: /tmp/datashare
      - run:
          name: deploy datashare dist jar to github release
          command: |
            upload_url=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -d "{\"tag_name\":\"${CIRCLE_TAG}\", \"name\":\"${CIRCLE_TAG}\",\"body\":\"release ${CIRCLE_TAG}\"}" "https://api.github.com/repos/ICIJ/datashare/releases" | jq -r '.upload_url')
            upload_url="${upload_url%\{*}"
            echo "uploading asset to release url: $upload_url"
            curl -s -m 120 -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/java-archive" --data-binary "@/tmp/datashare/datashare-dist/target/datashare-dist-${CIRCLE_TAG}-all.jar" "$upload_url?name=datashare-dist-${CIRCLE_TAG}.jar&label=datashare-dist-${CIRCLE_TAG}.jar"

  build_front:
    docker:
      - image: circleci/node:10.15.2
      - image: docker.elastic.co/elasticsearch/elasticsearch:6.3.0
        environment:
          - "discovery.type=single-node"
          - "cluster.name=datashare"
          - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
          - "http.cors.enabled=true"
          - "http.cors.allow-origin=*"
          - "http.cors.allow-methods=OPTIONS, HEAD, GET, POST, PUT, DELETE"
        name: elasticsearch
    working_directory: /tmp
    steps:
      - attach_workspace:
           at: /tmp/datashare
      - run:
           name: adds_ssh_dir
           command: |
             mkdir -p ~/.ssh
             chmod 700 ~/.ssh
      - add_ssh_keys:
          fingerprints:
            - "b3:e6:7c:f3:86:9e:e9:88:d1:cf:22:8c:97:3e:93:54"
      - run:
          name: clone
          command: |
            ssh-keyscan github.com >> ~/.ssh/known_hosts
            git clone git@github.com:ICIJ/datashare-client.git
      - run:
          name: release client on GitHub
          command: |
            upload_url=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -d "{ \"tag_name\": \"${CIRCLE_TAG}\", \"target_commitish\": \"master\", \"name\": \"${CIRCLE_TAG}\", \"body\": \"Released by Circle CI\", \"draft\": false, \"prerelease\": false }" "https://api.github.com/repos/ICIJ/datashare-client/releases")
            echo $upload_url > /tmp/datashare-client/datashare-client.url
      - run:
          name: checkout tag
          command: |
            cd datashare-client
            git pull origin master --tags
            git checkout ${CIRCLE_TAG}
      - run:
          name: make install
          command: |
            cd /tmp/datashare-client
            make install

      - save_cache:
          key: dependency-cache-{{ checksum "/tmp/datashare-client/package.json" }}
          paths:
            - /tmp/datashare-client/node_modules

      - run:
          name: run tests and build dist
          command: |
            cd /tmp/datashare-client
            make unit dist

      - persist_to_workspace:
          root: /tmp/datashare-client
          paths:
            - dist
            - datashare-client.url

  deploy_front:
    docker:
      - image: circleci/node:10.15.2
    working_directory: /tmp
    steps:
      - attach_workspace:
          at: /tmp/datashare
      - run:
          name: deploy datashare-client dist to github release
          command: |
            cd /tmp/datashare/dist
            tar czf ../datashare-client-${CIRCLE_TAG}.tgz .
            zip -r ../datashare-client-${CIRCLE_TAG}.zip .
            upload_url=$(cat /tmp/datashare/datashare-client.url | jq -r '.upload_url')
            if [ "$upload_url" = "null" ]; then
              upload_url=$(curl -s "https://api.github.com/repos/ICIJ/datashare-client/releases/tags/${CIRCLE_TAG}" | jq -r '.upload_url')
            fi
            upload_url="${upload_url%\{*}"
            echo "uploading asset to release url: $upload_url"
            curl -s -m 120 -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/zip" --data-binary "@/tmp/datashare/datashare-client-${CIRCLE_TAG}.zip" "$upload_url?name=datashare-client-${CIRCLE_TAG}.zip&label=datashare-client-${CIRCLE_TAG}.zip"
            curl -s -m 120 -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/gzip" --data-binary "@/tmp/datashare/datashare-client-${CIRCLE_TAG}.tgz" "$upload_url?name=datashare-client-${CIRCLE_TAG}.tgz&label=datashare-client-${CIRCLE_TAG}.tgz"

  build_docker:
    docker:
      - image: docker:17.05.0-ce-git
    working_directory: /tmp
    steps:
      - attach_workspace:
           at: /tmp/datashare
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache py-pip=9.0.0-r1
            pip install docker-compose==1.12.0
      - run:
          name: build and push docker image
          command: |
            cp -a /tmp/datashare/dist/ /tmp/datashare/datashare-dist/target/datashare-dist-$CIRCLE_TAG-all/app
            docker build -t icij/datashare:${CIRCLE_TAG} /tmp/datashare/datashare-dist/target/datashare-dist-$CIRCLE_TAG-all/
            docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
            docker push icij/datashare:${CIRCLE_TAG}

  build_installers:
    docker:
      - image: circleci/build-image
    working_directory: /tmp
    steps:
      - attach_workspace:
           at: /tmp/datashare
      - run:
          name: install dependencies
          command: |
            apt-get install -y nsis cpio jq imagemagick icnsutils
            wget http://nsis.sourceforge.net/mediawiki/images/c/c9/Inetc.zip && unzip Inetc.zip && cp Plugins/x86-ansi/INetC.dll /usr/share/nsis/Plugins/
            wget https://github.com/hogliux/bomutils/archive/0.2.tar.gz && tar -zxf 0.2.tar.gz && cd bomutils-0.2 && make && make install
            wget https://github.com/downloads/mackyle/xar/xar-1.6.1.tar.gz && tar -zxf xar-1.6.1.tar.gz && cd xar-1.6.1 && ./configure && make && make install
      - run:
          name: adds_ssh_dir
          command: |
            mkdir -p ~/.ssh
            chmod 700 ~/.ssh
      - add_ssh_keys:
          fingerprints:
          - "b3:e6:7c:f3:86:9e:e9:88:d1:cf:22:8c:97:3e:93:54"
      - run:
          name: checkout
          command: |
            ssh-keyscan github.com >> ~/.ssh/known_hosts
            git clone git@github.com:ICIJ/datashare-installer.git
      - run:
          name: build mac installer
          command: |
            cd /tmp/datashare-installer/mac
            make VERSION=${CIRCLE_TAG} dist/Datashare.pkg
      - run:
          name: build windows installer
          command: |
            cd /tmp/datashare-installer/windows
            make VERSION=${CIRCLE_TAG} dist/installDatashare.exe
      - run:
          name: build linux installer
          command: |
            cd /tmp/datashare-installer/linux
            make VERSION=${CIRCLE_TAG} dist/datashare.sh
      - run:
          name: deploy installers on github
          command: |
            cd /tmp/datashare-installer
            ./deploy.sh ${CIRCLE_TAG}

workflows:
  version: 2
  build_workflow:
    jobs:
      - build_back:
          filters:
              tags:
                  only: /.*/
      - deploy_back:
          requires:
            - build_back
          filters:
            tags:
              only: /^[0-9.]*/
            branches:
              ignore: /.*/
      - build_front:
          requires:
            - deploy_back
          filters:
              tags:
                  only: /^[0-9.]*/
              branches:
                  ignore: /.*/
      - deploy_front:
          requires:
            - build_front
          filters:
            tags:
              only: /^[0-9.]*/
            branches:
              ignore: /.*/
      - build_docker:
          requires:
            - deploy_front
          filters:
              tags:
                  only: /^[0-9.]*/
              branches:
                  ignore: /.*/
      - build_installers:
          requires:
            - build_docker
          filters:
              tags:
                  only: /^[0-9.]*/
              branches:
                  ignore: /.*/
back to top