Skip to content

Commit

Permalink
Merge pull request #6726 from habitat-sh/shain/migrate_mac_builds
Browse files Browse the repository at this point in the history
Migrate Mac Builds to new pipeline
  • Loading branch information
scotthain authored Jul 12, 2019
2 parents 9527df7 + 9a33513 commit 3a151cb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 90 deletions.
29 changes: 0 additions & 29 deletions .buildkite/Brewfile

This file was deleted.

23 changes: 9 additions & 14 deletions .buildkite/release_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,15 @@ steps:
- BUILDKITE_AGENT_ACCESS_TOKEN

- label: ":mac: :habicat: core/hab"
command: .buildkite/scripts/build_mac_release.sh
concurrency_group: "habitat/release/macos"
# We only want to run one build at a time because these are long-lived VMs and the builds
# are by definition not very isolated
concurrency: 1
env:
# Temporary workaround for https://github.com/habitat-sh/habitat/issues/4871#issuecomment-419233861
SSL_CERT_FILE: "/usr/local/etc/openssl/cert.pem"
agents:
# This is the only queue that has Mac builders at the moment;
# they're also not being used by anyone else.
queue: omnibus
os: Darwin
"os:version": 10.12 # Build statically on the oldest thing we can
command:
- .buildkite/scripts/build_mac_release.sh
agents:
queue: default-macos-privileged
plugins:
- chef/anka#v0.5.2:
vm-name: macos-base-10.12
inherit-environment-vars: true
wait-network: true

- wait

Expand Down
40 changes: 19 additions & 21 deletions .buildkite/scripts/build_mac_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ set -euo pipefail
source .buildkite/env
source .buildkite/scripts/shared.sh

# Set SSL cert location
export SSL_CERT_FILE=/usr/local/etc/openssl/cert.pem

echo "--- Installing buildkite agent"
brew tap buildkite/buildkite
brew install --token="$BUILDKITE_AGENT_ACCESS_TOKEN" buildkite-agent

echo "--- Installing Habitat Toolchain Omnibus package"
# This is a temporary situation until we have a pipeline building the
# toolchain packages and automatically installing them in our
# workers. Until then, we'll do it ourselves
bootstrap_package="habitat-bootstrap-1.0.0%2B20180813202835-1.pkg"
# We now have a temporary pipeline to building this bootstrap package, but
# it just pushes to an S3 bucket here. The final omnibus pipeline is still
# WIP right now.
bootstrap_package="mac-bootstrapper-1.0.0-latest.pkg"
curl --remote-name \
--location \
"https://s3-us-west-2.amazonaws.com/shain-bk-test/${bootstrap_package}"
Expand All @@ -18,16 +25,13 @@ sudo installer \
-pkg "${bootstrap_package}" \
-target /
rm "${bootstrap_package}"
export PATH="/opt/mac-bootstrapper/embedded/bin:$PATH"

# TODO (CM): consider getting Bash updated on builders (likely via Homebrew)
# TODO (CM): have a cleanup function
# Clear out /hab
# Uninstall Homebrew stuff
# Uninstall Rustup, Rust?

echo "--- :beer: Updating Homebrew dependencies"
brew bundle install --verbose --file=.buildkite/Brewfile
echo "--- :beer: Installing wget from homebrew"
brew install wget

echo "--- Installing hab"
curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh | sudo bash
echo "--- :habicat: Using $(hab --version)"

# Declaring this variable for the import_keys function only; see its
Expand Down Expand Up @@ -55,21 +59,15 @@ echo "--- :rust: Using Rust toolchain ${RUST_TOOLCHAIN}"
rustup default "${RUST_TOOLCHAIN}"
rustc --version # just 'cause I'm paranoid and I want to double check

echo "--- Cleanup caches"
# TODO (CM): enable control of cache clearing on a pipeline-wide basis
sudo rm -Rf /hab/cache/src
rm -Rf "${HOME}/.cargo/{git,registry}"

echo "--- :habicat: :hammer_and_wrench: Building 'hab'"

# NOTE: This does *not* need the CI_OVERRIDE_CHANNEL /
# HAB_BLDR_CHANNEL variables that builds for other supported platforms
# need, because we're not pulling anything from Builder. Once we do,
# we'll need to make sure we pull from the right channels.
sudo -E PATH="/opt/hab-bundle/embedded/bin:${PATH}" \
"$(brew --prefix bash)/bin/bash" \
components/plan-build/bin/hab-plan-build.sh \
components/hab
sudo -E bash \
components/plan-build/bin/hab-plan-build.sh \
components/hab
source results/last_build.env

echo "--- :buildkite: Annotating build"
Expand Down
30 changes: 15 additions & 15 deletions components/hab/habitat/x86_64-darwin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ As Habitat currently does not have first class support for the Mac platform, a p

## Prerequisites

### Reference
The following script is what runs in CI and installs all the required prerequisites *except* xcode. Please use this as a reference for the following steps.
```sh
./.buildkite/scripts/build_mac_release.sh
```

### Install XCode Command Line Developer Tools
This installs basic developer tooling needed to compile and build software on a Mac.

Expand All @@ -15,17 +21,15 @@ xcode-select --install

Since there is not yet a complete Habitat build toolchain available for macOS, we provide the minimal set of binaries and static libraries needed to compile a `hab` binary using Chef's Omnibus tooling platform. This effectively takes the place of the packages we would add to a `pkg_build_deps` entry in a Habitat plan file.

TODO: Where can this package be retrieved from?
This currently exists in at `https://s3-us-west-2.amazonaws.com/shain-bk-test/mac-bootstrapper-1.0.0-latest.pkg`

```sh
sudo installer \
-pkg <PATH_TO_BOOTSTRAP_TOOLCHAIN_PACKAGE> \
-target /
```

TODO: Can we rename `hab-bundle`?

This will install the toolchain in `/opt/hab-bundle`; this is where the build program is expecting to find binaries and libraries it needs.
This will install the toolchain in `/opt/mac-bootstrapper`; this is where the build program is expecting to find binaries and libraries it needs.

### Install Homebrew
Follow the instructions at https://brew.sh.
Expand All @@ -34,20 +38,16 @@ Follow the instructions at https://brew.sh.
Follow the instructions at https://rustup.rs/

### Install Homebrew prerequisites
Though most of the toolchain needed to build a `hab` binary exist in the Omnibus bootstrap toolchain, a few are not yet available there. Until they are migrated in, we need to use Homebrew to get them.

``` sh
brew bundle install --verbose --file=<HABITAT_REPO>/.buildkite/Brewfile
The only extra homebrew dependency we have current is wget, which can be installed by running the following:
```sh
brew install wget
```

This step is temporary, until we have a fully-contained toolchain in an Omnibus package

### Install `hab`
This is currently handled with the `brew bundle` command above, but for completeness:
We install hab via the `curl|bash` method:

``` sh
brew tap habitat-sh/habitat
brew install hab
curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh | sudo bash
```

### Install Builder Origin Keys
Expand All @@ -65,10 +65,10 @@ Here, we use `sudo` to install keys in system-wide `/hab/cache/keys/` directory
Ensure that the necessary tools are on your path, and then build.

``` sh
PATH="/opt/hab-bundle/embedded/bin:${PATH}"
PATH="/opt/mac-toolchain/embedded/bin:${PATH}"
PATH="~/.cargo/bin:${PATH}"
export PATH
sudo -E $(brew --prefix bash)/bin/bash components/plan-build/bin/hab-plan-build.sh components/hab/mac
sudo -E bash components/plan-build/bin/hab-plan-build.sh components/hab
```

Assuming success, this will produce a local `./results` directory with the artifact.
22 changes: 11 additions & 11 deletions components/hab/habitat/x86_64-darwin/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ do_prepare() {
# Our dependencies are coming from an Omnibus toolchain in
# https://github.com/habitat-sh/release-engineering/tree/master/components/bootstrap/x86_64-darwin/mac-bootstrapper
# (private for now, but will be opened soon)
la_ldflags="-L/opt/hab-bundle/embedded/lib -lz"
la_ldflags="$la_ldflags -L/opt/hab-bundle/embedded/lib -llzma"
la_ldflags="$la_ldflags -L/opt/hab-bundle/embedded/lib -lbz2"
la_ldflags="$la_ldflags -L/opt/hab-bundle/embedded/lib -lexpat"
la_ldflags="$la_ldflags -L/opt/hab-bundle/embedded/lib -liconv"

export LIBARCHIVE_LIB_DIR=/opt/hab-bundle/embedded/lib
export LIBARCHIVE_INCLUDE_DIR=/opt/hab-bundle/embedded/include
la_ldflags="-L/opt/mac-bootstrapper/embedded/lib -lz"
la_ldflags="$la_ldflags -L/opt/mac-bootstrapper/embedded/lib -llzma"
la_ldflags="$la_ldflags -L/opt/mac-bootstrapper/embedded/lib -lbz2"
la_ldflags="$la_ldflags -L/opt/mac-bootstrapper/embedded/lib -lexpat"
la_ldflags="$la_ldflags -L/opt/mac-bootstrapper/embedded/lib -liconv"

export LIBARCHIVE_LIB_DIR=/opt/mac-bootstrapper/embedded/lib
export LIBARCHIVE_INCLUDE_DIR=/opt/mac-bootstrapper/embedded/include
export LIBARCHIVE_LDFLAGS="$la_ldflags"
export LIBARCHIVE_STATIC=true

export OPENSSL_LIB_DIR=/opt/hab-bundle/embedded/lib
export OPENSSL_INCLUDE_DIR=/opt/hab-bundle/embedded/include
export OPENSSL_LIB_DIR=/opt/mac-bootstrapper/embedded/lib
export OPENSSL_INCLUDE_DIR=/opt/mac-bootstrapper/embedded/include
export OPENSSL_STATIC=true

export SODIUM_LIB_DIR=/opt/hab-bundle/embedded/lib
export SODIUM_LIB_DIR=/opt/mac-bootstrapper/embedded/lib
export SODIUM_STATIC=true
}

Expand Down

0 comments on commit 3a151cb

Please sign in to comment.