Skip to content

Instantly share code, notes, and snippets.

@mathieu-benoit
Last active October 25, 2024 11:33
Show Gist options
  • Save mathieu-benoit/f72516de0be5c50d6535328a6ecdc299 to your computer and use it in GitHub Desktop.
Save mathieu-benoit/f72516de0be5c50d6535328a6ecdc299 to your computer and use it in GitHub Desktop.
humctl-dev-demo
#!/bin/bash
# setup
if [ ! -f demo-magic.sh ]; then
curl -LO https://github.com/paxtonhare/demo-magic/raw/master/demo-magic.sh
fi
. demo-magic.sh -d #-n
clear
# demo cleanup
rm score.yaml
humctl delete env ephemeral && true
humctl delete value MESSAGE && true
# Also, delete and recreate the App, as Admin or Manager
clear
# demo
HUMANITEC_ENV=development
humctl config set org ${HUMANITEC_ORG}
clear
pe "humctl version"
pe "humctl config set app ${HUMANITEC_APP}"
pe "humctl config set env ${HUMANITEC_ENV}"
pe "humctl login"
clear
pe "humctl get apps"
pe "humctl get envs" # TODO: add in the tutorial
pei "clear && echo \"### 1/5 use case: Deploy a sample Workload.\""
cat <<EOF > score.yaml
apiVersion: score.dev/v1b1
metadata:
name: my-workload
containers:
my-container:
image: .
EOF
# Show the Score file in VS Code
pe "humctl score validate score.yaml" # TODO: add in the tutorial
pe "humctl score deploy -f score.yaml --image ghcr.io/mathieu-benoit/my-sample-workload:latest --message \"Initial deployment\"" # TODO: which container image to use here by default? Yes, customer should have their own, but let's propose a working example.
pe "humctl get deploy ."
pe "echo 'See Deployment in Humanitec Portal:'"
echo "https://app.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/envs/${HUMANITEC_ENV}/status"
pe "humctl get active-resources"
# Add a variable
pei "clear && echo \"### 2/5 use case: Add a variable.\""
pe "humctl create value MESSAGE \"Hello, Humanitec!\" --env \"\""
cat <<EOF > score.yaml
apiVersion: score.dev/v1b1
metadata:
name: my-workload
containers:
my-container:
image: .
variables:
MESSAGE: \${resources.env.MESSAGE}
resources:
env:
type: environment
EOF
# Show the Score file in VS Code
pe "humctl score validate score.yaml" # TODO: add in the tutorial
pe "humctl score deploy -f score.yaml --image ghcr.io/mathieu-benoit/my-sample-workload:latest --message \"Add a container variable\""
pe "humctl get deploy ."
pe "humctl diff sets deploy/+0 deploy/+1"
pe "echo 'See Deployment in Humanitec Portal:'"
echo "https://app.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/envs/${HUMANITEC_ENV}/status"
pe "humctl get active-resources"
# Add a resource
pei "clear && echo \"### 3/5 use case: Deploy a Redis database resource.\""
pe "humctl score available-resource-types" # TODO: add in the tutorial
pe "humctl score available-resource-types --filter-type redis -o yaml" # TODO: add in the tutorial
cat <<EOF > score.yaml
apiVersion: score.dev/v1b1
metadata:
name: my-workload
containers:
my-container:
image: .
variables:
MESSAGE: \${resources.env.MESSAGE}
REDIS_HOST: \${resources.my-cache.host}
REDIS_PORT: \${resources.my-cache.port}
REDIS_USERNAME: \${resources.my-cache.username}
REDIS_PASSWORD: \${resources.my-cache.password}
resources:
env:
type: environment
my-cache:
type: redis
EOF
# Show the Score file in VS Code
pe "humctl score validate score.yaml" # TODO: add in the tutorial
pe "humctl score deploy -f score.yaml --image ghcr.io/mathieu-benoit/my-sample-workload:latest --message \"Add a Redis resource\""
pe "humctl get deploy ."
pe "humctl diff sets deploy/+0 deploy/+1"
pe "echo 'See Deployment in Humanitec Portal:'"
echo "https://app.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/envs/${HUMANITEC_ENV}/status"
pe "humctl get active-resources"
# Create Ephemeral Env
pei "clear && echo \"### 4/5 use case: Create an Ephemeral Env with new variable value and a DNS resource.\""
export HUMANITEC_EPH_ENV=ephemeral
pe "humctl create env ${HUMANITEC_EPH_ENV} -t development"
pe "humctl get envs"
pe "humctl create value MESSAGE \"Hello, Ephemeral Environment!\" --env ${HUMANITEC_EPH_ENV}"
pe "humctl score available-resource-types --filter-type dns -o yaml" # TODO: add in the tutorial
cat <<EOF > score.yaml
apiVersion: score.dev/v1b1
metadata:
name: my-workload
containers:
my-container:
image: .
variables:
MESSAGE: \${resources.env.MESSAGE}
REDIS_HOST: \${resources.my-cache.host}
REDIS_PORT: \${resources.my-cache.port}
REDIS_USERNAME: \${resources.my-cache.username}
REDIS_PASSWORD: \${resources.my-cache.password}
resources:
env:
type: environment
my-cache:
type: redis
my-dns:
type: dns
my-route:
type: route
params:
host: \${resources.my-dns.host}
path: /
port: 8080
service:
ports:
tcp:
port: 8080
targetPort: 8080
EOF
# Show the Score file in VS Code
pe "humctl score validate score.yaml" # TODO: add in the tutorial
pe "humctl score deploy -f score.yaml --image ghcr.io/mathieu-benoit/my-sample-workload:latest --message \"Add a DNS resource\" --env ${HUMANITEC_EPH_ENV}"
pe "humctl get deploy . --env ${HUMANITEC_EPH_ENV}"
pe "humctl diff sets env/${HUMANITEC_EPH_ENV} env/${HUMANITEC_ENV}"
pe "echo 'See Deployment in Humanitec Portal:'"
echo "https://app.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/envs/${HUMANITEC_EPH_ENV}/status"
pe "humctl get active-resources --env ${HUMANITEC_EPH_ENV}"
# Delete Ephemeral Env
pei "clear && echo \"### 5/5 use case: Delete Ephemeral Env and deploy new updates in Development Env.\""
pe "humctl delete env ${HUMANITEC_EPH_ENV}"
pe "humctl get envs"
pe "humctl score deploy -f score.yaml --image ghcr.io/mathieu-benoit/my-sample-workload:latest --message \"Add a DNS resource\""
pe "humctl get deploy ."
pe "humctl diff sets deploy/+0 deploy/+1"
pe "echo 'See Deployment in Humanitec Portal:'"
echo "https://app.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/envs/${HUMANITEC_ENV}/status"
pe "humctl get active-resources"
pei "echo \"### End of the demo.\""
@mathieu-benoit
Copy link
Author

mathieu-benoit commented Oct 23, 2024

curl -L0 https://gist.githubusercontent.com/mathieu-benoit/f72516de0be5c50d6535328a6ecdc299/raw/eb5b80aedba2a4c96edb308f29579cc82746b12a/humctl-dev-demo.sh -o humctl-dev-demo.sh

chmod +x humctl-dev-demo.sh

export HUMANITEC_ORG=FIXME
export HUMANITEC_APP=FIXME

# Open VS Code to show the score.yaml and have a terminal in there too:
code .

./humctl-dev-demo.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment