This is an automated email from the ASF dual-hosted git repository.

kamilbregula pushed a commit to branch aip-11
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/aip-11 by this push:
     new e4b43c1  Add cleanup command (#141)
e4b43c1 is described below

commit e4b43c18ae805cf97d88d8047c62795cc8eb0766
Author: Kamil BreguĊ‚a <[email protected]>
AuthorDate: Fri Nov 8 12:35:01 2019 +0100

    Add cleanup command (#141)
---
 site.sh | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/site.sh b/site.sh
index 369ed17..fa8d9c2 100755
--- a/site.sh
+++ b/site.sh
@@ -33,6 +33,7 @@ usage: ${0} <command> [<args>]
 These are  ${0} commands used in various situations:
 
     stop                Stop the environment
+    cleanup             Delete the virtual environment in Docker
     build-image         Build a Docker image with a environment
     install-node-deps   Download all the Node dependencies
     preview             Starts the web server
@@ -221,6 +222,25 @@ function build_site {
 EOF
 }
 
+function cleanup_environment {
+    container_status="$(docker inspect "${CONTAINER_NAME}" --format 
'{{.State.Status}}')"
+    echo "Current container status: ${container_status}"
+    if [[ "${container_status}" == "running" ]]; then
+        echo "Container running. Killing the container."
+        docker kill "${CONTAINER_NAME}"
+    fi
+
+    if [[ $(docker container ls -a --filter="Name=${CONTAINER_NAME}" -q ) ]]; 
then
+        echo "Container exists. Removing the container."
+        docker rm "${CONTAINER_NAME}"
+    fi
+
+    if [[ $(docker images "${IMAGE_NAME}" -q) ]]; then
+        echo "Images exists. Deleeting the image."
+        docker rmi "${IMAGE_NAME}"
+    fi
+}
+
 if [[ "$#" -eq 0 ]]; then
     echo "You must provide at least one command."
     echo
@@ -241,6 +261,10 @@ elif [[ "${CMD}" == "stop" ]] ; then
     prevent_docker
     docker kill "${CONTAINER_NAME}"
     exit 0
+elif [[ "${CMD}" == "cleanup" ]] ; then
+    prevent_docker
+    cleanup_environment
+    exit 0
 elif [[ "${CMD}" == "help" ]]; then
     usage
     exit 0

Reply via email to