Skip to content

Commit

Permalink
refactor: remove providers mirror
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Dec 28, 2023
1 parent 93160bb commit 9c8cdea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 59 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ jobs:
# configure build cache,
# ref to https://github.com/moby/buildkit/tree/v0.11.5#registry-push-image-and-cache-separately.
cache-from: |
type=registry,ref=${{ env.REPO }}/build-cache:${{ matrix.target }}-${{ matrix.task }}${{ startsWith(github.ref, 'refs/tags/') && '-release' || '' }}
type=registry,ref=${{ env.REPO }}/build-cache:${{ matrix.target }}-${{ matrix.task }}
cache-to: |
${{ github.event_name != 'pull_request' && format('type=registry,mode=max,oci-mediatypes=false,compression=gzip,ref={0}/build-cache:{1}-{2}{3},ignore-error=true', env.REPO, matrix.target, matrix.task, startsWith(github.ref, 'refs/tags/') && '-release' || '' ) || '' }}
no-cache-filters: |
${{ startsWith(github.ref, 'refs/tags/') && 'fetch' || '' }}
${{ github.event_name != 'pull_request' && format('type=registry,mode=max,oci-mediatypes=false,compression=gzip,ref={0}/build-cache:{1}-{2},ignore-error=true', env.REPO, matrix.target, matrix.task) || '' }}
- name: Setup Cosign
if: ${{ github.event_name != 'pull_request' }}
uses: sigstore/[email protected]
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ Hermit Crab manages the archives as the following layer structure, which is abso
Hermit Crab can reuse the mirroring providers by `terraform providers mirror` as well.

```shell
terraform providers mirror /tmp/providers
terraform providers mirror /tmp/providers-plugins

docker run -d --restart=always -p 80:80 -p 443:443 \
-v /tmp/providers:/usr/share/terraform/providers \
-v /tmp/providers-plugins:/usr/share/terraform/providers/plugins \
sealio/hermitcrab
```

Expand Down Expand Up @@ -144,6 +144,12 @@ Terraform Provider Network Mirror protocol wants [HTTPS](https://en.wikipedia.or
sealio/hermitcrab
```

Also support to launch from Helm Chart.

```shell
helm install my-release oci://ghcr.io/seal-io/helm-charts/hermitcrab
```

After setting up Hermit Crab, you can configure the [CLI Configuration](https://developer.hashicorp.com/terraform/cli/config/config-file) as below to use the mirroring service.

```hcl
Expand Down
53 changes: 0 additions & 53 deletions pack/server/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
#
# Fetch
#
FROM --platform=$TARGETPLATFORM hashicorp/terraform:1.5.7 AS fetch

ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN set -eo pipefail; \
apk add -U --no-cache \
ca-certificates \
curl openssh \
unzip \
git \
jq \
; \
rm -rf /var/cache/apk/*

ENV TF_LOG="ERROR"
WORKDIR /workspace

# download templates
RUN set -eo pipefail; \
echo "walrus-catalog walrus-catalog-sandbox" | tr -s '[:blank:]' '\n' | \
while read -r org _; do \
curl -sSL "https://api.github.com/orgs/$org/repos" | jq -r '.[].name' | \
while read -r repo _; do \
git clone "https://github.com/$org/$repo" "$org"_"$repo" --depth 1; \
done; \
done

# mirror plugins
## cache plugins to reduce network latency
ENV TF_PLUGIN_CACHE_DIR="/workspace/.terraform.d/plugin-cache" \
TF_PLUGIN_MIRROR_DIR="/workspace/.terraform.d/plugins"
RUN set -eo pipefail; \
mkdir -p $TF_PLUGIN_CACHE_DIR; \
mkdir -p $TF_PLUGIN_MIRROR_DIR; \
echo -e "provider_installation {\n \
filesystem_mirror {\n \
path = \"$TF_PLUGIN_MIRROR_DIR\"\n \
}\n \
direct {} \n \
}\n" > /root/.terraformrc && \
find . -maxdepth 1 -type d -name 'walrus-catalog*' -exec sh -c 'terraform -chdir="$1" init && terraform -chdir="$1" providers mirror $TF_PLUGIN_MIRROR_DIR' _ {} \;
## remove non-plugin files to prevent annoying message
RUN set -eo pipefail; \
find $TF_PLUGIN_MIRROR_DIR -type f ! -name "terraform-provider-*" -delete

#
# Release
#
Expand Down Expand Up @@ -77,9 +27,6 @@ ENV LANG='en_US.UTF-8' \
LANGUAGE='en_US:en' \
LC_ALL='en_US.UTF-8'

# get terraform plugins
COPY --from=fetch /workspace/.terraform.d/plugins /usr/share/terraform/providers/plugins

EXPOSE 80 443
VOLUME /var/run/hermitcrab
COPY /image/ /
Expand Down

0 comments on commit 9c8cdea

Please sign in to comment.