Skip to content

Commit

Permalink
Static Linux builds with Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 21, 2020
1 parent e4ba0b4 commit 8983f2d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 46 deletions.
42 changes: 19 additions & 23 deletions .azure/azure-linux-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,44 @@ jobs:
GHC 8.4:
BUILD: stack
STACK_YAML: stack-ghc-84.yaml
EXTRA_SUFFIX: ""
GHC 8.6:
BUILD: stack
STACK_YAML: stack-ghc-86.yaml
EXTRA_SUFFIX: ""
GHC 8.8:
BUILD: stack
STACK_YAML: stack-ghc-88.yaml
EXTRA_SUFFIX: ""
Alpine:
BUILD: stack
STACK_YAML: stack-alpine.yaml
EXTRA_SUFFIX: "alpine"
style:
BUILD: style
EXTRA_SUFFIX: ""
pedantic:
BUILD: pedantic
STACK_YAML: stack.yaml
EXTRA_SUFFIX: ""
steps:
- script: |
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
mkdir -p ~/.local/bin
curl -f -L "https://github.com/fpco/cache-s3/releases/download/${CACHE_S3_VERSION}/cache-s3-${CACHE_S3_VERSION}-${OS_NAME}-x86_64.tar.gz" -o ~/.local/bin/cache-s3.tar.gz
tar xzf ~/.local/bin/cache-s3.tar.gz -C ~/.local/bin
export PATH=$HOME/.local/bin:$PATH;
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" restore stack --base-branch="${BASE_BRANCH}"
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" restore stack work --base-branch="${BASE_BRANCH}"
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}${EXTRA_SUFFIX}" restore stack --base-branch="${BASE_BRANCH}"
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}${EXTRA_SUFFIX}" restore stack work --base-branch="${BASE_BRANCH}"
etc/scripts/ci-setup.sh
case "$BUILD" in
style)
./etc/scripts/get-hlint.sh
export PATH="$(pwd)"/hlint:$PATH
;;
cabal)
sudo add-apt-repository -y ppa:hvr/ghc
sudo apt-get update
sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
# See note here: https://github.com/haskell-CI/haskell-ci#alex--happy-with-ghc--78
if [ "$GHCVER" = "head" ] || [ "${GHCVER%.*}" = "7.8" ] || [ "${GHCVER%.*}" = "7.10" ]; then
sudo apt-get install happy-1.19.4 alex-3.1.3
export PATH=/opt/alex/3.1.3/bin:/opt/happy/1.19.4/bin:$PATH
else
sudo apt-get install happy alex
fi
export PATH=$HOME/.local/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
cabal --version
cabal update
PACKAGES=$(stack --install-ghc query locals | grep '^ *path' | sed 's@^ *path:@@')
cabal install --only-dependencies --enable-tests --enable-benchmarks --force-reinstalls --ghc-options=-O0 --reorder-goals --max-backjumps=-1 $CABALARGS $PACKAGES
;;
*)
export PATH=$HOME/.local/bin:$PATH
stack --install-ghc $ARGS test --bench --only-dependencies
stack $ARGS test --bench --only-dependencies
;;
esac
GHC_OPTIONS="-Werror"
Expand All @@ -68,7 +60,11 @@ jobs:
hlint test/ --cpp-simple
;;
stack)
stack test --haddock --no-haddock-deps --ghc-options="$GHC_OPTIONS"
stack test --haddock --no-haddock-deps --ghc-options="$GHC_OPTIONS" --copy-bins --local-bin-path bin
# Make sure Alpine actually builds a static exe that works on Ubuntu
./bin/stack --version
ldd ./bin/stack || true # ldd returns exit code 1 on statics, which we don't want to fail for
;;
pedantic)
stack --system-ghc build --pedantic
Expand Down Expand Up @@ -111,9 +107,9 @@ jobs:
export AWS_SECRET_ACCESS_KEY="$(AWS_SECRET_ACCESS_KEY)";
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
if [ "$(Build.SourceBranchName)" = "${BASE_BRANCH}" ]; then
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack;
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}${EXTRA_SUFFIX}" save stack;
fi;
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack work
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}${EXTRA_SUFFIX}" save stack work
condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'))
env:
OS_NAME: ${{ parameters.os }}
Expand Down
19 changes: 17 additions & 2 deletions .azure/azure-nightly-template-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
vmImage: ${{ parameters.vmImage }}
steps:
- script: |
set -ex
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
echo $STACK_ROOT
mkdir -p ~/.local/bin
Expand All @@ -17,31 +19,40 @@ jobs:
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" restore stack work --base-branch="${BASE_BRANCH}"
etc/scripts/ci-setup.sh
export PATH=$HOME/.local/bin:/opt/ghc/$GHCVER/bin:/opt/happy/1.19.5/bin:/opt/alex/3.1.7/bin:$PATH
set +ex
env:
OS_NAME: ${{ parameters.os }}
AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
STACK_YAML: $(Build.SourcesDirectory)/stack-alpine.yaml
displayName: 'Installation ${{parameters.os}}'
- script: |
set -ex
# Retry installing nix due to nondeterministic error
# Fatal error: glibc detected an invalid stdio handle
# See:
# https://github.com/nh2/static-haskell-nix/pull/27#issuecomment-502652181
# https://github.com/NixOS/nix/issues/2733
(for i in {1..5}; do bash <(curl https://nixos.org/nix/install) && exit 0; done; exit 1)
source ~/.profile
. ~/.nix-profile/etc/profile.d/nix.sh
nix-channel --add https://nixos.org/channels/nixos-19.09 nixpkgs
nix-channel --update # Get GHC 8.2.2
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
export PATH=$HOME/.local/bin:$PATH;
stack etc/scripts/release.hs check
set +ex
displayName: Integration Test
- script: |
set -ex
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
export PATH=$HOME/.local/bin:$PATH;
set -ex
stack etc/scripts/release.hs build
cp _release/stack-* $(Build.ArtifactStagingDirectory)
set +ex
displayName: Build bindist
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')
Expand All @@ -51,6 +62,8 @@ jobs:
artifactName: stack-linux
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')
- script: |
set -ex
export PATH=$HOME/.local/bin:$PATH;
export AWS_ACCESS_KEY_ID="$(AWS_ACCESS_KEY_ID)";
export AWS_SECRET_ACCESS_KEY="$(AWS_SECRET_ACCESS_KEY)";
Expand All @@ -59,6 +72,8 @@ jobs:
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack;
fi;
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack work
set +ex
env:
OS_NAME: ${{ parameters.os }}
displayName: 'Cache data'
16 changes: 16 additions & 0 deletions .azure/azure-nightly-template-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
vmImage: ${{ parameters.vmImage }}
steps:
- script: |
set -ex
export AWS_ACCESS_KEY_ID="$(AWS_ACCESS_KEY_ID)";
export AWS_SECRET_ACCESS_KEY="$(AWS_SECRET_ACCESS_KEY)";
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
Expand All @@ -20,21 +22,31 @@ jobs:
etc/scripts/ci-setup.sh
brew install mercurial
export PATH=$HOME/.local/bin:/opt/ghc/$GHCVER/bin:/opt/happy/1.19.5/bin:/opt/alex/3.1.7/bin:$PATH
set +ex
env:
OS_NAME: ${{ parameters.os }}
displayName: 'Installation ${{parameters.os}}'
- script: |
set -ex
curl https://nixos.org/nix/install | sh
. ~/.nix-profile/etc/profile.d/nix.sh
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
export PATH=$HOME/.local/bin:$PATH;
stack etc/scripts/release.hs check
set +ex
displayName: Integration Test
- script: |
set -ex
export STACK_ROOT="$(Build.SourcesDirectory)"/.stack-root;
export PATH=$HOME/.local/bin:$PATH;
stack etc/scripts/release.hs build
cp _release/stack-* $(Build.ArtifactStagingDirectory)
set +ex
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')
displayName: Build bindist
- task: PublishBuildArtifacts@1
Expand All @@ -43,6 +55,8 @@ jobs:
artifactName: stack-osx
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')
- script: |
set -ex
export PATH=$HOME/.local/bin:$PATH;
export AWS_ACCESS_KEY_ID="$(AWS_ACCESS_KEY_ID)";
export AWS_SECRET_ACCESS_KEY="$(AWS_SECRET_ACCESS_KEY)";
Expand All @@ -51,6 +65,8 @@ jobs:
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack;
fi;
cache-s3 --prefix="${CACHE_S3_PREFIX}" --git-branch="$(Build.SourceBranchName)" --suffix="${OS_NAME}" save stack work
set +ex
env:
OS_NAME: ${{ parameters.os }}
displayName: 'Cache data'
15 changes: 0 additions & 15 deletions etc/scripts/ci-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,3 @@ if [ `uname` = "Darwin" ]; then
else
travis_retry fetch_stack_linux
fi

case "$BUILD" in
stack)
# However, we only need stack to download GHC for stack builds.
travis_retry stack --no-terminal setup;
;;
cabal)
mkdir -p $HOME/.cabal
cat > $HOME/.cabal/config <<EOF
remote-repo: hackage.haskell.org:http://hackage.fpcomplete.com/
remote-repo-cache: $HOME/.cabal/packages
jobs: \$ncpus
EOF
;;
esac
6 changes: 6 additions & 0 deletions src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ runContainerAndExit = do
bamboo = lookup "bamboo_buildKey" env
jenkins = lookup "JENKINS_HOME" env
msshAuthSock = lookup "SSH_AUTH_SOCK" env
mstackYaml = lookup "STACK_YAML" env
muserEnv = lookup "USER" env
isRemoteDocker = maybe False (isPrefixOf "tcp://") dockerHost
image <- either throwIO pure (dockerImage docker)
Expand Down Expand Up @@ -267,6 +268,11 @@ runContainerAndExit = do
Just sshAuthSock ->
["-e","SSH_AUTH_SOCK=" ++ sshAuthSock
,"-v",sshAuthSock ++ ":" ++ sshAuthSock]
,case mstackYaml of
Nothing -> []
Just stackYaml ->
["-e","STACK_YAML=" ++ stackYaml
,"-v",stackYaml++ ":" ++ stackYaml ++ ":ro"]
-- Disable the deprecated entrypoint in FP Complete-generated images
,["--entrypoint=/usr/bin/env"
| isJust (lookupImageEnv oldSandboxIdEnvVar imageEnvVars) &&
Expand Down
30 changes: 30 additions & 0 deletions stack-alpine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resolver: lts-14.27

packages:
- .

docker:
enable: true
#repo: fpco/alpine-haskell-stack:8.6.5
repo: fpco/alpine-haskell-stack@sha256:665495cf78a9a7a667a45061a1322989b128d3443d87821fac1445dc85984804

flags:
stack:
hide-dependency-versions: true
supported-build: true

ghc-options:
"$locals": -fhide-source-paths -optl-static

extra-deps:
- Cabal-3.0.0.0@rev:0
- hpack-0.33.0@rev:0
- http-download-0.2.0.0@rev:0
- filelock-0.1.1.4@rev:0
- pantry-0.4.0.1@rev:0
- casa-client-0.0.1@rev:0
- casa-types-0.0.1@rev:0

drop-packages:
# See https://github.com/commercialhaskell/stack/pull/4712
- cabal-install
3 changes: 1 addition & 2 deletions stack-ghc-84.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ extra-deps:
- pantry-0.4.0.1@rev:0
- casa-client-0.0.1@rev:0
- casa-types-0.0.1@rev:0
- github: snoyberg/filelock
commit: 97e83ecc133cd60a99df8e1fa5a3c2739ad007dc
- filelock-0.1.1.4@rev:0

drop-packages:
# See https://github.com/commercialhaskell/stack/pull/4712
Expand Down
3 changes: 1 addition & 2 deletions stack-ghc-88.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ extra-deps:
- lukko-0.1.1.1@sha256:5c674bdd8a06b926ba55d872abe254155ed49a58df202b4d842b643e5ed6bcc9,4289
- hpack-0.33.0@rev:0
- http-download-0.2.0.0@rev:0
- github: snoyberg/filelock
commit: 97e83ecc133cd60a99df8e1fa5a3c2739ad007dc
- filelock-0.1.1.4@rev:0
- pantry-0.4.0.1@rev:0
- casa-client-0.0.1@rev:0
- casa-types-0.0.1@rev:0
Expand Down
3 changes: 1 addition & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ extra-deps:
- Cabal-3.0.0.0@rev:0
- hpack-0.33.0@rev:0
- http-download-0.2.0.0@rev:0
- git: https://github.com/snoyberg/filelock.git
commit: 97e83ecc133cd60a99df8e1fa5a3c2739ad007dc
- filelock-0.1.1.4@rev:0
- pantry-0.4.0.1@rev:0
- casa-client-0.0.1@rev:0
- casa-types-0.0.1@rev:0
Expand Down

0 comments on commit 8983f2d

Please sign in to comment.