diff --git a/Quick-Guide-to-publishing-websites-on-hal.elte.hu-with-Python3-backend.md b/Quick-Guide-to-publishing-websites-on-hal.elte.hu-with-Python3-backend.md index 95a65c5..f1c99fc 100644 --- a/Quick-Guide-to-publishing-websites-on-hal.elte.hu-with-Python3-backend.md +++ b/Quick-Guide-to-publishing-websites-on-hal.elte.hu-with-Python3-backend.md @@ -101,7 +101,7 @@ By going to **localhost/your_app** in your browser you should be able to see now # Testing your website with Docker Since the site on hal.elte.hu will run inside a Docker container, before publishing you should test your work locally. To install Docker visit [this](https://docs.docker.com/get-docker/) link. -Once Docker is up and running, you should make a new project folder **DO NOT USE /var/www/html/!**, and copy `your_app.conf` and the `your_app folder` from `/var/www/html/` inside. Once you're done adding some other scirpts detailed a little further, the folder struture should look like this: +Once Docker is up and running, you should make a new project folder **DO NOT USE /var/www/html/!**, and copy `your_app.conf` and the `your_app folder` from `/var/www/html/` inside. (You should omit copying the venv.) Once you're done adding some other scirpts detailed a little further, the folder struture should look like this: > |----/your_app_docker/ > |-----------------your_app.conf > |-----------------Dockerfile --> **We’ll make this later** @@ -115,6 +115,75 @@ Once Docker is up and running, you should make a new project folder **DO NOT USE > |-------------------------templates/ > |-----------------------------main.html > |----------------------------- (…) -> |-------------------------venv/ > |-------------------------main.py -> |------------------------- (…) \ No newline at end of file +> |------------------------- (…) + +To make the missing files: +#### `Dockerfile` (NO EXTENSION) +``` +ARG pyversion=3.9 +FROM python:${pyversion}-bullseye +ARG pyversion=3.9 +ENV PYVERSION ${pyversion:-3.9} + +# Install packages +RUN apt-get -yqq update && \ + apt-get -yqq install apache2 apache2-dev locales libapache2-mod-wsgi-py3 && \ + apt-get clean + +# Install locale +COPY ./locale.gen /etc/locale.gen +RUN locale-gen + +COPY your_app /var/www/html/your_app + +RUN chown -R www-data:www-data /var/www/ +RUN chmod -R 755 /var/www/ + +USER www-data + +# Prepare virtualenv +WORKDIR /var/www/html/your_app/your_app/ +COPY ./requirements.txt . +RUN python3 -m venv ./venv +RUN . ./venv/bin/activate +RUN ./venv/bin/pip install --upgrade pip setuptools +RUN ./venv/bin/pip install -r ./requirements.txt + +# Configure Apache +USER root +COPY ./start-apache.sh / +RUN a2dismod mpm_event && a2enmod mpm_prefork +COPY ./your_app.conf /etc/apache2/sites-available/000-default.conf + +# Start Apache +EXPOSE 80 +CMD ["/bin/sh", "/start-apache.sh"] +``` +Make sure that `your_app` is replaced with the name of your folder, and the paths are the same, as in the folder structure above. +#### `start_apache.sh` +``` +#!/bin/sh + +set -e + +. /etc/apache2/envvars +ulimit -n 8192 +chown root:www-data /var/lock/apache2 +chown -R www-data:www-data /var/www/html +exec /usr/sbin/apache2 -k start -DFOREGROUND +``` +#### `locale.gen` +``` +hu_HU.UTF-8 UTF-8 + +``` +Add here other languages as needed. + +With everything in place go to `/your_app_docker` and run the following commands: +1. Build an image: `docker build --rm -t your_app_img .` +2. Run the container: `docker run -d --name your_app -p 8085:80 your_app_img` + +Then you should be able to access your website at **localhost:8085/your_app**. Once you're done you can stop and remove both the container and the image. + +# Upload your project to Gitea