#Dockerize it
This commit is contained in:
parent
937457e7dc
commit
fd17441e91
1
.docker/.gitignore
vendored
Normal file
1
.docker/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
docker-compose.yml
|
36
.docker/Dockerfile
Normal file
36
.docker/Dockerfile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
FROM php:7.4-fpm
|
||||||
|
|
||||||
|
# Thanks to: https://www.digitalocean.com/community/tutorials/how-to-containerize-a-laravel-application-for-development-with-docker-compose-on-ubuntu-18-04
|
||||||
|
|
||||||
|
# Arguments defined in docker-compose.yml
|
||||||
|
ARG user
|
||||||
|
ARG uid
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
libpng-dev \
|
||||||
|
libonig-dev \
|
||||||
|
libxml2-dev \
|
||||||
|
zip \
|
||||||
|
unzip
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
|
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
|
||||||
|
|
||||||
|
# Get latest Composer
|
||||||
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
# Create system user to run Composer and Artisan Commands
|
||||||
|
RUN useradd -G www-data,root -u $uid -d /home/$user $user
|
||||||
|
RUN mkdir -p /home/$user/.composer && \
|
||||||
|
chown -R $user:$user /home/$user
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /var/www
|
||||||
|
|
||||||
|
USER $user
|
42
.docker/README.md
Normal file
42
.docker/README.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Application download & Docker setup
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
- Docker Compose CLI
|
||||||
|
- Git
|
||||||
|
- A text editor, like `nano`
|
||||||
|
|
||||||
|
## Project repository setup
|
||||||
|
|
||||||
|
1. Download the project repository via Git: `git clone https://git.alex.lol/FLOT/HovedprosjektWebApp.git /srv/FLOTWebApp`
|
||||||
|
2. Navigate to the repository directory: `cd /srv/FLOTWebApp`
|
||||||
|
3. Copy `.env.example` to `.env`. Leave the `.env` file as is for now.
|
||||||
|
4. Navigate to the `.docker` directory in the repository.
|
||||||
|
5. Copy `docker-compose.example.yml` to `docker-compose.yml`.
|
||||||
|
6. Edit `docker-compose.yml` (with your text editor) and modify configuration/volumes to match your needs.
|
||||||
|
7. Copy `nginx/hovedprosjekt.example.conf` to `nginx/hovedprosjekt.conf`.
|
||||||
|
8. Edit `nginx/hovedprosjekt.conf` and modify domain/TLS configuration to your needs.
|
||||||
|
- Make sure that the SSL certificate and key uses the path as the volume mapping in `docker-compose.yml`.
|
||||||
|
8. Edit `../.env` and modify your database credentials to match the ones you set in `docker-compose.yml`
|
||||||
|
- `DB_HOST` (db) and `DB_PORT` (5432) can generally be left as is
|
||||||
|
9. Run `docker-compose build app`
|
||||||
|
10. If built successfully, run `docker-compose up -d` to run all containers in "detached" mode.
|
||||||
|
|
||||||
|
## Application setup - First-time setup only
|
||||||
|
|
||||||
|
These steps should be run after you have run `docker-compose up -d`, as the containers need to be running.
|
||||||
|
|
||||||
|
1. While still being in the `.docker` directory run: `docker-compose exec app composer install`
|
||||||
|
- This will attach the `app` container and run the following command to install dependencies for the application: `composer install`
|
||||||
|
- Dependency installation might take a while, so be patient.
|
||||||
|
2. Then run: `docker-compose exec app php artisan key:generate` to generate an app key that's saved in `.env`
|
||||||
|
|
||||||
|
## Logs [Optional]
|
||||||
|
|
||||||
|
You do not need to look at the logs, but if things aren't working, the logs might point you in the right direction:
|
||||||
|
> `docker-compose logs -f` will show the logs and display new entries while open.
|
||||||
|
|
||||||
|
### Special thanks
|
||||||
|
|
||||||
|
Special thanks to the DigitalOcean tutorial "[How To Containerize a Laravel Application for Development with Docker Compose on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-containerize-a-laravel-application-for-development-with-docker-compose-on-ubuntu-18-04)", which was used as the initial template.
|
49
.docker/docker-compose.example.yml
Normal file
49
.docker/docker-compose.example.yml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
version: '3.7'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
args:
|
||||||
|
user: hovedprosjekt
|
||||||
|
uid: 1000
|
||||||
|
context: ./
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: hovedprosjekt
|
||||||
|
container_name: hovedprosjekt-app
|
||||||
|
restart: unless-stopped
|
||||||
|
working_dir: /var/www/
|
||||||
|
volumes:
|
||||||
|
- ../:/var/www
|
||||||
|
networks:
|
||||||
|
- hovedprosjekt
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:12.2-alpine
|
||||||
|
container_name: hovedprosjekt-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: FLOTHP_D8jqH4YjS4ajD4
|
||||||
|
POSTGRES_USER: hovedprosjekt
|
||||||
|
POSTGRES_DB: hovedprosjekt
|
||||||
|
volumes:
|
||||||
|
- /srv/flot_pgdata:/var/lib/postgresql/data
|
||||||
|
networks:
|
||||||
|
- hovedprosjekt
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
image: nginx:1.17
|
||||||
|
container_name: hovedprosjekt-nginx
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
|
- 443:443
|
||||||
|
volumes:
|
||||||
|
- ../:/var/www
|
||||||
|
- ./nginx/:/etc/nginx/conf.d/
|
||||||
|
- /srv/ssl:/srv/ssl
|
||||||
|
networks:
|
||||||
|
- hovedprosjekt
|
||||||
|
|
||||||
|
networks:
|
||||||
|
hovedprosjekt:
|
||||||
|
driver: bridge
|
2
.docker/nginx/.gitignore
vendored
Normal file
2
.docker/nginx/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.conf
|
||||||
|
!*.example.conf
|
77
.docker/nginx/hovedprosjekt.example.conf
Normal file
77
.docker/nginx/hovedprosjekt.example.conf
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
index index.php index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
# Comment this line if not using HTTPS.
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
gzip_static on;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass app:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Domain name, use `.example.com` for wildcard of `example.com`
|
||||||
|
server_name .hovedprosjekt.no;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
listen [::]:443 ssl http2;
|
||||||
|
root /var/www/public;
|
||||||
|
|
||||||
|
# Domain name, use `.example.com` for wildcard of `example.com`
|
||||||
|
server_name .hovedprosjekt.no;
|
||||||
|
|
||||||
|
# TLS certificate configuration
|
||||||
|
ssl_certificate /srv/ssl/hovedprosjekt/fullchain.pem;
|
||||||
|
ssl_certificate_key /srv/ssl/hovedprosjekt/key.pem;
|
||||||
|
|
||||||
|
server_tokens off;
|
||||||
|
|
||||||
|
include ssl_params;
|
||||||
|
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN";
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header X-Content-Type-Options "nosniff";
|
||||||
|
|
||||||
|
index index.html index.htm;
|
||||||
|
|
||||||
|
charset utf-8;
|
||||||
|
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
root /var/www/public;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
gzip_static on;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass app:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /favicon.ico { access_log off; log_not_found off; }
|
||||||
|
location = /robots.txt { access_log off; log_not_found off; }
|
||||||
|
|
||||||
|
location ~ /\.ht {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,9 @@ APP_URL=http://localhost
|
|||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=pgsql
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=db
|
||||||
DB_PORT=3306
|
DB_PORT=5432
|
||||||
DB_DATABASE=laravel
|
DB_DATABASE=laravel
|
||||||
DB_USERNAME=root
|
DB_USERNAME=root
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
Loading…
Reference in New Issue
Block a user