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

feat: simplify and optimise #43

Merged
merged 1 commit into from
May 15, 2024
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 .terraformrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
disable_checkpoint = true
plugin_cache_dir = "/home/runtimeuser/.terraform.d/plugin-cache"
38 changes: 20 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,19 @@ RUN cd /src && \
export CGO_ENABLED=0 && \
go install golang.org/x/tools/cmd/goimports@latest && \
go install mvdan.cc/gofumpt@latest && \
# go install github.com/terraform-docs/terraform-docs@$TERRAFORM_DOCS_VERSION && \
go install github.com/Azure/terraform-module-test-helper/bin/breaking_detect@$TFMOD_TEST_HELPER_VERSION && \
go install github.com/securego/gosec/v2/cmd/gosec@$GOSEC_VERSION && \
# go install github.com/minamijoyo/hcledit@$HCLEDIT_VERSION && \
git clone https://github.com/lonegunmanb/hcledit.git && \
cd hcledit && git checkout $HCLEDIT_VERSION && go install && \
cd /src && \
go install github.com/lonegunmanb/previousTag@latest && \
go install github.com/magodo/hclgrep@latest && \
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH || $GOPATH)/bin $GOLANGCI_LINT_VERSION && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCI_LINT_VERSION && \
go install github.com/lonegunmanb/avmfix@$AVMFIX_VERSION && \
go install github.com/lonegunmanb/yorbox@$YORBOX_VERSION && \
go install github.com/Azure/grept@$GREPT_VERSION && \
go install github.com/lonegunmanb/newres/v3@$NEWRES_VERSION && \
go install github.com/lonegunmanb/hclmerge@$HCLMERGE_VERSION && \
# curl '-#' -fL -o /tmp/yor.tar.gz https://github.com/bridgecrewio/yor/releases/download/${YOR_VERSION}/yor_${YOR_VERSION}_linux_${TARGETARCH}.tar.gz && \
# tar -xzf /tmp/yor.tar.gz -C /go/bin && chmod +x /go/bin/yor
# go install github.com/terraform-linters/tflint@$TFLINT_VERSION && \
git clone https://github.com/lonegunmanb/tflint.git && \
cd tflint && git checkout $TFLINT_VERSION && \
go install && \
cd /src && \
git clone https://github.com/lonegunmanb/yor.git && \
cd yor && git checkout main && \
Expand All @@ -69,23 +60,30 @@ RUN cd /src && \
git clone https://github.com/tfutils/tfenv.git && \
cd /src/tfenv && \
git checkout $TFENV && \
rm -rf .git && \
cd /src && \
git clone https://github.com/iamhsa/pkenv.git && \
cd pkenv && \
rm -rf .git

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 as runner
ARG GOLANG_IMAGE_TAG=1.19
ARG TERRAFORM_VERSION=1.3.3
ARG TARGETARCH
ARG HOME_DIR=/home/runtimeuser
ARG PACKER_VERSION=1.9.4
ARG TFSEC_VERSION=v1.28.4
ARG TFLINT_VERSION=v0.41.0
ENV TFLINT_PLUGIN_DIR /home/runtimeuser/tflint
ENV GOROOT=/usr/local/go
ENV GOPATH=/home/runtimeuser/go
ENV PATH=$PATH:/home/runtimeuser/tfenv/bin:/pkenv/bin:$GOROOT/bin:$GOPATH/bin
ENV PATH=$PATH:${HOME_DIR}/tfenv/bin:${HOME_DIR}/pkenv/bin:$GOROOT/bin:$GOPATH/bin
ENV TFLINTENV_DEFAULT_VERSION=$TFLINT_VERSION
ENV TFLINTENV_HOME_DIR=/home/runtimeuser/tflintenv
ENV TFENV_AUTO_INSTALL=true
ENV TFENV_TERRAFORM_VERSION=$TERRAFORM_VERSION
ENV TF_CLI_CONFIG_FILE=/home/runtimeuser/.terraformrc
ENV TF_CLI_CONFIG_FILE=${HOME_DIR}/.terraformrc
# Update image, install and configure system-wide software
RUN yum update -y && \
yum install -y ca-certificates zip unzip jq python3-devel python3-pip make git less diffutils build-essential openssh-server wget && \
tdnf install moby-cli ca-certificates -y && \
Expand All @@ -97,13 +95,17 @@ RUN yum update -y && \
git config --global user.email "[email protected]" && \
git config --global user.name "github-actions[bot]" && \
git config --global --add safe.directory '*'
RUN mkdir /home/runtimeuser && \
chmod -R 777 /home/runtimeuser
COPY .terraformrc /home/runtimeuser/.terraformrc
# Create home directory, copy over utilities for xyzenv, terraform cli config, and set permissions
RUN mkdir ${HOME_DIR}
COPY .terraformrc ${HOME_DIR}/.terraformrc
COPY --from=build /go/bin /usr/local/go/bin
COPY --from=build /src/tfenv /home/runtimeuser/tfenv
RUN chmod 777 /home/runtimeuser/tfenv && \
git clone https://github.com/iamhsa/pkenv.git /pkenv && \
cd /pkenv && rm -rf .git && \
COPY --from=build /src/tfenv ${HOME_DIR}/tfenv
COPY --from=build /src/pkenv ${HOME_DIR}/pkenv
RUN mkdir ${HOME_DIR}/tflintenv && \
mkdir -p ${HOME_DIR}/.terraform.d/plugin-cache && \
chmod -Rv a+rwX ${HOME_DIR} && \
chmod 777 ${HOME_DIR}/tfenv/bin/* && \
chmod 777 ${HOME_DIR}/pkenv/bin/* && \
rm -r /tmp/* && \
yum clean all
ENV HOME=${HOME_DIR}
6 changes: 6 additions & 0 deletions avm_scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "==> Cleaning terraform directories, state files and lock files..."
find -type d -name .terraform -print0 | xargs -0 rm -rf
find -type f -name .terraform.lock.hcl -print0 | xargs -0 rm -rf
find -type f -name 'terraform.tfstate*' -print0 | xargs -0 rm -rf
exit 0
6 changes: 6 additions & 0 deletions avm_scripts_canary/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "==> Cleaning terraform directories, state files and lock files..."
find -type d -name .terraform -print0 | xargs -0 rm -rf
find -type f -name .terraform.lock.hcl -print0 | xargs -0 rm -rf
find -type f -name 'terraform.tfstate*' -print0 | xargs -0 rm -rf
exit 0
10 changes: 8 additions & 2 deletions avmmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ checkovplancheck:

fmtcheck: gofmtcheck tffmtcheck terrafmtcheck

pr-check: fmtcheck tfvalidatecheck lint unit-test
pr-check: clean fmtcheck tfvalidatecheck lint unit-test clean2

unit-test:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/run-unit-test.sh" | bash
Expand Down Expand Up @@ -80,4 +80,10 @@ autofix:
grept-apply:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/grept-apply.sh" | bash

.PHONY: docs docscheck fmt gofmt fumpt gosec tffmtcheck tfvalidatecheck terrafmtcheck gofmtcheck golint tflint lint checkovcheck checkovplancheck fmtcheck pr-check unit-test e2e-test version-upgrade-test terrafmt pre-commit depsensure yor-tag autofix tools
clean:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/clean.sh" | bash

clean2:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/clean.sh" | bash

.PHONY: clean clean2 docs docscheck fmt gofmt fumpt gosec tffmtcheck tfvalidatecheck terrafmtcheck gofmtcheck golint tflint lint checkovcheck checkovplancheck fmtcheck pr-check unit-test e2e-test version-upgrade-test terrafmt pre-commit depsensure yor-tag autofix tools
Loading