Skip to content

Commit

Permalink
Merge pull request #272 from CircleCI-Public/packr2
Browse files Browse the repository at this point in the history
[CIRCLE-15952]: Replace CI packr install with vendored binary
  • Loading branch information
Zachary Scott authored Feb 13, 2019
2 parents 26252a9 + 558bc6f commit 4379bab
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 18 deletions.
17 changes: 3 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ commands:
command: |
[ -f ~/goreleaser_amd64.db ] || curl --silent --location --fail --retry 3 << parameters.GORELEASER_URL >> > ~/goreleaser_amd64.deb
sudo apt install ~/goreleaser_amd64.deb
install-packr:
parameters:
PACKR_URL:
type: string
default: https://github.com/gobuffalo/packr/releases/download/v2.0.0-rc.13/packr_2.0.0-rc.13_linux_amd64.tar.gz
steps:
- run:
name: Install packr2 to build packrd data before goreleaser builds final binary
command: |
cd $(mktemp -d)
curl -SL << parameters.PACKR_URL >> | tar -xzv
sudo mv packr2 /usr/local/bin/packr2
gomod:
steps:
- restore_cache:
Expand All @@ -79,6 +67,7 @@ commands:
steps:
- slack/status:
fail_only: "true"
only_for_branch: "master"

jobs:
test:
Expand Down Expand Up @@ -142,7 +131,7 @@ jobs:
- checkout
- install-goreleaser
- gomod
- install-packr
- run: make dev
- run:
name: Release
command: goreleaser --skip-publish --skip-validate
Expand All @@ -166,7 +155,7 @@ jobs:
git tag -a "v0.1.$CIRCLE_BUILD_NUM" -m "Release v0.1.$CIRCLE_BUILD_NUM"
git push origin "v0.1.$CIRCLE_BUILD_NUM"
- gomod
- install-packr
- run: make dev
- run:
name: Release
command: goreleaser
Expand Down
53 changes: 53 additions & 0 deletions .circleci/install-packr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

PACKR_VERSION="2.0.1"
RELEASE_URL="https://github.com/gobuffalo/packr/releases/download"
DESTDIR="${DESTDIR:-$PWD/bin}"

SCRATCH=$(mktemp -d)
cd "$SCRATCH"

function error() {
echo "An error occured installing the tool."
echo "The contents of the directory $SCRATCH have been left in place to help to debug the issue."
}

trap error SIGINT

function get_arch_type() {
if [[ $(uname -m) == "i686" ]]; then
echo "386"
elif [[ $(uname -m) == "x86_64" ]]; then
echo "amd64"
fi
}

function get_arch_base() {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "darwin"
fi
}

ARCH="$(get_arch_base)_$(get_arch_type)"
PACKR_RELEASE_URL="${RELEASE_URL}/v${PACKR_VERSION}/packr_${PACKR_VERSION}_${ARCH}.tar.gz"

echo "Fetching packr from $PACKR_RELEASE_URL"

curl --retry 3 --fail --location "$PACKR_RELEASE_URL" | tar -xz

echo "Installing packr for $ARCH to $DESTDIR"
mv packr2 "$DESTDIR"
chmod +x "$DESTDIR/packr2"

command -v "$DESTDIR/packr2"

# Delete the working directory when the install was successful.
rm -r "$SCRATCH"

exit 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ stage/
# packr related
*/*-packr.go
packrd/
/bin/packr2
8 changes: 8 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ If you cloned the repo inside of your `$GOPATH`, you can use `GO111MODULE=on` in
$ make
```

The `make` file assumes you have the `packr2` binary available which is installable via `make dev`. This will pull the latest stable binary into the project's `./bin/packr2` path.

If you don't run `make dev`, you will see a make error:

```
/bin/sh: 1: bin/packr2: not found
```

### 3. Run tests

```
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

build: always
GO111MODULE=on packr2
GO111MODULE=on bin/packr2
go build -o build/$(GOOS)/$(GOARCH)/circleci

build-all: build/linux/amd64/circleci build/darwin/amd64/circleci
Expand All @@ -16,7 +16,7 @@ build/%/amd64/circleci: always
clean:
GO111MODULE=off go clean -i
rm -rf build out docs dist
packr2 clean
bin/packr2 clean

.PHONY: test
test:
Expand All @@ -43,11 +43,11 @@ doc:

.PHONY: dev
dev:
go get golang.org/x/tools/cmd/godoc
bash .circleci/install-packr.sh

.PHONY: pack
pack:
GO111MODULE=on packr2 build
GO111MODULE=on bin/packr2 build

.PHONY: always
always:
Empty file added bin/.gitkeep
Empty file.

0 comments on commit 4379bab

Please sign in to comment.