Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker files #323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/
data/
23 changes: 23 additions & 0 deletions docker/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
APP_NAME=Astral
APP_ENV=local
APP_KEY=change-me
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost:8080

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=astral
DB_USERNAME=astral
DB_PASSWORD=astral

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

GITHUB_CLIENT_ID=change-me
GITHUB_CLIENT_SECRET=change-me
GITHUB_CLIENT_CALLBACK_URL=http://localhost:8080/auth/github/callback
2 changes: 2 additions & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
.env
79 changes: 79 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Source code
#
FROM alpine/git as sources

RUN mkdir /code
RUN git clone https://github.com/astralapp/astral /code

#
# PHP Dependencies
#
FROM composer:1.10.5 as vendor

COPY --from=sources /code/app/ app/
COPY --from=sources /code/bootstrap/ bootstrap/
COPY --from=sources /code/config/ config/
COPY --from=sources /code/database/ database/
COPY --from=sources /code/public/ public/
COPY --from=sources /code/resources/ resources/
COPY --from=sources /code/routes/ routes/
COPY --from=sources /code/storage/ storage/
COPY --from=sources /code/tests/ tests/
COPY --from=sources /code/server.php server.php
COPY --from=sources /code/artisan artisan
COPY --from=sources /code/composer.json composer.json
COPY --from=sources /code/composer.lock composer.lock

RUN composer install

#
# Frontend
#
FROM node:14.1.0-alpine3.11 as frontend

RUN mkdir -p /app/public

COPY --from=sources /code/package.json /code/webpack.mix.js /code/tailwind.config.js /code/yarn.lock /app/
COPY --from=sources /code/resources/assets/ /app/resources/assets/

WORKDIR /app

RUN yarn
RUN yarn dev

#
# Application
#
FROM php:7.4.5-apache-buster

# Apache
# Enable rewrite module
RUN a2enmod rewrite

# Fix server's fully qualified domain name
ARG APACHE_SERVERNAME=localhost
RUN echo "ServerName" $APACHE_SERVERNAME >> /etc/apache2/apache2.conf

# MYSQL --------------------------------------------------------------
RUN docker-php-ext-install mysqli pdo pdo_mysql
# end MYSQL ----------------------------------------------------------

# PHP INI --------------------------------------------------------------------------------------------------------------
#ARG PHP_INI=php.ini
#COPY $PHP_INI /usr/local/etc/php/
# end PHP INI ----------------------------------------------------------------------------------------------------------

# APACHE CONF ----------------------------------------------------------------------------------------------------------
ENV APACHE_DOCUMENT_ROOT /var/www/html/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
# end APACHE CONF ------------------------------------------------------------------------------------------------------

COPY --from=vendor /app/ /var/www/html/
COPY --from=frontend /app/public/js/ /var/www/html/public/js/
COPY --from=frontend /app/public/css/ /var/www/html/public/css/
COPY --from=frontend /app/mix-manifest.json /var/www/html/mix-manifest.json

RUN chown -R www-data:www-data /var/www/html
47 changes: 47 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# docker and docker-compose

## build

### build standalone docker image
`docker build -t astral:latest .`

### build with docker-compose
`docker-compose build`

### push to docker hub
`docker login -u <username>`

`docker tag astral:latest <username>/astral:latest`

`docker push <username>/astral`


## run

### config file

copy the `.env.template` file to `.env` and change the values

### run (standalone)
`docker run -it --rm -p 8080:80 astral:latest`

### run (docker-compose)
`docker-compose up -d`

### first run
- generate application key

`docker-compose exec app php artisan key:generate`

- create/migrate database

`docker-compose exec app php artisan migrate`




## inspirations for docker multi-stage builds of laravel apps

https://laravel-news.com/multi-stage-docker-builds-for-laravel

https://github.com/glimberger/docker-php
35 changes: 35 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3.5"
services:
app:
build:
context: .
dockerfile: Dockerfile
# image: astral:latest
restart: unless-stopped
volumes:
- ./.env:/var/www/html/.env
ports:
- 127.0.0.1:8080:80
networks:
- network
environment:
TZ: Europe/Paris
mariadb:
image: mariadb:10.3.14-bionic
restart: unless-stopped
ports:
- 127.0.0.1:3306:3306
volumes:
- ./data/mysql:/var/lib/mysql
networks:
- network
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
TZ: Europe/Paris

networks:
network:
driver: bridge