Created
November 18, 2017 18:06
-
-
Save saurabhnanda/1ce4a937aef9b5b867ec3188636924e9 to your computer and use it in GitHub Desktop.
Haskall on CircleCI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
defaults: &defaults | |
environment: | |
BASH_ENV: ~/.bashrc | |
# These libraries eat up a lot of memory while compiling and cannot be built in parallel with other libraries. | |
$ They will exhaust your memory and cause the build to crash if not built separately. | |
KNOWN_CULPRITS: "regex-tdfa lens" | |
# Space separated list of files that you want to finally deploy | |
ARTEFACTS: ".stack-work/install/x86_64-linux/lts-9.0/8.0.2/bin/webservice-exe templates" | |
# Can be used for the deployment script below, if you need it. | |
APP_ENV: production | |
YAML_PARSER: .circleci/get_key_from_yaml.py | |
jobs: | |
build: | |
<<: *defaults | |
# If you have a pre-compiled docker image in some docker container reposotiry, you can comment lines 21 & 22 | |
# and uncomment lines 17-21 and change them to use your own docker image, instaed of the one by CircleCI | |
# docker: | |
# - image: saurabhnanda/vl-haskell:ubuntu-14.04 | |
# auth: | |
# username: $DOCKERHUB_USERNAME # this is fetched from the "Project Settings" tab on the CircleCI UI | |
# password: $DOCKERHUB_PASSWORD # this is fetched from the "Project Settings" tab on the CircleCI UI | |
docker: | |
- image: circleci/ubuntu-server | |
# CHANGE THE FOLLOWING | |
working_directory: ~/usually-your-project-name | |
steps: | |
- run: | |
# Lines 32-34 are required if you aren't using a custom docker image. They are to install some system-wide/C libraries that your Haskell code may depende on. | |
name: "Figuring out the SHA-checksums of last 10 commits" | |
command: | | |
apt-get update | |
apt-get install -y --force-yes curl | |
apt-get install -y --force-yes --no-install-recommends make xz-utils libpq-dev libicu-dev libblas-dev liblapack-dev libgmp3-dev clang gcc git-core | |
printf 'Host *\n\tStrictHostKeyChecking no\n' >> ~/.ssh/config && chmod 400 ~/.ssh/config | |
git clone -b $CIRCLE_BRANCH --single-branch --depth=10 $CIRCLE_REPOSITORY_URL /tmp/repo | |
i=1; for sha in $(cd /tmp/repo && git log -n 10 --pretty='%H'); do echo $sha > ~/commit-sha$i.txt && let i+=1; done | |
- restore_cache: | |
keys: | |
- v4-source-code-{{ checksum "~/commit-sha1.txt" }} # <=== this is the current commit, will this ever be in cache? | |
- v4-source-code-{{ checksum "~/commit-sha2.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha3.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha4.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha5.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha6.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha7.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha8.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha9.txt" }} | |
- v4-source-code-{{ checksum "~/commit-sha10.txt" }} | |
- run: | |
name: Fetching latest source code and checking out the current commit | |
command: | | |
printf 'Host *\n\tStrictHostKeyChecking no\n' >> ~/.ssh/config && chmod 400 ~/.ssh/config | |
if ! git status; then git clone YOUR_GIT_REPO_URL ~/usually-your-project-name; fi | |
git fetch --all | |
git reset --hard HEAD | |
git checkout $CIRCLE_SHA1 | |
- run: | |
name: Installing snapshot dependencies for the Haskell project | |
no_output_timeout: 2400 | |
command: | | |
export PATH="$HOME/.local/bin:$PATH" | |
if ! command -v stack; then curl -sSL https://get.haskellstack.org/ | sh && stack setup; fi | |
stack setup | |
stack build -j1 $KNOWN_CULPRITS --ghc-options="-j -M3.5G -A32m -RTS -O0" --resolver=`$YAML_PARSER stack.yaml resolver` | |
stack build --only-snapshot --ghc-options='-j +RTS -M3.5G -sstderr -A32m -RTS -O0' | |
- save_cache: | |
key: v7-haskell-project-deps | |
paths: | |
- ~/.local/bin | |
- ~/.stack | |
- run: | |
name: Compiling the Haskell project | |
no_output_timeout: 2400 | |
command: | | |
export PATH="$HOME/.local/bin:$PATH" | |
stack build --dump-logs --ghc-options='-j +RTS -M3G -sstderr -A32m -RTS -O0' | |
- run: | |
name: Copying the build artifacts | |
command: | | |
mkdir ~/artefacts | |
cp -R $ARTEFACTS ~/artefacts | |
- save_cache: | |
key: v4-source-code-{{ checksum "~/commit-sha1.txt" }} | |
when: always | |
paths: | |
# REMEMBER TO CHANGE THIS | |
- ~/usually-you-project-name | |
- persist_to_workspace: | |
# Must be an absolute path, or relative path from working_directory | |
root: /root | |
paths: | |
- artefacts/ | |
deploy: | |
<<: *defaults | |
# REMEMBER TO CHANGE THIS | |
working_directory: ~/usually-you-project-name | |
docker: | |
- image: circleci/ubuntu-server | |
steps: | |
- attach_workspace: | |
# Must be absolute path or relative path from working_directory | |
at: /tmp/artefacts | |
- deploy: | |
name: Copying all build artefacts to remote server and signalling haproxy restart | |
command: | | |
# TODO -- write your deployment script here, else you can get rid of this step and the workflow as well. | |
workflows: | |
version: 2 | |
build_and_deploy: | |
jobs: | |
- build | |
- hold-deploy: | |
type: approval | |
requires: | |
- build | |
- deploy: | |
requires: | |
- hold-deploy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment