@@ -0,0 +1,150 @@
5+ROOT=$(cd $(dirname $0) ; pwd)
8+# For nightly-YYYY-MM-DD, tag should be nightly
9+# For lts-X.Y, tag should be ltsX
10+SHORTNAME=$(echo $TARGET | cut -d- -f 1)
11+if [ $SHORTNAME = "lts" ]
13+ TAG=$(echo $TARGET | sed 's@^lts-\([0-9]*\)\.[0-9]*@lts\1@')
18+IMAGE=commercialhaskell/stackage:$TAG
23+DOT_STACKAGE_DIR=$ROOT/dot-stackage
24+WORKDIR=$ROOT/$TAG/work
25+# ssh key is used for committing snapshots (and their constraints) to Github
33+ "$DOT_STACKAGE_DIR" \
37+GITCONFIG=$ROOT/gitconfig
40+ email = michael+stackage-build@fpcomplete.com
41+ name = Stackage Build host
44+HACKAGE_CREDS=$ROOT/hackage-creds
46+function require_400_file {
49+ echo File not found: "$1"
56+require_400_file "$SSH_DIR/id_rsa"
57+require_400_file "$HACKAGE_CREDS"
60+BINDIR=$(cd $ROOT/bin ; pwd)
63+rm -f stackage-curator stackage-curator-2*.bz2
64+CURATOR2=stackage-curator-2-401883a889b06e0a2ac772fac7abcc743d5a00e2
65+wget "https://download.fpcomplete.com/stackage-curator-2/$CURATOR2.bz2"
66+bunzip2 "$CURATOR2.bz2"
68+mv $CURATOR2 stackage-curator
69+./stackage-curator --version
73+ARGS_COMMON="--rm -v $WORKDIR:$HOME/work -w $HOME/work -v $BINDIR/stackage-curator:/usr/bin/stackage-curator:ro -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v $BINDIR/stack:/usr/bin/stack:ro -v $STACK_DIR:$HOME/.stack"
74+ARGS_PREBUILD="$ARGS_COMMON -u $USERID -e HOME=$HOME -v $CABAL_DIR:$HOME/.cabal -v $GHC_DIR:$HOME/.ghc -v $DOT_STACKAGE_DIR:$HOME/.stackage"
75+ARGS_BUILD="$ARGS_COMMON -v $CABAL_DIR:$HOME/.cabal:ro -v $GHC_DIR:$HOME/.ghc:ro"
76+# instance-data is an undocumented feature of S3 used by amazonka,
77+# see https://github.com/brendanhay/amazonka/issues/271
78+ARGS_UPLOAD="$ARGS_COMMON -u $USERID -e HOME=$HOME -v $HACKAGE_CREDS:/hackage-creds:ro -v $DOT_STACKAGE_DIR:$HOME/.stackage -v $SSH_DIR:$HOME/.ssh:ro -v $GITCONFIG:$HOME/.gitconfig:ro -v $CABAL_DIR:$HOME/.cabal:ro --add-host instance-data:169.254.169.254"
80+# Make sure we actually need this snapshot. We only check this for LTS releases
81+# since, for nightlies, we'd like to run builds even if they are unnecessary to
82+# get early warning information of upcoming failures. (See the duplicate check
83+# below for why this is safe.)
84+if [ $SHORTNAME = "lts" ]
86+ docker run $ARGS_UPLOAD $IMAGE /bin/bash -c "exec stackage-curator check-target-available --target $TARGET"
92+rm -f stack stack-*.bz2
93+STACK=stack-401883a889b06e0a2ac772fac7abcc743d5a00e2
94+wget "https://download.fpcomplete.com/stackage-curator-2/$STACK.bz2"
102+# Determine the new build plan unless NOPLAN is set
104+# * Update the package index (unless LTS)
105+# * Create a new plan
106+if [ "${NOPLAN:-}x" = "x" ]
108+ if [ $SHORTNAME = "lts" ]
110+ docker run $ARGS_PREBUILD $IMAGE /bin/bash -c "stackage-curator constraints --target $TARGET && stackage-curator snapshot-incomplete && stackage-curator snapshot"
112+ docker run $ARGS_PREBUILD $IMAGE /bin/bash -c "stackage-curator update && stackage-curator constraints --target $TARGET && stackage-curator snapshot-incomplete && stackage-curator snapshot"
117+# Do the rest of the pre-build actions:
119+# * Check that the snapshot is valid
120+# * Fetch and unpack all needed tarballs (the build step does not have write access to the tarball directory)
121+docker run $ARGS_PREBUILD $IMAGE /bin/bash -c 'GHCVER=$(sed -n "s/^ghc-version: \(.*\)/\1/p" constraints.yaml) && stack setup ghc-$GHCVER --verbosity=error && stack exec --resolver=ghc-$GHCVER stackage-curator check-snapshot && stackage-curator unpack'
128+# Now do the actual build. We need to first set the owner of the home directory
129+# correctly, so we run the command as root, change owner, and then use sudo to
130+# switch back to the current user
131+docker run $ARGS_BUILD $IMAGE nice -n 15 /bin/bash -c "chown $USER $HOME && exec sudo -E -u $USER env \"HOME=$HOME\" \"PATH=\$PATH\" stackage-curator build --jobs $JOBS"
133+# Make sure we actually need this snapshot. We used to perform this check
134+# exclusively before building. Now we perform it after as well for the case of
135+# nightly, where we don't perform this check beforehand. This is also slightly
136+# safer, in case someone else already uploaded a specific snapshot while we
138+docker run $ARGS_UPLOAD $IMAGE /bin/bash -c "exec stackage-curator check-target-available --target $TARGET"
140+# Successful build, so we need to:
142+# * Upload the docs to S3
143+# * Upload the new snapshot .yaml file to the appropriate Github repo, also upload its constraints
144+# * Register as a new Hackage distro (currently disabled)
145+docker run $ARGS_UPLOAD $IMAGE /bin/bash -c "stackage-curator upload-docs --target $TARGET && exec stackage-curator upload-github --target $TARGET"
146+# FIXME - add back "stackage-curator hackage-distro --target $TARGET" when we will be ready to publish
147+# information about the new snapshots on Hackage
149+echo -n "Completed at "