Skip to content

Commit

Permalink
feat: built frontend and backend production docker image (#274)
Browse files Browse the repository at this point in the history
* feat: built frontend and backend production docker image

* fix: fix markdown linting

* fix: fix prettier issue

* changing back to fpm
  • Loading branch information
Delyc authored Sep 18, 2024
1 parent 2559ed0 commit effe202
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
38 changes: 29 additions & 9 deletions Docker/DockerfileLaravelProd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM php:8-fpm
FROM php:8.2-fpm

WORKDIR /app
COPY ./Website/htdocs/mpmanager /app

RUN apt-get update && \
apt-get install -y \
Expand All @@ -13,26 +16,43 @@ RUN apt-get update && \
supervisor \
libzip-dev \
vim \
git
git \
zsh \
unzip # Add unzip for Composer

# install ohmyzsh
RUN chsh -s $(which zsh)
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# add php artisan alias
RUN echo 'alias "cmd=php artisan"' >> ~/.zshrc

# remove apt lists
RUN rm -rf /var/lib/apt/lists/*

# install php extentions
# install php extensions
RUN docker-php-ext-install gd mysqli zip pdo pdo_mysql soap ftp opcache bcmath pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg\
&& docker-php-ext-configure pcntl --enable-pcntl

# Download composer.phar
RUN curl -sS https://getcomposer.org/composer.phar -o /usr/local/bin/composer.phar

RUN touch /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_enable=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_autostart=0 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_connephpct_back=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_connect_back=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_port=9000 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_log=/tmp/php5-xdebug.log >> /usr/local/etc/php/conf.d/xdebug.ini;

EXPOSE 9000
COPY ./owner-changer.sh /owner-changer.sh
RUN chmod +x /owner-changer.sh
ENTRYPOINT ["/owner-changer.sh"]
CMD ["www-data"]
# Run the composer install
RUN php /usr/local/bin/composer.phar install

EXPOSE 80

COPY ./Docker/vhost.conf /etc/apache2/sites-available/000-default.conf

RUN chown -R www-data:www-data /app
RUN chmod -R 775 /app/storage

RUN a2enmod rewrite
11 changes: 11 additions & 0 deletions Docker/vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<VirtualHost *:80>
DocumentRoot /app/public

<Directory "/app/public">
AllowOverride all
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
25 changes: 12 additions & 13 deletions Website/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
FROM node:18.20.4

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

COPY package.json /app/
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies
RUN npm install

COPY . /app

RUN mkdir -p dist
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

COPY entrypoint-dev.sh /tmp/entrypoint-dev.sh

RUN chmod +x /tmp/entrypoint-dev.sh

RUN cp -a /app/. /app_backup

ENTRYPOINT [ "/tmp/entrypoint-dev.sh"]

EXPOSE 8081

CMD [ "tail", "-f", "/dev/null" ]
CMD [ "http-server", "dist", "-p", "8081" ]
23 changes: 23 additions & 0 deletions docs/development/build-for-production.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
order: 6
---

# Building docker image for production

## Backend Prod

From the root directory run

```bash
docker build --platform linux/amd64 -t micropowermanager-laravel-prod -f Docker/DockerfileLaravelProd .
```

## Frontend Prod

```bash
cd Website/ui
```

```bash
docker build --platform linux/amd64 -t micropowermanager-frontend-prod -f Dockerfile
```

0 comments on commit effe202

Please sign in to comment.