[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Packaging Terraform, a Golang package

From: Chris Marusich
Subject: Re: Packaging Terraform, a Golang package
Date: Thu, 20 Dec 2018 01:31:48 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hello Chris and Pierre!

Thank you for your tips regarding Golang and Terraform.  I've built it -
both ad-hoc and using a slightly modified version of Chris' original
package definition.  I'm still getting used to Golang's build system and
our own golang-build-system, so please bear with me!

I was able to run the official Terraform build steps on the latest
Terraform release by issuing the following commands - but I'm not sure
if this actually produced the terraform program:

mkdir terraform
cd terraform/
tar -xf v0.11.11.tar.gz
mkdir -p src/
cp -r terraform-0.11.11 src/
guix package -i go make git bash grep findutils which coreutils diffutils -p 
mkdir gobin
eval "$(guix package --search-paths=exact --profile=$(realpath --no-symlinks 
export GOPATH="$(pwd)"
export GOBIN="$GOPATH/bin"
export PATH="$PATH:$GOBIN"
cd src/
make tools

Those last two commands are the ones listed in Terraform's
It looks like the final command, "make" will execute the "fmtcheck",
"generate", and "test" recipes in that order.  Here are the relevant
parts of the Makefile:

--8<---------------cut here---------------start------------->8---
default: test


# test runs the unit tests
# we run this one package at a time here because running the entire suite in
# one command creates memory usage issues when running in Travis-CI.
test: fmtcheck generate
        go list $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=2m 


# generate runs `go generate` to build the dynamically generated
# source files.
        @which stringer > /dev/null; if [ $$? -ne 0 ]; then \
          go get -u; \
        go generate ./...
        @go fmt command/internal_plugin_list.go > /dev/null


        @sh -c "'$(CURDIR)/scripts/'"
--8<---------------cut here---------------end--------------->8---

So, in essence this runs "go generate", "go fmt", and "go test".  The
script seems to be a read-only linter to assist the
Terraform maintainers in finding badly formatted Golang files.

This is slightly different from the installation procedure that our
go-build-system runs.  When you build the attached package (which
packages an older version of terraform for now), our go-build-system
runs steps like the following (in order from top to bottom):

* Phase: unpack: Make a "src/" directory.
* Phase: setup-environment: set GOPATH to (getcwd) and GOBIN to $out/bin.
* Phase: build: go install -v -x '-ldflags=-s -w'
* Phase: check: go test

All in all, this has raised some questions in my mind:

1) Is it bad that our package definition isn't running "go generate" or
"go fmt"?  Do you know if "go install" does this for us somehow?  I
don't think "stringer" or "mockgen" are present in the build
environment, but our "go install" invocation seems to build terraform
even without them.  I wonder if the built terraform is broken in some
ways because we didn't run the code generation/formatting steps.

2) After I ran "make" ad-hoc, I couldn't find a built "terraform"
executable anywhere.  Where is it?  Am missing something obvious, or
could it be that the official documentation incomplete and I need to ask
upstream for advice?

3) The official instructions seem to arbitrarily choose to run the build
in parallel, using 4 threads, which means this package won't play nice
with build arguments like --cores.  I suppose I might need to work with
upstream to fix that.

This feels so close, and yet so far.  Hopefully we only have a little
more to do to get Terraform packaged well!  Thank you again for your


Attachment: 0001-gnu-Add-terraform.patch
Description: Text Data

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]