Skip to content

Commit

Permalink
Create Dockerfile
Browse files Browse the repository at this point in the history
[feat] update
  • Loading branch information
John authored and John committed May 2, 2020
1 parent 54b617c commit 736e017
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git/
data/
23 changes: 23 additions & 0 deletions .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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
.env
79 changes: 79 additions & 0 deletions 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
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
# astral-docker
# astral app docker deployment

https://github.com/astralapp/astral

## 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-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

0 comments on commit 736e017

Please # to comment.