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

Mirror plugins during build #93

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Terraform providers are installed into the bundle during porter build.
We recommend that you put your provider declarations into a single file, e.g. "terraform/providers.tf".
Then use `initFile` to specify the relative path to this file within workingDir.
This will dramatically improve Docker image layer caching and performance when building, publishing and installing the bundle.
> Note: this approach isn't suitable when using terraform modules as those need to be "initilized" as well but aren't specified in the `initFile`. You shouldn't specifiy an `initFile` in this situation.

## Terraform state

Expand Down
10 changes: 7 additions & 3 deletions pkg/terraform/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (

const dockerfileLines = `
RUN apt-get update && apt-get install -y wget unzip && \
apt-get clean -y && rm -rf /var/lib/apt/lists/* && \
wget https://releases.hashicorp.com/terraform/{{.ClientVersion}}/terraform_{{.ClientVersion}}_linux_amd64.zip && \
unzip terraform_{{.ClientVersion}}_linux_amd64.zip -d /usr/bin && \
rm terraform_{{.ClientVersion}}_linux_amd64.zip
COPY {{.WorkingDir}}/{{.InitFile}} $BUNDLE_DIR/{{.WorkingDir}}/
RUN cd $BUNDLE_DIR/{{.WorkingDir}} && terraform init -backend=false
RUN cd $BUNDLE_DIR/{{.WorkingDir}} && \
terraform init -backend=false && \
rm -fr .terraform/providers && \
terraform providers mirror /usr/local/share/terraform/plugins
`

// BuildInput represents stdin passed to the mixin for the build command.
Expand All @@ -24,8 +28,8 @@ type BuildInput struct {

// MixinConfig represents configuration that can be set on the terraform mixin in porter.yaml
// mixins:
// - terraform:
// version: 0.12.17
// - terraform:
// version: 0.12.17
type MixinConfig struct {
ClientVersion string `yaml:"clientVersion,omitempty"`
InitFile string `yaml:"initFile,omitempty"`
Expand Down