Skip to content

Commit

Permalink
updated GitOps lab (#83)
Browse files Browse the repository at this point in the history
* added ds deploy command
* added comments to scripts
  • Loading branch information
bartr authored May 18, 2023
1 parent ac2de79 commit 7f57a9e
Show file tree
Hide file tree
Showing 92 changed files with 1,802 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .ds/commands/applications/list
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds applications list" queries the Res-Edge data service and displays a list of Applications

KIC_RES_EDGE_ENTITYNAME="applications" "$CLI_CMD_DIR/res-edge/entity-list" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/applications/show
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds applications show --id <id>" displays a json object from the Res-Edge data service

KIC_RES_EDGE_ENTITYNAME="applications" "$CLI_CMD_DIR/res-edge/entity-show" "$@"
57 changes: 7 additions & 50 deletions .ds/commands/cicd
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
#!/bin/bash

RESEDGE_AUTOMATION_DOCKER_IMAGE="ghcr.io/cse-labs/res-edge-automation:0.9"
# "ds cicd" use the Res-Edge Automation docker image and the Res-Edge Data Service
# to generate GitOps manifest files for each Cluster

usage() {
echo "Usage: kic cicd [--show]"
exit 1
}
# Run "git status" to see the repo changes

# check the number of parameters
if [ $# -gt 1 ]; then
usage
fi

# extract the first parameter into a variable
param="$1"

# check if the parameter is valid
if [ $# -eq 1 ]; then
if [[ $param == "--show" ]]; then
show_flag=1
else
usage
fi
fi

# If the flag is set, show a message
if [[ $show_flag -eq 1 ]]; then
cat << EOF
Default Script
#!/bin/bash
# The following command will execute the ghcr.io/cse-labs/res-edge-automation image in docker
# and will mount the current directory into a working directory inside the container.
# The container will retrieve all required information from the dataservice
# and validate, create and/or update (as necessary) the clusters gitops manifest files
# in the working directory without pushing changes to remote repository.
docker run -it --rm \\
--net host \\
-v \$(pwd):/goa \\
${RESEDGE_AUTOMATION_DOCKER_IMAGE} \\
-s "${DS_URL}"
EOF
exit
fi
# The changes are not pushed to GitHub
# use "ds deploy" to push any GitOps changes

echo "Running ci-cd locally ..."

# The following command will execute the ghcr.io/cse-labs/res-edge-automation image in docker
# and will mount the current directory into a working directory inside the container.
# The container will retrieve all required information from the dataservice
# and validate, create and/or update (as necessary) the clusters gitops manifest files
# in the working directory without pushing changes to remote repository.
docker run -it --rm \
--net host \
-v "$(pwd)":/goa \
${RESEDGE_AUTOMATION_DOCKER_IMAGE} \
-v "$KIC_BASE":/goa \
ghcr.io/cse-labs/res-edge-automation:0.9 \
-s "${DS_URL}"
2 changes: 2 additions & 0 deletions .ds/commands/clusters/list
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds clusters list" queries the Res-Edge data service and displays a list of Clusters

KIC_RES_EDGE_ENTITYNAME="clusters" "$CLI_CMD_DIR/res-edge/entity-list" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/clusters/show
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds clusters show --id <id>" displays a json object from the Res-Edge data service

KIC_RES_EDGE_ENTITYNAME="clusters" "$CLI_CMD_DIR/res-edge/entity-show" "$@"
14 changes: 14 additions & 0 deletions .ds/commands/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# "ds cicd" uses Res-Edge Automation to update the Cluster manifests in the "clusters" directory
# "ds deploy" will commit and push any changes to the "clusters" directory tree to GitHub
# It will not push changes outside the clusters directory

if [[ $(git status "$KIC_BASE/clusters" --porcelain | wc -l ) = 0 ]]; then
echo "No updates to deploy"
exit 0
fi

git add "$KIC_BASE/clusters"
git commit -m "Res-Edge Automation via ds cicd"
git push
4 changes: 3 additions & 1 deletion .ds/commands/env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

env | grep -e "^DS_" -e "^CLI_" -e "^KIC_" | sort
# "ds env" will display a sorted list of environment variables used by the CLIs

env | grep -e "^CLI_" -e "^DS_" -e "^KIC_" | sort
2 changes: 2 additions & 0 deletions .ds/commands/groups/list
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds groups list" queries the Res-Edge data service and displays a list of Groups

KIC_RES_EDGE_ENTITYNAME="groups" "$CLI_CMD_DIR/res-edge/entity-list" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/groups/show
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds groups show --id <id>" displays a json object from the Res-Edge data service

KIC_RES_EDGE_ENTITYNAME="groups" "$CLI_CMD_DIR/res-edge/entity-show" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/namespaces/list
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds namespaces list" queries the Res-Edge data service and displays a list of Namespaces

KIC_RES_EDGE_ENTITYNAME="namespaces" "$CLI_CMD_DIR/res-edge/entity-list" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/namespaces/show
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds namespaces show --id <id>" displays a json object from the Res-Edge data service

KIC_RES_EDGE_ENTITYNAME="namespaces" "$CLI_CMD_DIR/res-edge/entity-show" "$@"
3 changes: 3 additions & 0 deletions .ds/commands/overlay
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# "ds overlay <name> <version>" will create a new Kustomize overlay for the application
# The overlay will set the new version to <version>

set -e

dir=""
Expand Down
2 changes: 2 additions & 0 deletions .ds/commands/policies/list
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds policies list" queries the Res-Edge data service and displays a list of Policies

KIC_RES_EDGE_ENTITYNAME="policies" "$CLI_CMD_DIR/res-edge/entity-list" "$@"
2 changes: 2 additions & 0 deletions .ds/commands/policies/show
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# "ds policies show --id <id>" displays a json object from the Res-Edge data service

KIC_RES_EDGE_ENTITYNAME="policies" "$CLI_CMD_DIR/res-edge/entity-show" "$@"
8 changes: 7 additions & 1 deletion .ds/commands/reload
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

# Warning: this is a destructive command

# "ds reload" will reload the SQL database with the default sample data
# Any prior database changes will be overwritten and are not recoverable
# Use the --force flag to make the database changes

# get the pod name
pod=$(kic pods | grep mssql | awk '{print $2}')

Expand All @@ -18,5 +24,5 @@ if [ "$1" != "--force" ]; then
exit 1
fi

# execute the load script
# execute the load script "in" the pod
kubectl exec -n api "$pod" -- /home/mssql/5/load.sh
4 changes: 4 additions & 0 deletions .ds/root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ scriptCommands:
- name: reload
short: Reload the SQL database with default sample data (Destructive!)
path: reload

- name: deploy
short: Deploy the Res-Edge Automation changes to clusters
path: deploy
4 changes: 3 additions & 1 deletion .kic/commands/env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

env | grep -e "^DS_" -e "^CLI_" -e "^KIC_" | sort
# "kic env" will display a sorted list of environment variables used by the CLIs

env | grep -e "^CLI_" -e "^DS_" -e "^KIC_" | sort
3 changes: 3 additions & 0 deletions .kic/commands/sync
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

# "kic sync" runs an immediate "Flux reconcile"
# This improves debugging as you don't have to wait for the scheduled flux reconcile to run

flux reconcile source git gitops
5 changes: 5 additions & 0 deletions apps/flux-system/source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ spec:
interval: 1m0s
secretRef:
name: flux-system

# update these values to your repo and branch
# run "ds cicd" to update the Cluster manifests
# run "ds deploy" to push the GitOps changes to GitHub

url: https://github.com/cse-labs/res-edge-labs
ref:
branch: main
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: imdb
namespace: flux-system
spec:
interval: 1m0s
path: ./clusters/central-la-nola-2301/imdb
prune: true
sourceRef:
kind: GitRepository
name: gitops
7 changes: 6 additions & 1 deletion clusters/central-la-nola-2301/flux-system/source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ spec:
interval: 1m0s
secretRef:
name: flux-system

# update these values to your repo and branch
# run "ds cicd" to update the Cluster manifests
# run "ds deploy" to push the GitOps changes to GitHub

url: https://github.com/cse-labs/res-edge-labs
ref:
branch: gitops-lab
branch: main
73 changes: 73 additions & 0 deletions clusters/central-la-nola-2301/imdb/imdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: v1
kind: Service
metadata:
name: imdb
namespace: imdb
spec:
ports:
- name: http
nodePort: 31080
port: 8080
protocol: TCP
targetPort: http
selector:
app: imdb
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: imdb
name: imdb
namespace: imdb
spec:
replicas: 1
selector:
matchLabels:
app: imdb
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: imdb
spec:
containers:
- args:
- --in-memory
- --region
- central
- --zone
- central-la
image: ghcr.io/cse-labs/imdb:1.0.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 10
httpGet:
path: /healthz
port: http
initialDelaySeconds: 5
periodSeconds: 60
name: app
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
failureThreshold: 10
httpGet:
path: /readyz
port: http
initialDelaySeconds: 5
periodSeconds: 60
resources:
limits:
cpu: 1000m
memory: 2048Mi
requests:
cpu: 500m
memory: 1024Mi
4 changes: 4 additions & 0 deletions clusters/central-la-nola-2301/namespaces/imdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: imdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: imdb
namespace: flux-system
spec:
interval: 1m0s
path: ./clusters/central-la-nola-2302/imdb
prune: true
sourceRef:
kind: GitRepository
name: gitops
7 changes: 6 additions & 1 deletion clusters/central-la-nola-2302/flux-system/source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ spec:
interval: 1m0s
secretRef:
name: flux-system

# update these values to your repo and branch
# run "ds cicd" to update the Cluster manifests
# run "ds deploy" to push the GitOps changes to GitHub

url: https://github.com/cse-labs/res-edge-labs
ref:
branch: gitops-lab
branch: main
Loading

0 comments on commit 7f57a9e

Please sign in to comment.