-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gcp support, and dockerfiles with nix support now
- kloudlite CRDs are now applied with `--server-side` flag
- Loading branch information
1 parent
9fd6985
commit 6276eab
Showing
104 changed files
with
1,532 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
** | ||
# !terraform | ||
# !build-scripts | ||
# !infrastructure-templates | ||
# infrastructure-templates/**/.terraform.d | ||
# !.ci | ||
# !flake.nix | ||
# !flake.lock | ||
# !context.tar | ||
!terraform | ||
!build-scripts | ||
!infrastructure-templates | ||
!.ci | ||
!.terraform.d.zip | ||
infrastructure-templates/**/.terraform.d | ||
!context.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
.direnv | ||
.terraform.d | ||
.dump | ||
.buildx-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
#syntax=docker/dockerfile:1.4 | ||
FROM alpine:3.16 | ||
RUN apk add bash curl gettext jq lz4 helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community --no-cache | ||
RUN apk add bash curl gettext jq lz4 helm kubectl zstd --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community --no-cache | ||
RUN curl -L0 https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip > tf.zip && unzip tf.zip && mv terraform /usr/local/bin && rm tf.zip | ||
RUN adduser --disabled-password --home="/app" --uid 1717 nonroot | ||
USER nonroot | ||
WORKDIR /app | ||
COPY --chown=nonroot ./terraform ./terraform | ||
RUN mkdir -p infrastructure-templates | ||
COPY --chown=nonroot ./infrastructure-templates ./infrastructure-templates | ||
# COPY --chown=nonroot ./infrastructure-templates ./infrastructure-templates | ||
ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache" | ||
# COPY .terraform.d.zip /app/terraform.zip | ||
RUN mkdir -p $TF_PLUGIN_CACHE_DIR | ||
SHELL ["/bin/bash", "-c"] | ||
RUN <<'EOF' | ||
for dir in $(ls -d ./infrastructure-templates/*); do | ||
pushd $dir | ||
terraform init -backend=false & | ||
popd | ||
done | ||
# SHELL ["/bin/bash", "-c"] | ||
# RUN <<'EOF' | ||
# for dir in $(ls -d ./infrastructure-templates/{aws,gcp}/*); do | ||
# pushd $dir | ||
# terraform init -backend=false & | ||
# popd | ||
# done | ||
# | ||
# wait | ||
# | ||
# tdir=$(basename $(dirname $TF_PLUGIN_CACHE_DIR)) | ||
# tar cf - $tdir | lz4 -v -5 > tf.lz4 && rm -rf $tdir | ||
# EOF | ||
# ENV DECOMPRESS_CMD="lz4 -d tf.lz4 | tar xf -" | ||
# ENV TEMPLATES_DIR="/app/infrastructure-templates" | ||
|
||
WORKDIR /app | ||
ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache" | ||
RUN mkdir -p $TF_PLUGIN_CACHE_DIR | ||
RUN cat > script.sh <<EOF | ||
#!/usr/bin/env bash | ||
echo "hi" >> log.file | ||
ls -d ./infrastructure-templates/{gcp,aws}/* | tee log.file | xargs -I{} bash -c "echo name is {}; $(terraform init chdir={} -backend=false &)" | ||
# for dir in $(ls -d ./infrastructure-templates/{gcp,aws}/*); do | ||
# echo $dir >> log.file | ||
# pushd $dir | ||
# terraform init -backend=false & | ||
# popd | ||
# done | ||
|
||
wait | ||
|
||
tdir=$(basename $(dirname $TF_PLUGIN_CACHE_DIR)) | ||
tar cf - $tdir | lz4 -v -5 > tf.lz4 && rm -rf $tdir | ||
EOF | ||
|
||
COPY --chown=nonroot ./terraform ./terraform | ||
COPY --chown=nonroot ./infrastructure-templates ./infrastructure-templates | ||
# RUN --mount=type=bind,source=./infrastructure-templates,target=infrastructure-templates \ | ||
# --mount=type=bind,source=./terraform,target=terraform \ | ||
RUN --mount=type=cache,id=sample,target=/app/.terraform.d/plugin-cache \ | ||
chmod +x /app/script.sh && bash /app/script.sh | ||
RUN adduser --disabled-password --home="/app" --uid 1717 nonroot | ||
USER nonroot | ||
ENV DECOMPRESS_CMD="lz4 -d tf.lz4 | tar xf -" | ||
ENV TEMPLATES_DIR="/app/infrastructure-templates" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# vim: set ft=dockerfile: | ||
FROM nixos/nix:latest AS builder | ||
|
||
WORKDIR /app | ||
|
||
# COPY flake.nix flake.lock ./ | ||
ENV NIX_STORE_DIR=/nix/store2 | ||
|
||
RUN --mount=type=bind,source=flake.nix,target=flake.nix \ | ||
--mount=type=bind,source=flake.lock,target=flake.lock \ | ||
--mount=type=cache,target=/nix/store2 \ | ||
cp -R /nix/store /nix/store2 && nix \ | ||
--extra-experimental-features "nix-command flakes" \ | ||
--option filter-syscalls false \ | ||
build .#container | ||
|
||
# Copy the Nix store closure into a directory. The Nix store closure is the | ||
# entire set of Nix store values that we need for our build. | ||
RUN mkdir /tmp/nix-store-closure | ||
RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure | ||
|
||
# Set up the environment to use the packages defined in the flake | ||
# ENV PATH /root/.nix-profile/bin:$PATH | ||
|
||
# Your application's setup continues here... | ||
# FROM ubuntu:latest | ||
# FROM cgr.dev/chainguard/busybox:latest | ||
# FROM debian:12-slim | ||
# FROM busybox:latest | ||
FROM cgr.dev/chainguard/bash:latest | ||
# FROM gcr.io/distroless/static:latest | ||
COPY --from=builder /tmp/nix-store-closure /nix/store | ||
RUN mkdir -p /usr/local/bin | ||
COPY --from=builder /app/result/bin/* /usr/local/bin | ||
|
||
RUN mkdir -p /etc/ssl/certs | ||
COPY --from=builder /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt | ||
|
||
WORKDIR /app | ||
COPY ./terraform ./terraform | ||
ARG CLOUD_PROVIDER | ||
RUN mkdir -p infrastructure-templates | ||
COPY ./infrastructure-templates/${CLOUD_PROVIDER} ./infrastructure-templates/${CLOUD_PROVIDER} | ||
ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache" | ||
# COPY .terraform.d.zip /app/terraform.zip | ||
RUN mkdir -p $TF_PLUGIN_CACHE_DIR | ||
SHELL ["bash", "-c"] | ||
RUN <<'EOF' | ||
# for dir in $(ls -d ./infrastructure-templates/{gcp,aws}/*); do | ||
for dir in $(ls -d ./infrastructure-templates/${CLOUD_PROVIDER}/*); do | ||
pushd $dir | ||
terraform init -backend=false & | ||
popd | ||
done | ||
|
||
wait | ||
|
||
tdir=$(basename $(dirname $TF_PLUGIN_CACHE_DIR)) | ||
# tar cf - $tdir | lz4 -v -5 > tf.lz4 && rm -rf $tdir | ||
tar cf - $tdir | zstd -12 --compress > tf.zst && rm -rf $tdir | ||
EOF | ||
# ENV DECOMPRESS_CMD="lz4 -d tf.lz4 | tar xf -" | ||
ENV DECOMPRESS_CMD="zstd --decompress tf.zst --stdout | tar xf -" | ||
ENV TEMPLATES_DIR="/app/infrastructure-templates" | ||
|
||
# # Your application's setup continues here... | ||
# FROM ubuntu:latest | ||
# # FROM debian:12-slim | ||
# RUN mkdir -p /etc/ssl/certs | ||
# COPY --from=builder /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt | ||
# | ||
# COPY --from=builder /tmp/nix-store-closure /nix/store | ||
# COPY --from=builder /app/result/bin/* /usr/local/bin | ||
# | ||
# WORKDIR /app | ||
# # COPY ./terraform ./terraform | ||
# # RUN mkdir -p infrastructure-templates | ||
# # COPY ./infrastructure-templates ./infrastructure-templates | ||
# ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache" | ||
# # COPY .terraform.d.zip /app/terraform.zip | ||
# RUN mkdir -p $TF_PLUGIN_CACHE_DIR | ||
# RUN cat > script.sh <<EOF | ||
# #!/usr/bin/env bash | ||
# echo "hi" | ||
# # ls -d ./infrastructure-templates/{gcp,aws}/* | tee log.file | xargs -I{} bash -c "echo name is {}; pushd {}; terraform init -backend=false ;popd" | ||
# item=$(ls -d infrastructure-templates/{gcp,aws}/* | xargs -I{} printf "%s " {}) | ||
# echo "$item" | ||
# exit 1 | ||
# # for dir in $(ls -d infrastructure-templates/{gcp,aws}/*); do | ||
# # echo $dir >> log.file | ||
# # pushd $dir | ||
# # terraform init -backend=false & | ||
# # popd | ||
# # done | ||
# | ||
# wait | ||
# | ||
# # exit 1 | ||
# tdir=$(basename $(dirname $TF_PLUGIN_CACHE_DIR)) | ||
# tar cf - $tdir | lz4 -v -5 > tf.lz4 && rm -rf $tdir | ||
# EOF | ||
# RUN --mount=type=bind,source=infrastructure-templates,target=infrastructure-templates,readwrite \ | ||
# --mount=type=bind,source=terraform,target=terraform \ | ||
# --mount=type=cache,target=/app/.terraform.d/plugin-cache \ | ||
# chmod +x ./script.sh && bash ./script.sh && cat log.file && exit 1 | ||
# ENV DECOMPRESS_CMD="lz4 -d tf.lz4 | tar xf -" | ||
# ENV TEMPLATES_DIR="/app/infrastructure-templates" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# vim: set ft=dockerfile: | ||
FROM nixos/nix:latest AS nix | ||
|
||
FROM busybox:latest | ||
|
||
RUN mkdir -p /etc/ssl/certs | ||
COPY --from=nix /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt | ||
|
||
WORKDIR /app | ||
RUN --mount=type=bind,source=context.tar,target=context.tar \ | ||
tar xf context.tar && \ | ||
mkdir /nix && mv nixstore /nix/store && \ | ||
mkdir -p /usr/local/bin && mv result/bin/* /usr/local/bin/ && rm -rf result && \ | ||
mv tf.zst /app/tf.zst | ||
|
||
RUN adduser --disabled-password --home="/app" --uid 1717 nonroot | ||
USER nonroot | ||
COPY --chown=nonroot ./terraform ./terraform | ||
COPY --chown=nonroot ./infrastructure-templates ./infrastructure-templates | ||
# COPY --from=nixstore ./ /nix/store | ||
# RUN mkdir -p /usr/local/bin | ||
# COPY --from=builder ./bin/* /usr/local/bin | ||
# RUN --mount=type=bind,source=result,target=/result cp -r /result/bin/* /usr/local/bin | ||
# COPY ./bin/* /usr/local/bin | ||
# WORKDIR /app | ||
# COPY ./terraform ./terraform | ||
# ARG CLOUD_PROVIDER | ||
# COPY ./infrastructure-templates/${CLOUD_PROVIDER} ./infrastructure-templates/${CLOUD_PROVIDER} | ||
ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache" | ||
# # COPY ./tf.zst ./tf.zst | ||
ENV DECOMPRESS_CMD="zstd --decompress tf.zst --stdout | tar xf -" | ||
ENV TEMPLATES_DIR="/app/infrastructure-templates" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#! /usr/bin/env bash | ||
|
||
role="kloudlite_custom_role" | ||
project_id="rich-wavelet-412321" | ||
|
||
service_account="kloudlite-sa" | ||
# export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE="/home/nxtcoder17/Downloads/rich-wavelet-412321-adc26c13a544.json" | ||
# export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE="/tmp/gcp-auth.json" | ||
|
||
# gcloud auth login | ||
|
||
gcloud iam roles create $role \ | ||
--project=$project_id \ | ||
--title="Kloudlite Role" \ | ||
--description="kloudlite admin role" \ | ||
--permissions=compute.instances.start,compute.instances.stop \ | ||
--stage=GA | tee -a /tmp/output.json | ||
|
||
gcloud iam service-accounts create $service_account \ | ||
--description="service account json" \ | ||
--display-name="Kloudlite Account" \ | ||
--project="$project_id" | ||
|
||
gcloud projects add-iam-policy-binding "$project_id" \ | ||
--member="serviceAccount:$service_account@" \ | ||
--role="projects/$project_id/roles/$role" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.