Browse Source

updated backend run.sh

develop
Robin Thoni 7 years ago
parent
commit
f62340a488
4 changed files with 54 additions and 26 deletions
  1. 10
    2
      backend/Dockerfile
  2. 41
    0
      backend/common.sh
  3. 1
    23
      backend/run.sh
  4. 2
    1
      backend/vars-files

+ 10
- 2
backend/Dockerfile View File

@@ -1,25 +1,33 @@
1 1
 FROM microsoft/dotnet:1.0.3-sdk-projectjson
2 2
 
3
+ARG CONFIG_DIR=/etc/default/config-files/
4
+
3 5
 RUN rm -rf /var/log/*
4 6
 
5 7
 COPY ./backend/ /tmp/backend/
6 8
 
7 9
 ARG WEBAPI_PROJECT=WebApi
8 10
 ARG BUILD_CONFIG=Release
11
+ARG CONFIG_DIR=/etc/default/config-files/
9 12
 
10 13
 RUN echo "Building ${WEBAPI_PROJECT} in ${BUILD_CONFIG} configuration" && \
11 14
     cd /tmp/backend && \
12 15
     dotnet restore && \
13 16
     mkdir /var/www && \
14 17
     cd /tmp/backend/${WEBAPI_PROJECT} && \
15
-    dotnet publish --configuration "${BUILD_CONFIG}" --output /var/www && \
16
-    ln -s /var/www/${WEBAPI_PROJECT}.dll /var/www/__RUN_ME.DLL &&\
18
+    dotnet publish --configuration "${BUILD_CONFIG}" --output /var/www
19
+
20
+RUN ln -s /var/www/${WEBAPI_PROJECT}.dll /var/www/__RUN_ME.DLL &&\
21
+    mkdir "${CONFIG_DIR}" &&\
22
+    cp /tmp/backend/${WEBAPI_PROJECT}/appsettings.* "${CONFIG_DIR}" &&\
17 23
     rm /tmp/backend -rf
18 24
 
19 25
 COPY ./vars-vars /etc/vars-vars
20 26
 
21 27
 COPY ./vars-files /etc/vars-files
22 28
 
29
+COPY ./common.sh /common.sh
30
+
23 31
 COPY ./run.sh /run.sh
24 32
 
25 33
 EXPOSE 80

+ 41
- 0
backend/common.sh View File

@@ -0,0 +1,41 @@
1
+export CONFIG_DIR="/etc/default/config-files/"
2
+
3
+resolv_host()
4
+{
5
+  hostname="${1}"
6
+  ip=$(getent hosts "${hostname}" | cut -d' ' -f1)
7
+  echo "${ip}"
8
+}
9
+
10
+replace_var()
11
+{
12
+  file="${1}"
13
+  var="${2}"
14
+  sed -e "s?${var}?${!var}?g" -i "${file}"
15
+}
16
+
17
+replace_vars()
18
+{
19
+  file="${1}"
20
+  for var in $(cat /etc/vars-vars)
21
+  do
22
+    replace_var "${file}" "${var}"
23
+  done
24
+}
25
+
26
+replace_files()
27
+{
28
+  cat /etc/vars-files | while read line
29
+  do
30
+    filesrc="${CONFIG_DIR}$(echo "${line}" | awk '{print $1}')"
31
+    filedst=$(echo "${line}" | awk '{print $2}')
32
+    if [ -f "${filesrc}" ]
33
+    then
34
+      echo "Expanding file ${filesrc} to ${filedst}"
35
+      cp "${filesrc}" "${filedst}"
36
+      replace_vars "${filedst}"
37
+    else
38
+      echo "File ${filesrc} does not exist. Skipping."
39
+    fi
40
+  done
41
+}

+ 1
- 23
backend/run.sh View File

@@ -1,28 +1,6 @@
1 1
 #! /usr/bin/env bash
2 2
 
3
-replace_var()
4
-{
5
-  file="${1}"
6
-  var="${2}"
7
-  sed -e "s?${var}?${!var}?g" -i "${file}"
8
-}
9
-
10
-replace_vars()
11
-{
12
-  file="${1}"
13
-  for var in $(cat /etc/vars-vars)
14
-  do
15
-    replace_var "${file}" "${var}"
16
-  done
17
-}
18
-
19
-replace_files()
20
-{
21
-  for file in $(cat /etc/vars-files)
22
-  do
23
-    replace_vars "${file}"
24
-  done
25
-}
3
+. /common.sh
26 4
 
27 5
 replace_files
28 6
 

+ 2
- 1
backend/vars-files View File

@@ -1 +1,2 @@
1
-/var/www/appsettings.json
1
+appsettings.json /var/www/appsettings.json
2
+appsettings.dockerDevelopment.json /var/www/appsettings.Development.json

Loading…
Cancel
Save