From 5325d1a3a15e9d66e6582b765860035e16a8b42e Mon Sep 17 00:00:00 2001 From: Francesco Ranieri Date: Tue, 29 Nov 2022 19:10:21 +0100 Subject: [PATCH 1/3] feat: dockerize FE --- frontend/.dockerignore | 4 ++++ frontend/Dockerfile | 8 ++++++++ frontend/docker-compose.yaml | 11 +++++++++++ frontend/package.json | 11 ++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile create mode 100644 frontend/docker-compose.yaml diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..b416029 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.git +.gitignore +dist \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..459cbf9 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,8 @@ +FROM node:19.1.0-alpine +WORKDIR '/app' + +COPY package.json . +RUN npm install +COPY . . +EXPOSE 4200 +CMD ["npm", "start"] \ No newline at end of file diff --git a/frontend/docker-compose.yaml b/frontend/docker-compose.yaml new file mode 100644 index 0000000..3f94ffb --- /dev/null +++ b/frontend/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3' +services: + web: + build: + context: . + dockerfile: Dockerfile + ports: + - "4200:4200" + volumes: + - /fronted/node_modules + - .:/fronted \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 2afa3cc..8fcaf54 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -2,11 +2,12 @@ "name": "frontend", "version": "0.0.0", "scripts": { - "ng": "ng", - "start": "ng serve", - "build": "ng build", - "watch": "ng build --watch --configuration development", - "test": "ng test" + "ng": "ng", + "start": "npx ng serve --host 0.0.0.0 --poll=500", + "build": "npx ng build --prod demo", + "test": "npx ng test --browsers=ChromeHeadless", + "lint": "npx ng lint", + "e2e": "npx ng e2e" }, "private": true, "dependencies": { From a8548d847e9a8dba411f5150ae968d18f0eee172 Mon Sep 17 00:00:00 2001 From: Francesco Ranieri Date: Tue, 29 Nov 2022 21:04:31 +0100 Subject: [PATCH 2/3] WIP --- backend/Dockerfile | 17 ++++ backend/docker-compose.yaml | 12 ++- backend/requirements.txt | 4 +- backend/wait-for.sh | 191 ++++++++++++++++++++++++++++++++++++ 4 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 backend/Dockerfile create mode 100644 backend/wait-for.sh diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..ac7f6db --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.10.8-alpine + WORKDIR /backend/controllers + ENV FLASK_APP=app.py + ENV FLASK_RUN_HOST=0.0.0.0 + RUN apk add --no-cache gcc musl-dev linux-headers + RUN pip install -r requirements.txt + COPY requirements.txt requirements.txt + RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \ + unzip instantclient-basiclite-linuxx64.zip && \ + rm -f instantclient-basiclite-linuxx64.zip && \ + cd instantclient* && \ + rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci && \ + echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && \ + ldconfig + EXPOSE 5000 + COPY . . + CMD ["flask", "run"] \ No newline at end of file diff --git a/backend/docker-compose.yaml b/backend/docker-compose.yaml index 05db528..e9ba434 100644 --- a/backend/docker-compose.yaml +++ b/backend/docker-compose.yaml @@ -10,7 +10,17 @@ services: environment: - ORACLE_SID:ORCLCDB - ORACLE_PWD:password - + + flask: + build: . + ports: + - "5000:5000" + volumes: + - .:/backend + depends_on: + - oracle + command: ["../wait-for.sh", "oracle:1521", "--", "python", "app.py"] + volumes: desktop_oracle-volume: external: true diff --git a/backend/requirements.txt b/backend/requirements.txt index baf38e6..e543ee1 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,3 +1,3 @@ -cx-Oracle=8.3.0 +cx-Oracle==8.3.0 Flask~=2.2.2 -Flask-Cors=3.0.10 \ No newline at end of file +Flask-Cors==3.0.10 \ No newline at end of file diff --git a/backend/wait-for.sh b/backend/wait-for.sh new file mode 100644 index 0000000..eae37dd --- /dev/null +++ b/backend/wait-for.sh @@ -0,0 +1,191 @@ +#!/bin/sh + +# The MIT License (MIT) +# +# Copyright (c) 2017 Eficode Oy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +VERSION="2.2.3" + +set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result" +TIMEOUT=15 +QUIET=0 +# The protocol to make the request with, either "tcp" or "http" +PROTOCOL="tcp" + +echoerr() { + if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi +} + +usage() { + exitcode="$1" + cat << USAGE >&2 +Usage: + $0 host:port|url [-t timeout] [-- command args] + -q | --quiet Do not output any status messages + -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout + -v | --version Show the version of this tool + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit "$exitcode" +} + +wait_for() { + case "$PROTOCOL" in + tcp) + if ! command -v nc >/dev/null; then + echoerr 'nc command is missing!' + exit 1 + fi + ;; + http) + if ! command -v wget >/dev/null; then + echoerr 'wget command is missing!' + exit 1 + fi + ;; + esac + + TIMEOUT_END=$(($(date +%s) + TIMEOUT)) + + while :; do + case "$PROTOCOL" in + tcp) + nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1 + ;; + http) + wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1 + ;; + *) + echoerr "Unknown protocol '$PROTOCOL'" + exit 1 + ;; + esac + + result=$? + + if [ $result -eq 0 ] ; then + if [ $# -gt 7 ] ; then + for result in $(seq $(($# - 7))); do + result=$1 + shift + set -- "$@" "$result" + done + + TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7 + shift 7 + exec "$@" + fi + exit 0 + fi + + if [ $TIMEOUT -ne 0 -a $(date +%s) -ge $TIMEOUT_END ]; then + echo "Operation timed out" >&2 + exit 1 + fi + + sleep 1 + done +} + +while :; do + case "$1" in + http://*|https://*) + HOST="$1" + PROTOCOL="http" + shift 1 + ;; + *:* ) + HOST=$(printf "%s\n" "$1"| cut -d : -f 1) + PORT=$(printf "%s\n" "$1"| cut -d : -f 2) + shift 1 + ;; + -v | --version) + echo $VERSION + exit + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -q-*) + QUIET=0 + echoerr "Unknown option: $1" + usage 1 + ;; + -q*) + QUIET=1 + result=$1 + shift 1 + set -- -"${result#-q}" "$@" + ;; + -t | --timeout) + TIMEOUT="$2" + shift 2 + ;; + -t*) + TIMEOUT="${1#-t}" + shift 1 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + break + ;; + --help) + usage 0 + ;; + -*) + QUIET=0 + echoerr "Unknown option: $1" + usage 1 + ;; + *) + QUIET=0 + echoerr "Unknown argument: $1" + usage 1 + ;; + esac +done + +if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then + echoerr "Error: invalid timeout '$TIMEOUT'" + usage 3 +fi + +case "$PROTOCOL" in + tcp) + if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then + echoerr "Error: you need to provide a host and port to test." + usage 2 + fi + ;; + http) + if [ "$HOST" = "" ]; then + echoerr "Error: you need to provide a host to test." + usage 2 + fi + ;; +esac + +wait_for "$@" From 54a2182970b4332dbef538a43e9d2109975fa95c Mon Sep 17 00:00:00 2001 From: Francesco Ranieri Date: Thu, 1 Dec 2022 22:56:44 +0100 Subject: [PATCH 3/3] WIP --- backend/Dockerfile | 22 ++-- backend/docker-compose.yaml | 17 ++-- backend/utils/oracleUtils.py | 4 +- backend/wait-for.sh | 191 ----------------------------------- 4 files changed, 23 insertions(+), 211 deletions(-) delete mode 100644 backend/wait-for.sh diff --git a/backend/Dockerfile b/backend/Dockerfile index ac7f6db..3d349bd 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,17 +1,15 @@ FROM python:3.10.8-alpine - WORKDIR /backend/controllers + ENV FLASK_APP=app.py ENV FLASK_RUN_HOST=0.0.0.0 + ENV LD_LIBRARY_PATH=instantclient_12_8 RUN apk add --no-cache gcc musl-dev linux-headers + RUN pip install -r requirements.txt - COPY requirements.txt requirements.txt - RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \ - unzip instantclient-basiclite-linuxx64.zip && \ - rm -f instantclient-basiclite-linuxx64.zip && \ - cd instantclient* && \ - rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci && \ - echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && \ - ldconfig - EXPOSE 5000 - COPY . . - CMD ["flask", "run"] \ No newline at end of file + + RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip + RUN unzip instantclient-basiclite-linuxx64.zip + RUN rm -f instantclient-basiclite-linuxx64.zip + RUN cd instantclient_21_8 + RUN rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci + RUN ld \ No newline at end of file diff --git a/backend/docker-compose.yaml b/backend/docker-compose.yaml index e9ba434..c341028 100644 --- a/backend/docker-compose.yaml +++ b/backend/docker-compose.yaml @@ -6,21 +6,26 @@ services: ports: - "1521:1521" volumes: - - desktop_oracle-volume:/opt/oracle/oradata + - desktop_oracle-volume:/opt/oracle/oradata environment: - ORACLE_SID:ORCLCDB - ORACLE_PWD:password flask: - build: . + build: + context: . + dockerfile: Dockerfile ports: - "5000:5000" volumes: - - .:/backend + - flask-volume:/opt/flask/flaskdata depends_on: - - oracle - command: ["../wait-for.sh", "oracle:1521", "--", "python", "app.py"] + oracle: + condition: service_started + command: ["python", "controllers/app.py"] volumes: desktop_oracle-volume: - external: true + external: true + flask-volume: + external: true diff --git a/backend/utils/oracleUtils.py b/backend/utils/oracleUtils.py index 64d4f02..a311005 100644 --- a/backend/utils/oracleUtils.py +++ b/backend/utils/oracleUtils.py @@ -3,12 +3,12 @@ user = 'FRUIT' password = 'FRUIT' dns = 'localhost:1521/ORCLCDB' -lib_dir = 'C:\\Users\\ranie\\Desktop\\workspace\\database_system\\resources\\instantclient-basic-windows\\instantclient_21_7' +lib_dir = 'instantclient_21_7' def get_db_connection(): - cx_Oracle.init_oracle_client(lib_dir=lib_dir) + #cx_Oracle.init_oracle_client(lib_dir=lib_dir) pool = cx_Oracle.SessionPool(user=user, password=password, dsn=dns, min=2, max=5, increment=1, encoding="UTF-8") diff --git a/backend/wait-for.sh b/backend/wait-for.sh deleted file mode 100644 index eae37dd..0000000 --- a/backend/wait-for.sh +++ /dev/null @@ -1,191 +0,0 @@ -#!/bin/sh - -# The MIT License (MIT) -# -# Copyright (c) 2017 Eficode Oy -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -VERSION="2.2.3" - -set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result" -TIMEOUT=15 -QUIET=0 -# The protocol to make the request with, either "tcp" or "http" -PROTOCOL="tcp" - -echoerr() { - if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi -} - -usage() { - exitcode="$1" - cat << USAGE >&2 -Usage: - $0 host:port|url [-t timeout] [-- command args] - -q | --quiet Do not output any status messages - -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout - -v | --version Show the version of this tool - -- COMMAND ARGS Execute command with args after the test finishes -USAGE - exit "$exitcode" -} - -wait_for() { - case "$PROTOCOL" in - tcp) - if ! command -v nc >/dev/null; then - echoerr 'nc command is missing!' - exit 1 - fi - ;; - http) - if ! command -v wget >/dev/null; then - echoerr 'wget command is missing!' - exit 1 - fi - ;; - esac - - TIMEOUT_END=$(($(date +%s) + TIMEOUT)) - - while :; do - case "$PROTOCOL" in - tcp) - nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1 - ;; - http) - wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1 - ;; - *) - echoerr "Unknown protocol '$PROTOCOL'" - exit 1 - ;; - esac - - result=$? - - if [ $result -eq 0 ] ; then - if [ $# -gt 7 ] ; then - for result in $(seq $(($# - 7))); do - result=$1 - shift - set -- "$@" "$result" - done - - TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7 - shift 7 - exec "$@" - fi - exit 0 - fi - - if [ $TIMEOUT -ne 0 -a $(date +%s) -ge $TIMEOUT_END ]; then - echo "Operation timed out" >&2 - exit 1 - fi - - sleep 1 - done -} - -while :; do - case "$1" in - http://*|https://*) - HOST="$1" - PROTOCOL="http" - shift 1 - ;; - *:* ) - HOST=$(printf "%s\n" "$1"| cut -d : -f 1) - PORT=$(printf "%s\n" "$1"| cut -d : -f 2) - shift 1 - ;; - -v | --version) - echo $VERSION - exit - ;; - -q | --quiet) - QUIET=1 - shift 1 - ;; - -q-*) - QUIET=0 - echoerr "Unknown option: $1" - usage 1 - ;; - -q*) - QUIET=1 - result=$1 - shift 1 - set -- -"${result#-q}" "$@" - ;; - -t | --timeout) - TIMEOUT="$2" - shift 2 - ;; - -t*) - TIMEOUT="${1#-t}" - shift 1 - ;; - --timeout=*) - TIMEOUT="${1#*=}" - shift 1 - ;; - --) - shift - break - ;; - --help) - usage 0 - ;; - -*) - QUIET=0 - echoerr "Unknown option: $1" - usage 1 - ;; - *) - QUIET=0 - echoerr "Unknown argument: $1" - usage 1 - ;; - esac -done - -if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then - echoerr "Error: invalid timeout '$TIMEOUT'" - usage 3 -fi - -case "$PROTOCOL" in - tcp) - if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then - echoerr "Error: you need to provide a host and port to test." - usage 2 - fi - ;; - http) - if [ "$HOST" = "" ]; then - echoerr "Error: you need to provide a host to test." - usage 2 - fi - ;; -esac - -wait_for "$@"