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 67a5aa3  Add support for running site.sh in Docker (#112)
67a5aa3 is described below

commit 67a5aa3bfa4d917e088c4a600b8b2bc300650185
Author: Kamil BreguĊ‚a <[email protected]>
AuthorDate: Mon Nov 4 17:10:35 2019 +0100

    Add support for running site.sh in Docker (#112)
---
 site.sh | 51 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 9 deletions(-)

diff --git a/site.sh b/site.sh
index ae5a4b3..98e5916 100755
--- a/site.sh
+++ b/site.sh
@@ -48,6 +48,9 @@ can execute the following command:
 
     $0 ls
 
+The following command can also be performed from the Docker environment:
+install-node-deps, preview, build-site, lint-css, lint-js.
+
 EOF
 }
 
@@ -84,7 +87,7 @@ function ensure_container_running {
 function ensure_node_module_exists {
     if [[ ! -d landing-pages/node_modules/ ]] ; then
         echo "Missing node dependencies. Start installation."
-        docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" yarn 
install
+        run_command "/opt/site/landing-pages/" yarn install
         echo "Dependencies installed."
     fi
 }
@@ -95,6 +98,34 @@ function build_image {
     echo "End building image"
 }
 
+function run_command {
+    working_directory=$1
+    shift
+    if [[ -f /.dockerenv ]] ; then
+        echo "Native command"
+        pushd "${working_directory}"
+        exec "$@"
+    else
+        echo "Docker command"
+        docker exec -w "${working_directory}" "${CONTAINER_NAME}" "$@"
+    fi
+}
+
+function prepare_environment {
+    if [[ ! -f /.dockerenv ]] ; then
+        ensure_image_exists
+        ensure_container_exists
+        ensure_container_running
+    fi
+}
+
+function prevent_docker {
+    if [[ -f /.dockerenv ]] ; then
+        echo "This command is not supported in the Docker environment. Run 
this command from the host system."
+        exit 1
+    fi
+}
+
 if [[ "$#" -eq 0 ]]; then
     echo "You must provide at least one command."
     echo
@@ -108,9 +139,11 @@ shift
 
 # Check fundamentals commands
 if [[ "${CMD}" == "build-image" ]] ; then
+    prevent_docker
     build_image
     exit 0
 elif [[ "${CMD}" == "stop" ]] ; then
+    prevent_docker
     docker kill "${CONTAINER_NAME}"
     exit 0
 elif [[ "${CMD}" == "help" ]]; then
@@ -118,28 +151,28 @@ elif [[ "${CMD}" == "help" ]]; then
     exit 0
 fi
 
-ensure_image_exists
-ensure_container_exists
-ensure_container_running
+prepare_environment
 
 # Check container commands
 if [[ "${CMD}" == "install-node-deps" ]] ; then
-    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" yarn install
+    run_command "/opt/site/landing-pages/" yarn install
 elif [[ "${CMD}" == "preview" ]]; then
     ensure_node_module_exists
-    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run 
preview
+    run_command "/opt/site/landing-pages/" npm run preview
 elif [[ "${CMD}" == "build-site" ]]; then
     ensure_node_module_exists
-    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run build
+    run_command "/opt/site/landing-pages/" npm run build
 elif [[ "${CMD}" == "lint-js" ]]; then
     ensure_node_module_exists
-    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run 
lint:js
+    run_command "/opt/site/landing-pages/" npm run lint:js
 elif [[ "${CMD}" == "lint-css" ]]; then
     ensure_node_module_exists
-    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run 
lint:css
+    run_command "/opt/site/landing-pages/" npm run lint:css
 elif [[ "${CMD}" == "shell" ]]; then
+    prevent_docker
     docker exec -ti "${CONTAINER_NAME}" bash
 else
+    prevent_docker
     docker exec -ti "${CONTAINER_NAME}" "${CMD}" "$@"
 fi
 

Reply via email to