From 56cda16dc4a789b505da7ec520c251cff23b2189 Mon Sep 17 00:00:00 2001 From: Ranjith KA Date: Sun, 13 Oct 2024 23:42:30 +0530 Subject: [PATCH] Update the code to run in docker --- .zshrc | 44 +++++++++++++++++++++++++++++++- Dockerfile | 6 ++--- minikube/skaffold/01_skaffold.md | 20 +++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/.zshrc b/.zshrc index 9db21f9..8df9992 100644 --- a/.zshrc +++ b/.zshrc @@ -55,4 +55,46 @@ alias k_svc_all='kubectl get svc --all-namespaces' alias k_svc='kubectl get svc' alias k_ds_po='kube_desc_pod' alias k_login="kdex-fn" -alias k_busybox='kubectl run -i --tty busybox --image=busybox --restart=Never -- /bin/sh; kubectl delete pod busybox' \ No newline at end of file +alias k_busybox='kubectl run -i --tty busybox --image=busybox --restart=Never -- /bin/sh; kubectl delete pod busybox' + +dive_image() { + local IMAGE_NAME="${1}" + local TMP_FILE=/tmp/dive-tmp-image.tar + docker save "$IMAGE_NAME" > $TMP_FILE && dive $TMP_FILE --source=docker-archive && rm $TMP_FILE +} + +# Function to remove all "exited" containers +remove_exited_containers() { + local exited_containers=$(docker ps -a -f status=exited -q) + if [ -n "$exited_containers" ]; then + docker rm $exited_containers + fi +} + +# Function to remove all "created" containers +remove_created_containers() { + local created_containers=$(docker ps -a -f status=created -q) + if [ -n "$created_containers" ]; then + docker rm $created_containers + fi +} + +# Function to remove all stopped containers (both "exited" and "created") +remove_stopped_containers() { + docker container prune -f +} + +# Function to remove all untagged images +remove_untagged_images() { + local untagged_images=$(docker images -f "dangling=true" -q) + if [ -n "$untagged_images" ]; then + docker rmi $untagged_images + fi +} + +cleanup_docker() { + remove_exited_containers + remove_created_containers + remove_stopped_containers + remove_untagged_images +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 05b3e52..81f7e48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23 as builder +FROM golang:1.23-alpine AS builder ARG APP @@ -11,7 +11,7 @@ RUN go mod download # Copy the source from the current directory to the Working Directory inside the container COPY . . -RUN go build . +RUN go build -o Devops main.go FROM alpine:3.14 @@ -39,4 +39,4 @@ COPY --from=builder --chown=user1:user1 /build/Devops /app/ EXPOSE 8080 -ENTRYPOINT ["./Devops"] +ENTRYPOINT ["./Devops", "serve"] diff --git a/minikube/skaffold/01_skaffold.md b/minikube/skaffold/01_skaffold.md index 891b963..6d9e75d 100644 --- a/minikube/skaffold/01_skaffold.md +++ b/minikube/skaffold/01_skaffold.md @@ -14,3 +14,23 @@ It can be used to build, test, and deploy applications. ```bash brew install skaffold ``` + +## skaffold dev + +skaffold dev enables continuous local development on an application. While in dev mode, Skaffold will watch an application’s source files, and when it detects changes, will rebuild your images (or sync files to your running containers), push any new images, test built images, and redeploy the application to your cluster. + +Dev Loop: + +- File sync +- build +- Test +- Deploy + +Skaffold also supports a polling mode where the filesystem is checked for changes on a configurable interval, or a manual mode, where Skaffold waits for user input to check for file changes. These watch modes can be configured through the --trigger flag. + +## Debugging With Skaffold + +### TODO + +- [ ] Add debugging with Skaffold +- [ ] Steps for Golang and .NET Core