on master help sign in
Merge pull request #4462 from qrilka/new-build-server-scripts

build.sh variant with the new curator version (and new Stack)

commit85eda8b0796af5351a01b7c2bef9578d2411fed1 authorMichael Snoyman <michael@snoyman.com> dateTue 9 Apr 2019, 10:41 (8 years ago) parent3475415f49e0b3
1 file changed+150
automated/build-next.sh+150
automated/build-next.shnew file+150
@@ -0,0 +1,150 @@
1+#!/usr/bin/env bash
2+
3+set -eu +x
4+
5+ROOT=$(cd $(dirname $0) ; pwd)
6+TARGET=$1
7+
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" ]
12+then
13+ TAG=$(echo $TARGET | sed 's@^lts-\([0-9]*\)\.[0-9]*@lts\1@')
14+else
15+ TAG=$SHORTNAME
16+fi
17+
18+IMAGE=commercialhaskell/stackage:$TAG
19+
20+CABAL_DIR=$ROOT/cabal
21+STACK_DIR=$ROOT/stack
22+GHC_DIR=$ROOT/ghc
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
26+SSH_DIR=$ROOT/ssh
27+USERID=$(id -u)
28+
29+mkdir -p \
30+ "$CABAL_DIR" \
31+ "$STACK_DIR" \
32+ "$GHC_DIR" \
33+ "$DOT_STACKAGE_DIR" \
34+ "$WORKDIR" \
35+ "$SSH_DIR"
36+
37+GITCONFIG=$ROOT/gitconfig
38+cat >$GITCONFIG <<EOF
39+[user]
40+ email = michael+stackage-build@fpcomplete.com
41+ name = Stackage Build host
42+EOF
43+
44+HACKAGE_CREDS=$ROOT/hackage-creds
45+
46+function require_400_file {
47+ if [ ! -f "$1" ]
48+ then
49+ echo File not found: "$1"
50+ exit 1
51+ fi
52+
53+ chmod 400 "$1"
54+}
55+
56+require_400_file "$SSH_DIR/id_rsa"
57+require_400_file "$HACKAGE_CREDS"
58+
59+mkdir -p $ROOT/bin
60+BINDIR=$(cd $ROOT/bin ; pwd)
61+(
62+cd $BINDIR
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"
67+chmod +x $CURATOR2
68+mv $CURATOR2 stackage-curator
69+./stackage-curator --version
70+)
71+
72+
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"
79+
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" ]
85+then
86+ docker run $ARGS_UPLOAD $IMAGE /bin/bash -c "exec stackage-curator check-target-available --target $TARGET"
87+fi
88+
89+# Get latest stack
90+(
91+cd $BINDIR
92+rm -f stack stack-*.bz2
93+STACK=stack-401883a889b06e0a2ac772fac7abcc743d5a00e2
94+wget "https://download.fpcomplete.com/stackage-curator-2/$STACK.bz2"
95+bunzip2 "$STACK.bz2"
96+chmod +x $STACK
97+mv $STACK stack
98+./stack --version
99+)
100+
101+
102+# Determine the new build plan unless NOPLAN is set
103+#
104+# * Update the package index (unless LTS)
105+# * Create a new plan
106+if [ "${NOPLAN:-}x" = "x" ]
107+then
108+ if [ $SHORTNAME = "lts" ]
109+ then
110+ docker run $ARGS_PREBUILD $IMAGE /bin/bash -c "stackage-curator constraints --target $TARGET && stackage-curator snapshot-incomplete && stackage-curator snapshot"
111+ else
112+ docker run $ARGS_PREBUILD $IMAGE /bin/bash -c "stackage-curator update && stackage-curator constraints --target $TARGET && stackage-curator snapshot-incomplete && stackage-curator snapshot"
113+ fi
114+fi
115+
116+
117+# Do the rest of the pre-build actions:
118+#
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'
122+
123+case $SHORTNAME in
124+ lts) JOBS=1 ;;
125+ nightly) JOBS=2 ;;
126+esac
127+
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"
132+
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
137+# were building.
138+docker run $ARGS_UPLOAD $IMAGE /bin/bash -c "exec stackage-curator check-target-available --target $TARGET"
139+
140+# Successful build, so we need to:
141+#
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
148+
149+echo -n "Completed at "
150+date