terraform-switcher icon indicating copy to clipboard operation
terraform-switcher copied to clipboard

Alpine linux compatible version

Open hongkongkiwi opened this issue 5 years ago • 13 comments

Installer does not install a correct version for alpine linux.

Alpine linux does not support musl and therefore needs a different compilation target.

Here's a simple docker to build it on alpine:

FROM alpine:3.11 AS build
RUN apk upgrade -U -a && \
          apk upgrade && \
          apk add --update go gcc g++ git ca-certificates curl make && \
          git clone https://github.com/warrensbox/terraform-switcher.git /app
WORKDIR /app
RUN CGO_ENABLED=1 GOOS=linux go build

hongkongkiwi avatar Oct 19 '20 09:10 hongkongkiwi

s/musl/glibc/

skyzyx avatar Dec 07 '20 19:12 skyzyx

The above builder works great for a multi-stage docker image, where you can just COPY --from=build /app/terraform-switcher /usr/local/bin/tfswitch in a later image.

llamahunter avatar Mar 06 '21 20:03 llamahunter

Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:

ENV TERRAFORM_VERSION=0.14.7
RUN curl -L -o terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
 && unzip terraform.zip \
 && rm terraform.zip \
 && mkdir -p /root/.terraform.versions \
 && mv terraform /root/.terraform.versions/terraform_${TERRAFORM_VERSION}

repeat as needed for other TERRAFORM_VERSION's. Or make a loop and iterate through a list (tho that will blow the docker image cache if you change the list to add a new version).

llamahunter avatar Mar 06 '21 20:03 llamahunter

It would be great oh have a tfswitch Dockerhub image that can just be pulled in CI. This way every new version releasse would also create a new Docker (latest) image.

barakbd avatar May 20 '21 18:05 barakbd

@llamahunter

Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:

Ain't it going to be a bit more straightforward to make use of tfswitch to pre-populate your docker image with needed TF versions? 😄 Something like this:

RUN curl_cmd_to_install_tfswitch
RUN for TF_VER in 0.14.7 0.15.3 …; do tfswitch ${TF_VER}; done; tfswitch <TF_VER_TO_USE_BY_DEFAULT>

yermulnik avatar May 20 '21 18:05 yermulnik

I think pre-populating the image with a specific version defeats the purpose of tfswitch :)

barakbd avatar May 20 '21 19:05 barakbd

Well, it depends on the security policies and all that stuff: imagine your build server has access to pre-approved external endpoints but your CI has not (or an approval is required from security team for all the external stuff you bundle into container image) — here comes the need to embed stuff into container image at buildtime rather than downloading it at runtime and tfswitch helps to switch between known in advance versions of TF. I'd say this is the use case of big corporations which sometime are referred as "bloody enterprises" =)

yermulnik avatar May 20 '21 19:05 yermulnik

@llamahunter

Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:

Ain't it going to be a bit more straightforward to make use of tfswitch to pre-populate your docker image with needed TF versions? 😄 Something like this:

Ah, yeah, that seems a bit simpler. Just use tfswitch to download the binaries itself when building the image.

llamahunter avatar May 20 '21 19:05 llamahunter

I think pre-populating the image with a specific version defeats the purpose of tfswitch :)

Er... not really. depends on your use case. This is an image used elsewhere. We know that many users will be using specific versions of terraform. Rather than EVERY execution needing to download those versions OVER AND OVER, we download them once and bake them in to the image.

llamahunter avatar May 20 '21 19:05 llamahunter

@llamahunter - What do you think of my above comment regarding a dockerhub image? Please add a 👍 or 👎 . Should I open a separate issue for that?

barakbd avatar May 20 '21 20:05 barakbd

Ideally, for us, it would be a binary installable from https://pkgs.alpinelinux.org/packages.

llamahunter avatar May 21 '21 00:05 llamahunter

@llamahunter Ideally, I would like to create an Alpine linux binary. Similar to https://aur.archlinux.org/packages/tfswitch where users can install with yay:

# compiled from source
yay tfswitch

# precompiled
yay tfswitch-bin

I'll look into this for Alpine linux

warrensbox avatar May 25 '21 04:05 warrensbox

@barakbd I looked your docker MR. I have some suggestions. I will reach out to you soon.

warrensbox avatar May 25 '21 13:05 warrensbox