Skip to content

Commit bd40827

Browse files
committedApr 18, 2024
feat: initial commit
0 parents  commit bd40827

19 files changed

+525
-0
lines changed
 

‎.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

‎.github/workflows/ci.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: ci
2+
on:
3+
push:
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
- name: Setup Humanitec CLI
12+
uses: humanitec/setup-cli-action@v1
13+
with:
14+
version: "0.21.1"
15+
- name: Setup tflit
16+
uses: terraform-linters/setup-tflint@v4
17+
with:
18+
tflint_version: v0.49.0
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- run: make lint
25+
- env:
26+
HUMANITEC_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
27+
HUMANITEC_ORG: ${{ secrets.HUMANITEC_ORG }}
28+
run: |
29+
# Simulate a humctl login
30+
yq e -n '.token = "'"${HUMANITEC_ORG}"'"' > ~/.humctl
31+
make test
32+
33+
# publish on main
34+
publish:
35+
runs-on: ubuntu-latest
36+
needs: test
37+
if: github.ref == 'refs/heads/main'
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
- run: make publish

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kube/*
2+
setup/terraform/.terraform*
3+
setup/terraform/terraform.tfstate*

‎0_install.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
mkdir -p ./kube
5+
6+
if [ ! -f ./kube/config.yaml ]; then
7+
kind create cluster -n 5min-idp --kubeconfig ./kube/config.yaml --config ./setup/kind/cluster.yaml
8+
fi
9+
10+
# used by humanitec-agent to reach the cluster
11+
kind export kubeconfig --internal -n 5min-idp --kubeconfig ./kube/config-internal.yaml
12+
# used by docker to reach the cluster
13+
cp ./kube/config.yaml ./kube/config-docker.yaml
14+
kubeconfig_docker=$(pwd)/kube/config-docker.yaml
15+
yq '.clusters[0].cluster.server |= sub("127.0.0.1"; "docker.for.mac.localhost")' -i "$kubeconfig_docker"
16+
yq '.clusters[0].cluster.insecure-skip-tls-verify |= true' -i "$kubeconfig_docker"
17+
yq 'del(.clusters[0].cluster.certificate-authority-data)' -i "$kubeconfig_docker"
18+
19+
humctl_token=$(yq .token /root/.humctl)
20+
21+
export HUMANITEC_TOKEN=$humctl_token
22+
export TF_VAR_humanitec_org=$HUMANITEC_ORG
23+
export TF_VAR_kubeconfig=$kubeconfig_docker
24+
25+
terraform -chdir=setup/terraform init -upgrade
26+
terraform -chdir=setup/terraform apply -auto-approve
27+
28+
echo ""
29+
echo ">>>> Everything prepared, ready to deploy application."

‎1_demo.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
if ! humctl get application 5min-idp; then
5+
humctl create application 5min-idp
6+
fi
7+
8+
humctl score deploy --app 5min-idp --env development -f ./score.yaml

‎2_cleanup.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
humctl_token=$(yq .token /root/.humctl)
5+
kubeconfig_docker=$(pwd)/kube/config-docker.yaml
6+
7+
export HUMANITEC_TOKEN=$humctl_token
8+
export TF_VAR_humanitec_org=$HUMANITEC_ORG
9+
export TF_VAR_kubeconfig=$kubeconfig_docker
10+
11+
12+
if humctl get application 5min-idp; then
13+
humctl delete application 5min-idp
14+
fi
15+
16+
terraform -chdir=setup/terraform destroy -auto-approve
17+
18+
kind delete cluster -n 5min-idp
19+
20+
rm -rf ./kube

‎Dockerfile

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM alpine:3.19
2+
3+
LABEL org.opencontainers.image.source https://github.com/johanneswuerbach/5min-idp
4+
5+
RUN apk add --no-cache \
6+
bash curl git jq bash-completion docker-cli && \
7+
mkdir -p /etc/bash_completion.d
8+
9+
# inject the target architecture (https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope)
10+
ARG TARGETARCH
11+
12+
# install kubectl
13+
RUN curl -fsSL "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/$TARGETARCH/kubectl" > /tmp/kubectl && \
14+
install -o root -g root -m 0755 /tmp/kubectl /usr/local/bin/kubectl && \
15+
kubectl completion bash > /etc/bash_completion.d/kubectl && \
16+
rm /tmp/kubectl
17+
18+
# install helm (https://github.com/helm/helm/releases)
19+
RUN mkdir /tmp/helm && \
20+
curl -fsSL https://get.helm.sh/helm-v3.14.4-linux-${TARGETARCH}.tar.gz > /tmp/helm/helm.tar.gz && \
21+
tar -zxvf /tmp/helm/helm.tar.gz -C /tmp/helm && \
22+
install -o root -g root -m 0755 /tmp/helm/linux-${TARGETARCH}/helm /usr/local/bin/helm && \
23+
helm completion bash > /etc/bash_completion.d/helm && \
24+
rm -rf /tmp/helm
25+
26+
# install kind https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries
27+
RUN curl -fsSL https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-${TARGETARCH} > /tmp/kind && \
28+
install -o root -g root -m 0755 /tmp/kind /usr/local/bin/kind && \
29+
rm /tmp/kind
30+
31+
# install terraform (https://github.com/hashicorp/terraform/releases)
32+
RUN mkdir /tmp/terraform && \
33+
curl -fsSL https://releases.hashicorp.com/terraform/1.8.1/terraform_1.8.1_linux_${TARGETARCH}.zip > /tmp/terraform/terraform.zip && \
34+
unzip /tmp/terraform/terraform.zip -d /tmp/terraform && \
35+
install -o root -g root -m 0755 /tmp/terraform/terraform /usr/local/bin/terraform && \
36+
rm -rf /tmp/terraform
37+
38+
# install yq
39+
RUN curl -fsSL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${TARGETARCH} > /tmp/yq && \
40+
install -o root -g root -m 0755 /tmp/yq /usr/local/bin/yq && \
41+
yq shell-completion bash > /etc/bash_completion.d/yq && \
42+
rm /tmp/yq
43+
44+
# install humctl (https://github.com/humanitec/cli/releases)
45+
RUN mkdir /tmp/humctl && \
46+
curl -fsSL https://github.com/humanitec/cli/releases/download/v0.21.0/cli_0.21.0_linux_${TARGETARCH}.tar.gz > /tmp/humctl/humctl.tar.gz && \
47+
tar -zxvf /tmp/humctl/humctl.tar.gz -C /tmp/humctl && \
48+
install -o root -g root -m 0755 /tmp/humctl/humctl /usr/local/bin/humctl && \
49+
humctl completion bash > /etc/bash_completion.d/humctl && \
50+
rm -rf /tmp/humctl
51+
52+
WORKDIR /app
53+
54+
ENTRYPOINT ["/bin/bash"]

‎Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
IMG_TAG ?= latest
2+
IMG ?= ghcr.io/humanitec/5min-idp:$(IMG_TAG)
3+
PLATFORM ?= linux/amd64,linux/arm64
4+
5+
# Build the 5min-idp image
6+
build:
7+
docker buildx build --platform $(PLATFORM) -t $(IMG) .
8+
# Ideally we could remove the next step, but docker on GHA doesn't support
9+
# loading multi-platform builds yet
10+
docker buildx build -t $(IMG) --load .
11+
12+
# Check the 5min-idp image
13+
check-image:
14+
docker run --rm -v $(PWD):/app $(IMG) ./image/check.sh
15+
16+
# Push the 5min-idp image
17+
push:
18+
docker buildx build --platform $(PLATFORM) -t $(IMG) --push .
19+
20+
# Initialize tflint
21+
lint-init:
22+
tflint --init
23+
24+
# Lint terraform directory
25+
lint: lint-init
26+
tflint --config ../.tflint.hcl --chdir=./setup/terraform
27+
28+
# Test the 5min-idp
29+
test: build check-image
30+
docker run --rm -it -h=5min-idp \
31+
-e HUMANITEC_ORG \
32+
-v $(PWD):/app \
33+
-v $(HOME)/.humctl:/root/.humctl \
34+
-v /var/run/docker.sock:/var/run/docker.sock \
35+
$(IMG) ./image/test.sh

‎README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 5min-idp - Quick Humanitec Demo
2+
3+
Your Humanitec Demo Environment in less than 3 minutes.
4+
5+
Required:
6+
7+
* [humctl](https://developer.humanitec.com/platform-orchestrator/cli/)
8+
* docker
9+
10+
## Usage
11+
12+
### Configure
13+
14+
```bash
15+
humctl login
16+
export HUMANITEC_ORG=MY_ORG
17+
```
18+
19+
### Run
20+
21+
* Start the toolbox
22+
23+
```bash
24+
docker run --rm -it -h=5min-idp --pull=always \
25+
-e HUMANITEC_ORG \
26+
-v $(PWD):/app \
27+
-v $HOME/.humctl:/root/.humctl \
28+
-v /var/run/docker.sock:/var/run/docker.sock \
29+
ghcr.io/humanitec/5min-idp
30+
```
31+
32+
* Use it!
33+
34+
```bash
35+
./0_install.sh # install & connect a local cluster powered by kind
36+
./1_demo.sh # deploy your 1st score workload
37+
./2_cleanup.sh # cleanup everything
38+
```

‎image/check.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -exo pipefail
3+
4+
kubectl version --client
5+
helm version
6+
kind version
7+
terraform version
8+
humctl version

‎image/test.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -exo pipefail
3+
4+
./0_install.sh
5+
./1_demo.sh
6+
./2_cleanup.sh

‎score.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Based on https://github.com/score-spec/sample-score-app
2+
3+
apiVersion: score.dev/v1b1
4+
metadata:
5+
name: hello-world
6+
service:
7+
ports:
8+
www:
9+
port: 8080
10+
targetPort: 3000
11+
containers:
12+
hello-world:
13+
image: ghcr.io/score-spec/sample-score-app:main
14+
variables:
15+
PORT: "3000"
16+
MESSAGE: "Hello, World!"
17+
DB_DATABASE: ${resources.db.name}
18+
DB_USER: ${resources.db.username}
19+
DB_PASSWORD: ${resources.db.password}
20+
DB_HOST: ${resources.db.host}
21+
DB_PORT: ${resources.db.port}
22+
resources:
23+
dns:
24+
type: dns
25+
route:
26+
type: route
27+
params:
28+
host: ${resources.dns.host}
29+
path: /
30+
port: 8080
31+
db:
32+
type: postgres

‎setup/.tflint.hcl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugin "terraform" {
2+
enabled = true
3+
preset = "recommended"
4+
}

‎setup/kind/cluster.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
name: 5min-idp
4+
nodes:
5+
- role: control-plane
6+
extraPortMappings:
7+
- containerPort: 30080
8+
hostPort: 30080
9+
listenAddress: "0.0.0.0"
10+
protocol: TCP

‎setup/terraform/idp-base.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Configure k8s namespace naming
2+
3+
resource "humanitec_resource_definition" "k8s_namespace" {
4+
driver_type = "humanitec/echo"
5+
id = "default-namespace"
6+
name = "default-namespace"
7+
type = "k8s-namespace"
8+
9+
driver_inputs = {
10+
values_string = jsonencode({
11+
"namespace" = "$${context.app.id}-$${context.env.id}"
12+
})
13+
}
14+
}
15+
16+
resource "humanitec_resource_definition_criteria" "k8s_namespace" {
17+
resource_definition_id = humanitec_resource_definition.k8s_namespace.id
18+
}
19+
20+
# Configure DNS for localhost
21+
22+
resource "humanitec_resource_definition" "localhost_dns" {
23+
id = "localhost-dns"
24+
name = "localhost-dns"
25+
type = "dns"
26+
driver_type = "humanitec/dns-wildcard"
27+
28+
driver_inputs = {
29+
values_string = jsonencode({
30+
"domain" = "localhost"
31+
"template" = "$${context.app.id}-{{ randAlphaNum 4 | lower}}"
32+
})
33+
}
34+
35+
provision = {
36+
ingress = {
37+
match_dependents = false
38+
is_dependent = false
39+
}
40+
}
41+
}
42+
43+
resource "humanitec_resource_definition_criteria" "localhost_dns" {
44+
resource_definition_id = humanitec_resource_definition.localhost_dns.id
45+
}
46+
47+
# Provide postgres resource
48+
49+
module "postgres_basic" {
50+
# Not pinned as we don't have a release yet
51+
# tflint-ignore: terraform_module_pinned_source
52+
source = "github.com/humanitec-architecture/resource-packs-in-cluster//humanitec-resource-defs/postgres/basic"
53+
prefix = "5min-idp-"
54+
}
55+
56+
resource "humanitec_resource_definition_criteria" "postgres_basic" {
57+
resource_definition_id = module.postgres_basic.id
58+
class = "default"
59+
force_delete = true
60+
}

0 commit comments

Comments
 (0)
Failed to load comments.