version: 2 build-distro-bin: &build-distro-bin machine: true steps: - checkout # cannot interpolate env var and use as a cache key so just copy the Dockerfile to another filename - run: cp docker/distro_release/Dockerfile.$CIRCLE_JOB docker/distro_release/Dockerfile - restore_cache: keys: - v1-{{ .Environment.CIRCLE_JOB }}-image-{{ checksum "docker/distro_release/Dockerfile" }} - restore_cache: keys: - v1-{{ .Environment.CIRCLE_JOB }}-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: load or build docker image command: | if [[ -e ~/image.tar ]]; then docker load -i ~/image.tar else docker build --rm=false -t $CIRCLE_JOB -f docker/distro_release/Dockerfile.$CIRCLE_JOB docker/distro_release/ docker save $CIRCLE_JOB > ~/image.tar fi - run: name: build binary command: | docker run -it \ -v $HOME/.stack:/root/.stack \ -v $(pwd):/source \ -v $HOME/bin/:/root/.local/bin/ \ $CIRCLE_JOB build --allow-different-user --install-ghc --copy-bins # volumes owned by root if chown is not done the save_cache step fails silently sudo chown -R circleci:circleci ~/.stack .stack-work - run: name: compress binary command: | mkdir -p /tmp/workspace/bin cd /tmp/workspace/bin tar cvJf postgrest-$CIRCLE_TAG-$CIRCLE_JOB.tar.xz -C ~/bin postgrest - persist_to_workspace: root: /tmp/workspace paths: - bin/* - save_cache: paths: - ~/image.tar key: v1-{{ .Environment.CIRCLE_JOB }}-image-{{ checksum "docker/distro_release/Dockerfile" }} - save_cache: paths: - "~/.stack" - ".stack-work" key: v1-{{ .Environment.CIRCLE_JOB }}-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} jobs: build-cache: docker: - image: circleci/buildpack-deps:trusty steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y --only-upgrade binutils sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests dependencies command: | stack build --fast -j1 --only-dependencies stack build --fast --test --no-run-tests --only-dependencies - save_cache: paths: - "~/.stack" - ".stack-work" key: v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests style: docker: - image: nixos/nix:2.3 steps: - checkout - run: name: Install linting and styling scripts command: nix-env -f default.nix -iA lint style - run: name: Run linter command: | echo 'Note: For checking this locally, use `make lint`. Or, if using `nix`, run `nix-shell --run postgrest-lint`' postgrest-lint - run: name: Run style check command: | echo 'Note: For checking this locally, use `make style`. Or, if using `nix`, run `nix-shell --run postgrest-style`' postgrest-style-check build-test-9.4: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - image: circleci/postgres:9.4.26 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install ncat command: | # utility needed to test socket connection with curl < 7.40 sudo apt-get install nmap - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y --only-upgrade binutils sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests dependencies command: | stack build --fast -j1 --only-dependencies stack build --fast --test --no-run-tests --only-dependencies - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run tests command: | POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test test/io-tests.sh build-test-9.6: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - image: circleci/postgres:9.6.17 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run tests command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test postgrest:spec build-test-10: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - image: circleci/postgres:10.12 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run tests command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test postgrest:spec build-test-11: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - image: circleci/postgres:11.7 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run tests command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test postgrest:spec build-test-12: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - image: circleci/postgres:12.2 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y postgresql-client stack setup - run: name: build src and tests command: | stack build --fast -j1 stack build --fast --test --no-run-tests - run: name: run tests command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test postgrest:spec build-prof-test: docker: - image: circleci/buildpack-deps:trusty environment: - PGHOST=localhost - TERM=xterm - image: circleci/postgres:9.6.17 environment: - POSTGRES_USER=circleci - POSTGRES_DB=circleci - POSTGRES_HOST_AUTH_METHOD=trust steps: - checkout - restore_cache: keys: - v1-stack-prof-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: install stack & dependencies command: | curl -L https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz | tar zx -C /tmp sudo mv /tmp/stack-2.1.3-linux-x86_64/stack /usr/bin sudo apt-get update sudo apt-get install -y libgmp-dev sudo apt-get install -y postgresql-client stack setup - run: name: build dependencies with profiling enabled command: | stack build --profile -j1 --only-dependencies - save_cache: paths: - "~/.stack" - ".stack-work" key: v1-stack-prof-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }} - run: name: build with profiling enabled command: | stack build --profile -j1 - run: name: run memory usage tests command: | test/create_test_db "postgres://circleci@localhost" postgrest_test test/memory-tests.sh centos7: <<: *build-distro-bin ubuntu: <<: *build-distro-bin ubuntui386: <<: *build-distro-bin release: docker: - image: circleci/golang:1.9 steps: - attach_workspace: at: /tmp/workspace - checkout - run: name: add body and tars to github release command: | go get -u github.com/tcnksm/ghr START=$(echo $CIRCLE_TAG | cut -c2-) END='## \[' BODY=$(sed -n "1,/$START/d;/$END/q;p" CHANGELOG.md) ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -b "$BODY" --replace $CIRCLE_TAG /tmp/workspace/bin - setup_remote_docker - run: name: publish docker image command: | docker build --build-arg POSTGREST_VERSION=$CIRCLE_TAG -t postgrest ./docker/ docker login -u $DOCKER_USER -p $DOCKER_PASS docker tag postgrest postgrest/postgrest:$CIRCLE_TAG docker push postgrest/postgrest:$CIRCLE_TAG docker tag postgrest postgrest/postgrest:latest docker push postgrest/postgrest:latest build-nix: machine: true steps: - checkout - run: name: Install Nix command: | curl -L https://nixos.org/nix/install | sh echo "source $HOME/.nix-profile/etc/profile.d/nix.sh" >> $BASH_ENV - run: name: Install and use the Cachix binary cache command: | nix-env -iA cachix -f https://cachix.org/api/v1/install cachix use postgrest - run: name: Build the dynamic PostgREST executable command: | # We build the dynamic postgrest executable first in order to fail fast if anything # should be wrong with the source code. nix-build -A postgrest - restore_cache: keys: - v1-cabal-nix-dependencies-{{ checksum "postgrest.cabal" }} - run: name: Run the spec tests against all supported PostgreSQL versions command: | # Our utility scripts use cabal to run the tests, which will pick up all the libraries that # are built with Nix. So this should only ever build the PostgREST itself and be reasonably # quick. We accelerate that part further by caching `~/.cabal` and `dist-newstyle`. nix-shell --run postgrest-test-spec-all - save_cache: paths: - "~/.cabal" - "dist-newstyle" key: v1-cabal-nix-dependencies-{{ checksum "postgrest.cabal" }} - run: name: Build all derivations from default.nix and push results to Cachix command: | # Only push to the cache when CircleCI makes the CACHIX_SIGNING_KEY available (e.g. not for # pull requests). if [ -n "${CACHIX_SIGNING_KEY:-""}" ]; then echo "Building and caching all derivations..." nix-build | cachix push postgrest else echo "Building all derivations (caching skipped for outside pull requests)..." nix-build fi workflows: version: 2 build-test-release: jobs: - build-cache: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ - style: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ - build-test-9.4: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ requires: - build-cache - build-test-9.6: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ requires: - build-cache - build-test-10: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ requires: - build-cache - build-test-11: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ requires: - build-cache - build-test-12: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ requires: - build-cache - build-prof-test: filters: tags: only: /v[0-9]+(\.[0-9]+)*/ - centos7: requires: - build-test-9.4 - build-test-9.6 - build-test-10 - build-test-11 - build-test-12 - build-prof-test filters: tags: only: /v[0-9]+(\.[0-9]+)*/ branches: ignore: /.*/ - ubuntu: requires: - build-test-9.4 - build-test-9.6 - build-test-10 - build-test-11 - build-test-12 - build-prof-test filters: tags: only: /v[0-9]+(\.[0-9]+)*/ branches: ignore: /.*/ - ubuntui386: requires: - build-test-9.4 - build-test-9.6 - build-test-10 - build-test-11 - build-test-12 - build-prof-test filters: tags: only: /v[0-9]+(\.[0-9]+)*/ branches: ignore: /.*/ - release: requires: - centos7 - ubuntu - ubuntui386 filters: tags: only: /v[0-9]+(\.[0-9]+)*/ - build-nix: filters: tags: only: /v[0-9]+(\.[0-9]+)*/