Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Alpine Linux #597

Closed
james-crowley opened this issue May 17, 2019 · 10 comments
Closed

Support for Alpine Linux #597

james-crowley opened this issue May 17, 2019 · 10 comments
Labels

Comments

@james-crowley
Copy link
Contributor

I am trying to utilize this Terraform plugin in a docker build that runs Alpine linux. Currently, when I try to use the plugin by adding the binary to my docker container, I get the following error:


* provider.libvirt: * fork/exec ./terraform.d/plugins/linux_amd64/terraform-provider-libvirt: no such file or directory

This error lead to to this issue: vancluever/terraform-provider-acme#29

Looks like Alpine needs a static linked binary instead of dynamic lined binary, which is what your binaries build as.

I tried to manually build the plugin, but to make it statically linked, I think I need to disable CGO_ENABLED, which is required to be enabled by libvirt-go.

After install all the requirements and trying to disable CGO I end up with this error:

go install -ldflags "-w -extldflags "-static" -X main.version=$(git describe --always --abbrev=40 --dirty)"
# github.com/dmacvicar/terraform-provider-libvirt/libvirt
libvirt/config.go:16:15: undefined: libvirt.Connect
make: *** [Makefile:14: install] Error 2

I am not sure what the solution is as I am pretty new to GO. But any help you guys can provide would be great!

@MalloZup
Copy link
Collaborator

MalloZup commented May 20, 2019

@james-crowley thx for Issue. I have some speculation in mind but can you provide the whole setup to reproduce it locally so I could experiment when i have some spare time? tia

E.g the version of alpine linux, dockerfile etc. etc

@james-crowley
Copy link
Contributor Author

@MalloZup Sorry for the delay, I was on vacation last week.

Here is my dockerfile I am trying to use to build the plugin:

FROM golang:alpine

# Update APK
RUN apk update && apk upgrade

# Install Dependencies
RUN apk add git make pkgconfig libvirt gcc libvirt-dev libc-dev

# Debugging packages
RUN apk add file nano

RUN go get github.com/dmacvicar/terraform-provider-libvirt

I am currently testing is on by Mac running 10.13.6.

Additionally, here is my dockerfile that I would be using once I get the plugin binary built:

# Grab the Terraform binary
FROM hashicorp/terraform:0.11.13 AS terraform

## Python Base Image
FROM python:3-alpine

# Update APK
RUN apk update && apk upgrade

# Install Dependencies
RUN apk add git gettext sshpass openssh nano
#RUN apk add git make pkgconfig libvirt gcc libvirt-dev libc-dev file nano wget

# Grab Libvirt Plugin
RUN wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.5.1/terraform-provider-libvirt-0.5.1.Ubuntu_18.04.amd64.tar.gz
RUN tar -xvf terraform-provider-libvirt-0.5.1.Ubuntu_18.04.amd64.tar.gz

# Copy Terraform binary to image
COPY --from=terraform /bin/terraform /bin/

# Make temp ssh key
RUN mkdir -p /root/.ssh/
RUN ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''

# Setup Terraform Folder Struc
RUN mkdir -p /root/.terraform.d/plugins/linux_amd64/
RUN mv terraform-provider-libvirt /root/.terraform.d/plugins/linux_amd64/

If you need anything else please let me know!

@james-crowley
Copy link
Contributor Author

james-crowley commented Jun 5, 2019

@MalloZup Any updates on this issue? I am putting together a work flow/demo and would love to use alpine for it. I know you guys got your handsful with Terraform v0.12, but I did not know if you had quick fix for this.

Thanks for the help!

@MalloZup
Copy link
Collaborator

MalloZup commented Jun 5, 2019

@james-crowley ok I spent some time to your issue.

for building the provider-libvirt to alpine-linux:

I have used your 1st dockerfile

go # ls
bin  src

/go # cd src/github.com/dmacvicar/terraform-provider-libvirt/
/go/src/github.com/dmacvicar/terraform-provider-libvirt # ls
CHANGELOG.md     LICENSE          README.md        go.mod           libvirt          main_test.go     travis           website
CONTRIBUTING.md  Makefile         examples         go.sum           main.go          tools.go         vendor

/go/src/github.com/dmacvicar/terraform-provider-libvirt # make
go fmt ./libvirt .
libvirt/resource_libvirt_volume_test.go
go run golang.org/x/lint/golint -set_exit_status ./libvirt .
package golang.org/x/lint/golint: cannot find package "golang.org/x/lint/golint" in any of:
	/usr/local/go/src/golang.org/x/lint/golint (from $GOROOT)
	/go/src/golang.org/x/lint/golint (from $GOPATH)
make: *** [Makefile:42: lint-check] Error 1

/go/src/github.com/dmacvicar/terraform-provider-libvirt # apk add golang
ERROR: unsatisfiable constraints:
  golang (missing):
    required by: world[golang]
/go/src/github.com/dmacvicar/terraform-provider-libvirt # apk add go
(1/1) Installing go (1.11.5-r0)
Executing busybox-1.29.3-r10.trigger
OK: 420 MiB in 85 packages

/go/src/github.com/dmacvicar/terraform-provider-libvirt # make
go fmt ./libvirt .
go run golang.org/x/lint/golint -set_exit_status ./libvirt .
package golang.org/x/lint/golint: cannot find package "golang.org/x/lint/golint" in any of:
	/usr/local/go/src/golang.org/x/lint/golint (from $GOROOT)
	/go/src/golang.org/x/lint/golint (from $GOPATH)
make: *** [Makefile:42: lint-check] Error 1

/go/src/github.com/dmacvicar/terraform-provider-libvirt # make build
go fmt ./libvirt .
go run golang.org/x/lint/golint -set_exit_status ./libvirt .
package golang.org/x/lint/golint: cannot find package "golang.org/x/lint/golint" in any of:
	/usr/local/go/src/golang.org/x/lint/golint (from $GOROOT)
	/go/src/golang.org/x/lint/golint (from $GOPATH)
make: *** [Makefile:42: lint-check] Error 1

/go/src/github.com/dmacvicar/terraform-provider-libvirt # go get -u golang.org/x/lint/golint
go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;
	ignoring go.mod;
	see 'go help modules'

/go/src/github.com/dmacvicar/terraform-provider-libvirt # make build
go fmt ./libvirt .
go run golang.org/x/lint/golint -set_exit_status ./libvirt .
go vet ./libvirt
go build -ldflags "-X main.version=$(git describe --always --abbrev=40 --dirty)"
/go/src/github.com/dmacvicar/terraform-provider-libvirt # ls
CHANGELOG.md                Makefile                    go.mod                      main.go                     tools.go                    website
CONTRIBUTING.md             README.md                   go.sum                      main_test.go                travis
LICENSE                     examples                    libvirt                     terraform-provider-libvirt  vendor
/go/src/github.com/dmacvicar/terraform-provider-libvirt # cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.9.4
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

@MalloZup
Copy link
Collaborator

MalloZup commented Jun 5, 2019

In this way you have the binary. Use the make targets for that, especially the make build.

Once you have builded to alpine you can transfer to your other container

@MalloZup
Copy link
Collaborator

MalloZup commented Jun 5, 2019

@james-crowley let me know if you have other issue. But i think it should be solved and we can close once you have positive feedback. Thx!

@james-crowley
Copy link
Contributor Author

@MalloZup After some testing it seems to work. The only issue I ran into is the new /dev/urandom change in the latest update, as the building in the golang docker container only builds the current version.

When I build the Alpine binary, is there away to tell it to build a certain version? I tried to checkout https://github.com/dmacvicar/terraform-provider-libvirt/tree/v0.5.1 , but building it gave me an error.

@MalloZup
Copy link
Collaborator

@james-crowley for building a certain releases you could do git reset -- GIT-HASH commit --hard and the hash should be the released one . For example 0.5.2 is the c0e46b5

@james-crowley
Copy link
Contributor Author

@MalloZup thanks for all the help. Closing the issue.

@MalloZup
Copy link
Collaborator

@james-crowley yw! feel free to share your presentation some days 😺 and good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants