Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
**node_modules
config.json
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build:
chmod +x pre-run.sh
./pre-run.sh first_deploy

start:
chmod +x pre-run.sh
./pre-run.sh

clean:
echo Deletes all local Kubernetes cluster. This command deletes the VM, and removes all associated files.
minikube stop
minikube delete --all
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating a minikube profile which allows us to manage multiple minikube instances.
That way we don't terminate other minikube instances (applications running) by executing minikube stop.

minikube start -p docker-infrastructure
minikube profile docker-infrastructure

And perhaps add a stop step, that simply stops the current instance and doesn't delete it.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ docker build -t hakimixx/docker-infra-client:v1 client
docker push hakimixx/docker-infra-client:v1
```

### Minikube
To run the entire application with minikube on mac use:
```shell
make start
```

To clean up run:
```shell
make clean
```

### Terraform
Terraform allows us to manage infrastructure as code (IaC) rather than using a graphical
user interface. It allows us to manage the infrastructure in a safe, consistent and
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/deployments/client-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
spec:
containers:
- name: client
image: hakimixx/docker-infra-client:v1.1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vær opmærksom her

image: hakimixx/docker-infra-client:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
4 changes: 3 additions & 1 deletion kubernetes/deployments/server-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ spec:
spec:
containers:
- name: server
image: hakimixx/docker-infra-server
image: hakimixx/docker-infra-server:latest
ports:
- containerPort: 5000
imagePullPolicy: Always
env:
- name: PORT
value: '5000'
Expand All @@ -37,3 +38,4 @@ spec:
secretKeyRef:
name: pgpassword # name of secret
key: PGPASSWORD # secret key (secret is stored as key-value-pair)

3 changes: 2 additions & 1 deletion kubernetes/deployments/worker-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ spec:
spec:
containers:
- name: worker
image: hakimixx/docker-infra-worker
image: hakimixx/docker-infra-worker:latest
env:
- name: REDIS_HOST
value: redis-cluster-ip-service # name of service here
- name: REDIS_PORT
value: '6379' # default redis port
imagePullPolicy: Always


45 changes: 45 additions & 0 deletions pre-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
CURRENT_PATH=$PWD
eval $(minikube docker-env)
echo $CURRENT_PATH
echo $CURRENT_PATH | rev | cut -d "/" -f1 | rev
Comment on lines +4 to +5
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quote these values

FILES=(client-deployment.yml server-deployment.yml worker-deployment.yml)
PATH_OF_DOCKERFILES=$(echo $CURRENT_PATH | rev | cut -d "/" -f1 | rev)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do?


first_deploy() {
minikube start
minikube addons enable ingress
eval $(minikube docker-env)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quote here as well.
Generally quote everything (unless it's a numerical value) where you do not require the shell to perform word splitting.

kubectl create secret generic pgpassword --from-literal PGPASSWORD=postgres
}

if [[ ! -z "$1" ]]; then first_deploy; fi

docker build -t "$PATH_OF_DOCKERFILES"/docker-infra-client:latest -t "$PATH_OF_DOCKERFILES"/docker-infra-client:latest -f ./client/Dockerfile ./client
docker build -t "$PATH_OF_DOCKERFILES"/docker-infra-server:latest -t "$PATH_OF_DOCKERFILES"/docker-infra-server:latest -f ./server/Dockerfile ./server
docker build -t "$PATH_OF_DOCKERFILES"/docker-infra-worker:latest -t "$PATH_OF_DOCKERFILES"/docker-infra-worker:latest -f ./worker/Dockerfile ./worker

cd $CURRENT_PATH/kubernetes/deployments
# Use local images in minikube - this probably won't work on ubuntu
for key in ${!FILES[@]}; do
sed -i "" "/^\([[:space:]]*imagePullPolicy: \).*/s//\1Never/" ${FILES[${key}]}
done
cd $CURRENT_PATH

./scripts/apply-resources.sh
kubectl rollout restart deployment client-deployment
kubectl rollout restart deployment server-deployment
kubectl rollout restart deployment worker-deployment

cd $CURRENT_PATH/kubernetes/deployments
# Resetting values changed.
for key in ${!FILES[@]}; do
sed -i "" "/^\([[:space:]]*imagePullPolicy: \).*/s//\1Always/" ${FILES[${key}]}
done
cd $CURRENT_PATH
echo
echo
echo
echo sometimes it gets stuck just do ctrl + c on it, do verify by refreshing website.
Comment on lines +40 to +43
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps replace these lines with:

echo $'\nIn case the script is stuck, simply terminate and verify by refreshing the client'

minikube -p minikube docker-env
minikube tunnel