Skip to content

Commit

Permalink
Switch from stack to cabal-install for building server code (close
Browse files Browse the repository at this point in the history
…#3280) (#3558)

Co-authored-by: Alexis King <[email protected]>
  • Loading branch information
jberryman and lexi-lambda committed Jan 17, 2020
1 parent edb17e8 commit 1dd63a9
Show file tree
Hide file tree
Showing 17 changed files with 584 additions and 485 deletions.
107 changes: 52 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ refs:
at: /build
- *skip_job_on_ciignore
- checkout
- restore_cache:
keys:
- server-app-cache-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- server-deps-cache-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/stack.yaml" }}
- *wait_for_postgres
- run:
name: Install deps
Expand All @@ -107,19 +101,12 @@ refs:
# Setting default number of threads to 2
# since circleci allocates 2 cpus per test container
GHCRTS: -N2
HASURA_GRAPHQL_DATABASE_URL: 'postgresql://gql_test:@localhost:5432/gql_test'
HASURA_GRAPHQL_DATABASE_URL_2: 'postgresql://gql_test:@localhost:5432/gql_test2'
GRAPHQL_ENGINE: '/build/_server_output/graphql-engine'
GRAPHQL_ENGINE_TESTS: '/build/_server_output/graphql-engine-tests'
command: |
OUTPUT_FOLDER=/build/_server_test_output/$PG_VERSION .circleci/test-server.sh
- run:
name: Generate coverage report
working_directory: ./server
environment:
LC_ALL: 'C.UTF-8'
command: |
stack --system-ghc hpc report /build/_server_test_output/$PG_VERSION/graphql-engine.tix --destdir /build/_server_test_output/$PG_VERSION
HASURA_GRAPHQL_DATABASE_URL: postgresql://gql_test:@localhost:5432/gql_test
HASURA_GRAPHQL_DATABASE_URL_2: postgresql://gql_test:@localhost:5432/gql_test2
GRAPHQL_ENGINE: /build/_server_output/graphql-engine
GRAPHQL_ENGINE_TESTS: /build/_server_output/graphql-engine-tests
MIX_FILES_FOLDER: /build/_server_output/mix
command: OUTPUT_FOLDER="/build/_server_test_output/$PG_VERSION" .circleci/test-server.sh
- store_artifacts:
path: /build/_server_test_output
destination: server_test
Expand All @@ -144,24 +131,22 @@ jobs:
paths:
- ciignore

# build the server binary, and package into docker image
build_server:
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
resource_class: large
working_directory: ~/graphql-engine
steps:
- attach_workspace:
at: /build
- *skip_job_on_ciignore
- checkout
- *setup_remote_docker
- restore_cache:
keys:
- server-deps-cache-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/stack.yaml" }}
- restore_cache:
keys:
- server-app-cache-{{ .Branch }}-{{ .Revision }}
- cabal-store-v1-{{ checksum "server/cabal.project" }}-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/cabal.project.freeze" }}
- cabal-store-v1-{{ checksum "server/cabal.project" }}-{{ checksum "server/graphql-engine.cabal" }}-
- cabal-store-v1-{{ checksum "server/cabal.project" }}-
- cabal-store-v1-
- run:
name: Install latest postgresql client tools
command: |
Expand All @@ -174,11 +159,33 @@ jobs:
# for PRs non-optimized build, else optimized build
if [[ "$CIRCLE_BRANCH" =~ ^(dev|release) || "$CIRCLE_TAG" =~ ^v ]]; then
echo "Branch starts with dev or release, or tagged commit starts with v. Optimized build"
make ci-binary
make ci-build
else
echo "Non-release branch, build with coverage"
make BUILD_FLAGS='--coverage' ci-binary
make enable_coverage=true ci-build
fi
- save_cache:
key: cabal-store-v1-{{ checksum "server/cabal.project" }}-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/cabal.project.freeze" }}
paths:
- ~/.cabal/packages
- ~/.cabal/store
- store_artifacts:
path: /build/_server_output
destination: server
- persist_to_workspace:
root: /build
paths: [_server_output]

build_image:
docker:
- image: hasura/graphql-engine-server-builder:2020-01-14
working_directory: ~/graphql-engine
steps:
- attach_workspace:
at: /build
- *skip_job_on_ciignore
- checkout
- *setup_remote_docker
- run:
name: Build the docker image
working_directory: ./server
Expand All @@ -191,22 +198,12 @@ jobs:
# build and save the image
make ci-image
make ci-save-image
- save_cache:
key: server-app-cache-{{ .Branch }}-{{ .Revision }}
paths:
- ./server/.stack-work
- save_cache:
key: server-deps-cache-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/stack.yaml" }}
paths:
- ~/.stack
- store_artifacts:
path: /build/_server_output
destination: server
path: /build/_server_output/image.tar
destination: server/image.tar
- persist_to_workspace:
root: /build
paths:
- _server_output # binary is called graphql-engine

paths: [_server_output/image.tar]

# job to execute when all server tests pass. later we can collect test
# reports and publish them etc.
Expand All @@ -225,7 +222,7 @@ jobs:
PG_VERSION: "12"
POSTGIS_VERSION: "3.0.0"
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
- image: hasura/postgres-12.0-alpine-postgis3:6cbd863d47c0
<<: *test_pg_env

Expand All @@ -234,7 +231,7 @@ jobs:
environment:
PG_VERSION: "11"
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
- image: circleci/postgres:11-alpine-postgis
<<: *test_pg_env

Expand All @@ -243,7 +240,7 @@ jobs:
environment:
PG_VERSION: "10"
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
- image: circleci/postgres:10-alpine-postgis
<<: *test_pg_env

Expand All @@ -252,7 +249,7 @@ jobs:
environment:
PG_VERSION: "9_6"
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
- image: circleci/postgres:9.6-alpine-postgis
<<: *test_pg_env

Expand All @@ -261,32 +258,25 @@ jobs:
environment:
PG_VERSION: "9_5"
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
- image: circleci/postgres:9.5-alpine-postgis
<<: *test_pg_env

server_unit_tests:
resource_class: large
docker:
- image: hasura/graphql-engine-server-builder:20200110
- image: hasura/graphql-engine-server-builder:2020-01-14
working_directory: ~/graphql-engine
steps:
- attach_workspace:
at: /build
- *skip_job_on_ciignore
- checkout
- restore_cache:
keys:
- server-app-cache-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- server-deps-cache-{{ checksum "server/graphql-engine.cabal" }}-{{ checksum "server/stack.yaml" }}
- run:
name: Run unit tests
environment:
GHCRTS: -N2
command: |
/build/_server_output/graphql-engine-tests unit
command: /build/_server_output/graphql-engine-tests unit

test_cli_with_last_release:
docker:
Expand Down Expand Up @@ -502,6 +492,11 @@ workflows:
- build_server:
<<: *filter_only_vtags
requires:
- check_build_worthiness
- build_image:
<<: *filter_only_vtags
requires:
- build_server
- build_console
- test_server_pg_12:
<<: *filter_only_vtags
Expand Down Expand Up @@ -552,10 +547,12 @@ workflows:
- test_console:
<<: *filter_only_vtags
requires:
- build_console
- test_and_build_cli
- test_cli_with_last_release
- deploy:
<<: *filter_only_vtags_dev_release_branches
requires:
- build_image
- test_console
- all_server_tests_pass
10 changes: 2 additions & 8 deletions .circleci/server-builder.dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Don't update this without updating the
# packager imager of graphql-engine
FROM debian:stretch-20190228-slim
FROM haskell:8.6.5

ARG docker_ver="17.09.0-ce"
ARG resolver="lts-13.20"
ARG stack_ver="2.1.3"
ARG postgres_ver="11"
ARG postgres_ver="12"

# Install GNU make, curl, git and docker client. Required to build the server
RUN apt-get -y update \
Expand All @@ -17,10 +15,6 @@ RUN apt-get -y update \
&& curl -Lo /tmp/docker-${docker_ver}.tgz https://download.docker.com/linux/static/stable/x86_64/docker-${docker_ver}.tgz \
&& tar -xz -C /tmp -f /tmp/docker-${docker_ver}.tgz \
&& mv /tmp/docker/* /usr/bin \
&& curl -sL https://github.com/commercialhaskell/stack/releases/download/v${stack_ver}/stack-${stack_ver}-linux-x86_64.tar.gz \
| tar xz --wildcards --strip-components=1 -C /usr/local/bin '*/stack' \
&& stack --resolver ${resolver} setup \
&& stack build Cabal-2.4.1.0 \
&& apt-get -y purge curl \
&& apt-get -y auto-remove \
&& apt-get -y clean \
Expand Down
11 changes: 0 additions & 11 deletions .circleci/test-server-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ] ; then
exit 1
fi

if ! stack --allow-different-user exec -- which graphql-engine > /dev/null && [ -z "${GRAPHQL_ENGINE:-}" ] ; then
echo "Do 'stack build' before tests, or export the location of executable in the GRAPHQL_ENGINE envirnoment variable"
exit 1
fi

GRAPHQL_ENGINE=${GRAPHQL_ENGINE:-"$(stack --allow-different-user exec -- which graphql-engine)"}
if ! [ -x "$GRAPHQL_ENGINE" ] ; then
echo "$GRAPHQL_ENGINE is not present or is not an executable"
exit 1
fi

HGE_PID=""

run_hge_with_flags() {
Expand Down
52 changes: 27 additions & 25 deletions .circleci/test-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,40 @@ combine_all_hpc_reports() {
rm -f "$combined_file"
IFS=: tix_files_arr=($TIX_FILES)
unset IFS
for tix_file in "${tix_files_arr[@]}"
do
if ! [ -f "$tix_file" ] ; then
for tix_file in "${tix_files_arr[@]}"; do
if ! [ -f "$tix_file" ]; then
continue
fi
if [ -f "$combined_file" ] ; then
GHCRTS_PREV="$GHCRTS"
# Unsetting GHCRTS as hpc combine fails if GCHRTS=-N2 is present
unset GHCRTS
(set -x && stack --allow-different-user exec -- hpc combine "$combined_file" "$tix_file" --union --output="$combined_file_intermediate" && set +x && mv "$combined_file_intermediate" "$combined_file" && rm "$tix_file" ) || true
# Restoring GHCRTS
export GHCRTS="$GHCRTS_PREV"
if [ -f "$combined_file" ]; then
# Unset GHCRTS as hpc combine fails if GCHRTS=-N2 is present
( unset GHCRTS
set -x
hpc combine "$combined_file" "$tix_file" --union --output="$combined_file_intermediate"
set +x
mv "$combined_file_intermediate" "$combined_file"
rm "$tix_file"
) || true
else
mv "$tix_file" "$combined_file" || true
fi
done
}

generate_coverage_report() {
combine_all_hpc_reports
( shopt -s failglob
unset GHCRTS
cd ~/graphql-engine/server
mix_dirs=("$MIX_FILES_FOLDER"/*)
# This is the bash syntax to prepend `--hpcdir=` to each element of an array. Yeah, I don’t like
# it, either.
hpcdir_args=("${mix_dirs[@]/#/--hpcdir=}")
hpc_args=("${hpcdir_args[@]}" --reset-hpcdirs "$OUTPUT_FOLDER/graphql-engine.tix")
hpc report "${hpc_args[@]}"
mkdir -p "$OUTPUT_FOLDER/coverage"
hpc markup "${hpc_args[@]}" --destdir="$OUTPUT_FOLDER/coverage" )
}

kill_hge_servers() {
kill -s INT $HGE_PIDS || true
wait $HGE_PIDS || true
Expand Down Expand Up @@ -134,11 +150,6 @@ if [ -z "${HASURA_GRAPHQL_DATABASE_URL_2:-}" ] ; then
exit 1
fi

if ! stack --allow-different-user exec which hpc ; then
echo "hpc not found; Install it with 'stack install hpc'"
exit 1
fi

CIRCLECI_FOLDER="${BASH_SOURCE[0]%/*}"
cd $CIRCLECI_FOLDER
CIRCLECI_FOLDER="$PWD"
Expand All @@ -165,15 +176,6 @@ TIX_FILES=""

cd $PYTEST_ROOT

if ! stack --allow-different-user exec -- which graphql-engine > /dev/null && [ -z "${GRAPHQL_ENGINE:-}" ] ; then
echo "Do 'stack build' before tests, or export the location of executable in the GRAPHQL_ENGINE envirnoment variable"
exit 1
fi
GRAPHQL_ENGINE=${GRAPHQL_ENGINE:-"$(stack --allow-different-user exec -- which graphql-engine)"}
if ! [ -x "$GRAPHQL_ENGINE" ] ; then
echo "$GRAPHQL_ENGINE is not present or is not an executable"
exit 1
fi
RUN_WEBHOOK_TESTS=true

for port in 8080 8081 9876 5592
Expand Down Expand Up @@ -688,6 +690,6 @@ unset HASURA_HS_TEST_DB
# end horizontal scale test

echo -e "\n$(time_elapsed): <########## COMBINE ALL HPC REPORTS ########>\n"
combine_all_hpc_reports || true
generate_coverage_report || true

echo -e "\n$(time_elapsed): <########## DONE ########>\n"
Loading

0 comments on commit 1dd63a9

Please sign in to comment.