Skip to content

Commit

Permalink
Merge pull request #107 from phudtran/local-docker-dev
Browse files Browse the repository at this point in the history
Adjusted docker push/pull workflow for local dev
  • Loading branch information
zasherif authored Apr 2, 2020
2 parents 836fc72 + 99c8d86 commit 60c585f
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 26 deletions.
59 changes: 59 additions & 0 deletions install/create_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

KINDCONF=${1:-"${HOME}/mizar/build/tests/kind/config"}
USER=${2:-dev}

# create registry container unless it already exists
reg_name='local-kind-registry'
reg_port='5000'
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
reg_ip="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' "${reg_name}")"

if [[ $USER == "dev" ]]; then
PATCH="containerdConfigPatches:
- |-
[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"localhost:${reg_port}\"]
endpoint = [\"http://${reg_ip}:${reg_port}\"]"
REPO="localhost:5000"
else
PATCH=""
REPO="fwnetworking"
fi

# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --name kind --kubeconfig ${KINDCONF} --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
${PATCH}
nodes:
- role: control-plane
image: ${REPO}/kindnode:latest
extraMounts:
- hostPath: .
containerPath: /var/mizar
- role: worker
image: ${REPO}/kindnode:latest
extraMounts:
- hostPath: .
containerPath: /var/mizar
- role: worker
image: ${REPO}/kindnode:latest
extraMounts:
- hostPath: .
containerPath: /var/mizar
- role: worker
image: ${REPO}/kindnode:latest
extraMounts:
- hostPath: .
containerPath: /var/mizar
- role: worker
image: ${REPO}/kindnode:latest
extraMounts:
- hostPath: .
containerPath: /var/mizar
EOF
14 changes: 7 additions & 7 deletions install/create_crds.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
USER=${2:-dev}

# Create the CRDs
kubectl delete bouncers.mizar.com --all
kubectl delete dividers.mizar.com --all
kubectl delete droplets.mizar.com --all
kubectl delete endpoints.mizar.com --all
kubectl delete nets.mizar.com --all
kubectl delete vpcs.mizar.com --all
kubectl delete bouncers.mizar.com --all 2> /tmp/kubetctl.err
kubectl delete dividers.mizar.com --all 2> /tmp/kubetctl.err
kubectl delete droplets.mizar.com --all 2> /tmp/kubetctl.err
kubectl delete endpoints.mizar.com --all 2> /tmp/kubetctl.err
kubectl delete nets.mizar.com --all 2> /tmp/kubetctl.err
kubectl delete vpcs.mizar.com --all 2> /tmp/kubetctl.err

kubectl apply -f $DIR/mgmt/etc/crds/bouncers.crd.yaml
kubectl apply -f $DIR/mgmt/etc/crds/dividers.crd.yaml
Expand Down
2 changes: 1 addition & 1 deletion install/create_service_account.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
USER=${2:-dev}

# Create the service account
kubectl apply -f $DIR/mgmt/etc/account/serviceaccount.yaml
Expand Down
4 changes: 2 additions & 2 deletions install/create_testimage.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
DOCKER_ACC=${3:-fwnetworking}
USER=${2:-dev}
DOCKER_ACC=${3:-"localhost:5000"}

# Build the daemon image
docker image build -t $DOCKER_ACC/testpod:latest -f $DIR/mgmt/etc/docker/test.Dockerfile $DIR
Expand Down
16 changes: 11 additions & 5 deletions install/deploy_daemon.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
DOCKER_ACC=${3:-fwnetworking}
USER=${2:-dev}
DOCKER_ACC=${3:-"localhost:5000"}
YAML_FILE="dev.daemon.deploy.yaml"

if [[ "$USER" == "user" || "$USER" == "final" ]]; then
DOCKER_ACC="fwnetworking"
YAML_FILE="daemon.deploy.yaml"
fi

# Build the daemon image
docker image build -t $DOCKER_ACC/dropletd:latest -f $DIR/mgmt/etc/docker/daemon.Dockerfile $DIR
if [[ "$USER" == "dev" ]]; then
if [[ "$USER" == "dev" || "$USER" == "final" ]]; then
docker image push $DOCKER_ACC/dropletd:latest
fi

# Delete existing deployment and deploy
kubectl delete daemonset.apps/mizar-daemon
kubectl apply -f $DIR/mgmt/etc/deploy/daemon.deploy.yaml
kubectl delete daemonset.apps/mizar-daemon 2> /tmp/kubetctl.err
kubectl apply -f $DIR/mgmt/etc/deploy/$YAML_FILE
16 changes: 11 additions & 5 deletions install/deploy_operator.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
DOCKER_ACC=${3:-fwnetworking}
USER=${2:-dev}
DOCKER_ACC=${3:-"localhost:5000"}
YAML_FILE="dev.operator.deploy.yaml"

if [[ "$USER" == "user" || "$USER" == "final" ]]; then
DOCKER_ACC="fwnetworking"
YAML_FILE="operator.deploy.yaml"
fi

# Build the operator image
docker image build -t $DOCKER_ACC/endpointopr:latest -f $DIR/mgmt/etc/docker/operator.Dockerfile $DIR
if [[ "$USER" == "dev" ]]; then
if [[ "$USER" == "dev" || "$USER" == "final" ]]; then
docker image push $DOCKER_ACC/endpointopr:latest
fi

# Delete existing deployment and deploy
kubectl delete deployment.apps/mizar-operator
kubectl apply -f $DIR/mgmt/etc/deploy/operator.deploy.yaml
kubectl delete deployment.apps/mizar-operator 2> /tmp/kubetctl.err
kubectl apply -f $DIR/mgmt/etc/deploy/$YAML_FILE
2 changes: 1 addition & 1 deletion install/disable_kubeproxy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DIR=${1:-.}
USER=${2:-user}
USER=${2:-dev}

kubectl delete daemonsets -n kube-system kube-proxy
3 changes: 0 additions & 3 deletions k8s/kind/setup.sh

This file was deleted.

8 changes: 6 additions & 2 deletions kind-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ KINDCONF="${HOME}/mizar/build/tests/kind/config"
MIZARCONF="${HOME}/mizar/build/tests/mizarcni.config"
KINDHOME="${HOME}/.kube/config"
USER=${1:-user}
DOCKER_ACC=${2:-fwnetworking}

kind delete cluster

if [[ "$USER" == "dev" ]]; then
DOCKER_ACC="localhost:5000"
else
DOCKER_ACC="fwnetworking"
fi
docker image build -t $DOCKER_ACC/kindnode:latest -f k8s/kind/Dockerfile .

kind create cluster --config k8s/kind/cluster.yaml --kubeconfig $KINDCONF
source install/create_cluster.sh $KINDCONF $USER

api_ip=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kind-control-plane`
sed "s/server: https:\/\/127.0.0.1:[[:digit:]]\+/server: https:\/\/$api_ip:6443/" $KINDCONF > $MIZARCONF
Expand Down
31 changes: 31 additions & 0 deletions mgmt/etc/deploy/dev.daemon.deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: mizar-daemon
namespace: default
spec:
selector:
matchLabels:
job: mizar-daemon
template:
metadata:
labels:
job: mizar-daemon
spec:
serviceAccountName: mizar-operator
hostNetwork: true
hostPID: true
volumes:
- name: mizar
hostPath:
path: /home
type: Directory
containers:
- image: localhost:5000/dropletd:latest
name: mizar-daemon
securityContext:
privileged: true
volumeMounts:
- name: mizar
mountPath: /mizar
22 changes: 22 additions & 0 deletions mgmt/etc/deploy/dev.operator.deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mizar-operator
spec:
replicas: 1
selector:
matchLabels:
app: mizar-operator
template:
metadata:
labels:
app: mizar-operator
mizar: operator
spec:
serviceAccountName: mizar-operator
hostNetwork: true
containers:
- image: localhost:5000/endpointopr:latest
name: mizar-operator
securityContext:
privileged: true

0 comments on commit 60c585f

Please sign in to comment.