From a37909ef4eacffdec4b34e0631cc7c7c3c0ed939 Mon Sep 17 00:00:00 2001 From: Khaled Smaoui Date: Fri, 8 Nov 2024 15:30:29 -0800 Subject: [PATCH] Implemented dockerfiles for frontend, fixed some issues with local deployment and updated docs --- docker/Dockerfile-ecas-frontend | 57 +++++++++++++++++ docker/README.md | 8 ++- docker/build-from-dockerfiles | 8 +++ ...ker-compose.yml => docker-compose-S2I.yml} | 20 +----- docker/docker-compose-local.yml | 64 +++++++++++++++++++ docker/manage | 20 +++--- web-app/.env.sample | 1 + web-app/webpack.mix.js | 2 +- 8 files changed, 152 insertions(+), 28 deletions(-) create mode 100644 docker/Dockerfile-ecas-frontend create mode 100644 docker/build-from-dockerfiles rename docker/{docker-compose.yml => docker-compose-S2I.yml} (55%) create mode 100644 docker/docker-compose-local.yml diff --git a/docker/Dockerfile-ecas-frontend b/docker/Dockerfile-ecas-frontend new file mode 100644 index 000000000..7fb6e7169 --- /dev/null +++ b/docker/Dockerfile-ecas-frontend @@ -0,0 +1,57 @@ +FROM php:7.2-apache + +# Add the necessary libraries and extensions to PHP +RUN apt-get update \ + && apt-get install -y \ + libmcrypt-dev \ + curl \ + git \ + zip \ + unzip \ + default-mysql-client libmagickwand-dev --no-install-recommends \ + && pecl install imagick \ + && docker-php-ext-enable imagick \ + && docker-php-ext-install pdo_mysql \ + && docker-php-ext-install zip +RUN pecl install mcrypt-1.0.5 \ + && docker-php-ext-enable mcrypt +#RUN npm i -g npm +# Set the documet root +ENV APACHE_DOCUMENT_ROOT /web-app/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +# Enable mod_rewrite module to make our urls work +RUN a2enmod rewrite + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + + +RUN mkdir /web-app + + +WORKDIR /web-app + +COPY ./web-app ./ +RUN rm -rf public/css/* public/js/* bootstrap/cache/* + +RUN composer install + +USER root + + +RUN chmod -R go+w ./storage +RUN chmod -R go+w ./bootstrap/cache + + +RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf +RUN apt-get update \ + && apt-get install -y software-properties-common npm libavahi-compat-libdnssd-dev ssh +RUN service apache2 restart +RUN npm cache clean --force\ + && npm install \ + && npm run dev + + + + diff --git a/docker/README.md b/docker/README.md index bfc4d0710..272e17bfa 100644 --- a/docker/README.md +++ b/docker/README.md @@ -4,6 +4,9 @@ 1. Have a working installation of [Docker](https://www.docker.com/) 2. Use a shell such as `bash` ( or [Git bash](https://git-scm.com/downloads) if on Windows) 3. Have the [S2I binaries](https://github.com/openshift/source-to-image/releases) on your path +3. Get Red Hat credentials or Register for a Red Hat account if you don't have those credentials available. +4. Login to Red Hat registery using this command: docker login https://registry.redhat.io. You will get prompted for the credentials from step 3. +5. Copy env.sample to .env and add required secrets ## Running the project The `manage` script in this directory contains a set of utilities that help getting up and running in Docker in no time. The command `./manage --help` can be run at any time to read the usage instructions. @@ -14,4 +17,7 @@ To run the project execute `./manage start`: the api container will be serving c ### Development Mode During development it is useful to have code hot-reloading enabled, so that containers won't need to be rebuilt after each change. -To start both the api and frontend container in development mode, using code hot-reloading, run `./manage start-dev`. \ No newline at end of file +To start both the api and frontend container in development mode, using code hot-reloading, run `./manage start-dev`. + +### Build from dockerfiles + run ./build-from-dockerfiles \ No newline at end of file diff --git a/docker/build-from-dockerfiles b/docker/build-from-dockerfiles new file mode 100644 index 000000000..212c3833c --- /dev/null +++ b/docker/build-from-dockerfiles @@ -0,0 +1,8 @@ +#!/bin/bash +#cleanup volumes before starting docker compose +docker-compose -f docker-compose-local.yml down --volumes +cp ../web-app/.env .env +# build ecas-api and cas-api. For now only frontend is built from dockerfiles +./manage build api +./manage build cas-api +docker-compose -f docker-compose-local.yml up --build \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose-S2I.yml similarity index 55% rename from docker/docker-compose.yml rename to docker/docker-compose-S2I.yml index dcfd950e0..61cfe3bfa 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose-S2I.yml @@ -9,8 +9,9 @@ services: - 7070:8080 networks: - webnet + environment: - - APP_KEY=base64:sf+TeOK14bHa/pqupMwHbV5MUBFeZF/OPFh+LU++0w8= + - APP_KEY=${APP_KEY_BASE64} - APP_DEBUG=true - APP_URL=http://localhost - DOCUMENTROOT=/public @@ -34,23 +35,6 @@ services: networks: - webnet -# # ecas-frontend-dev -# # -# ecas-frontend-dev: -# build: -# context: .. -# dockerfile: docker/ecas-frontend/Dockerfile-dev -# working_dir: /web-app -# ports: -# - 8081:80 -# volumes: -# - ../web-app:/web-app -# networks: -# - webnet -# environment: -# - CHOKIDAR_USEPOLLING=true -# - APP_KEY=base64:sf+TeOK14bHa/pqupMwHbV5MUBFeZF/OPFh+LU++0w8= -# - APP_DEBUG=true networks: webnet: \ No newline at end of file diff --git a/docker/docker-compose-local.yml b/docker/docker-compose-local.yml new file mode 100644 index 000000000..99e21715a --- /dev/null +++ b/docker/docker-compose-local.yml @@ -0,0 +1,64 @@ +version: '3' +services: + + # ecas-frontend + # DYNAMICSBASEURL=https://ecaswebapi.azurewebsites.net/api + ecas-frontend: + build: + context: .. + dockerfile: docker/Dockerfile-ecas-frontend + working_dir: /web-app + ports: + - 7070:80 + + networks: + - webnet + volumes: + - ../web-app:/web-app + - /web-app/vendor + - /web-app/node_modules + - /web-app/storage + - /web-app/bootstrap/cache + - /web-app/public + + environment: + - APP_KEY=${APP_KEY_BASE64} + - APP_DEBUG=true + - APP_URL=http://localhost + - DOCUMENTROOT=/public + - DYNAMICSBASEURL=${DYNAMICSBASEURL:-http://ecas-api:8080/api} + + + + # ecas-api + # + ecas-api: + image: ecas-api + ports: + - 8080:8080 + networks: + - webnet + + # cas-api + # + cas-api: + image: cas-api + ports: + - 8081:8080 + networks: + - webnet + + +networks: + webnet: +volumes: + web-app-vendor: + driver: local + web-app-storage: + driver: local + web-app-cache: + driver: local + web-app-node: + driver: local + web-app-public: + driver: local \ No newline at end of file diff --git a/docker/manage b/docker/manage index 6a3e60f56..eb9c27fc2 100755 --- a/docker/manage +++ b/docker/manage @@ -81,6 +81,7 @@ build-ecas-frontend() { # BASE_IMAGE="registry.redhat.io/rhscl/php-73-rhel7" echo -e "\nBuilding ecas-frontend image from ${BASE_IMAGE}..." + docker pull ${BASE_IMAGE} ${S2I_EXE} build \ '../web-app' \ @@ -92,8 +93,10 @@ build-ecas-api() { # # ecas-api # - BASE_IMAGE="mcr.microsoft.com/dotnet/aspnet:6.0" + BASE_IMAGE="registry.redhat.io/rhel8/dotnet-60" echo -e "\nBuilding ecas-api image from ${BASE_IMAGE}..." + docker pull ${BASE_IMAGE} + ${S2I_EXE} build \ '../web-api/Ecas.Dyn365Service' \ @@ -109,6 +112,7 @@ build-ecas-cas-api() { DOTNET_STARTUP_PROJECT=CASInterfaceService/cas-interface-service.csproj BASE_IMAGE="registry.redhat.io/dotnet/dotnet-21-rhel7" echo -e "\nBuilding cas-api image from ${BASE_IMAGE}..." + docker pull ${BASE_IMAGE} ${S2I_EXE} build \ -e "DOTNET_STARTUP_PROJECT=${DOTNET_STARTUP_PROJECT}" \ @@ -120,6 +124,8 @@ build-ecas-cas-api() { build-ecas-all() { build-ecas-frontend build-ecas-api + build-ecas-cas-api + } configureEnvironment() { @@ -216,22 +222,20 @@ case "${COMMAND}" in start|up) unset DEBUG DEFAULT_CONTAINERS="ecas-frontend $DEFAULT_CONTAINERS" - _startupParams=$(getStartupParams $@) configureEnvironment $@ - docker-compose up -d ${_startupParams} - docker-compose logs -f + docker-compose -f docker-compose-S2I.yml up -d + docker-compose logs -f docker-compose-S2I.yml ;; start-dev) export DEBUG=true DEFAULT_CONTAINERS="ecas-frontend" - _startupParams=$(getStartupParams $@) configureEnvironment $@ - docker-compose up -d ${_startupParams} - docker-compose logs -f + docker-compose -f docker-compose-S2I.yml up -d + docker-compose logs -f docker-compose-S2I.yml ;; logs) configureEnvironment $@ - docker-compose logs -f + docker-compose logs -f docker-compose-S2I.yml ;; stop) DEFAULT_CONTAINERS="ecas-frontend ecas-frontend-dev" diff --git a/web-app/.env.sample b/web-app/.env.sample index 2346539cd..ca63b5196 100644 --- a/web-app/.env.sample +++ b/web-app/.env.sample @@ -3,6 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://ecas.test +APP_KEY_BASE64= DYNAMICSBASEURL= DYNAMICS_TIMEOUT=30 diff --git a/web-app/webpack.mix.js b/web-app/webpack.mix.js index f22f82751..f7d1e98ba 100644 --- a/web-app/webpack.mix.js +++ b/web-app/webpack.mix.js @@ -12,6 +12,6 @@ const mix = require('laravel-mix'); */ mix.js('resources/js/app.js', 'public/js') - .sass('resources/sass/app.scss', 'public/css'); + .sass('resources/sass/app.scss', 'public/css').version(); mix.js('node_modules/popper.js/dist/popper.js', 'public/js').sourceMaps(); \ No newline at end of file