#Laravel + tailwind via vite in docker

1 messages · Page 1 of 1 (latest)

south path
#

dockerfile:


RUN apt-get update -y
#extension for php
RUN apt-get install -y unzip libpq-dev libcurl4-gnutls-dev 
RUN docker-php-ext-install pdo pdo_mysql bcmath

WORKDIR /var/www
COPY . .

COPY --from=composer:2.5.8 /usr/bin/composer /usr/bin/composer

ENV PORT=8000
ENTRYPOINT [ "Docker/entrypoint.sh" ]

#node
FROM node:20.8.0 as node

WORKDIR /var/www
COPY . .

RUN npm install

VOLUME /var/www/node_modules
#

docker-compose.yml


services:
  #PHP Service
  php:
    build: 
      context: . # current directory
      target: php # target the php service in the dockerfile
      args:
        - APP_ENV=${APP_ENV}
    environment:
      - APP_ENV=${APP_ENV}
      - CONTAINER_ROLE=app
    working_dir: /var/www # where the app is located in the container
    volumes:
      - ./:/var/www # mount the current directory to the container directory to store the code
    ports:
      - 8000:8000 # my port so I can connect to it : docker port
    depends_on:
      - database # depends on the database service, so it needs to wait until the database is up and running

  #Database server 
  database:
    image: mysql:5.7.33
    ports:
      - 3306:3306 # my port so I can connect to it : docker port
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db-data:/var/lib/mysql # where the data is stored in the container
  
  #node service
  node:
    build:
      context: .
      target: node
    volumes:
      - .:/usr/src
      - ./node_modules:/usr/src/node_modules
    tty: true
    command: ["npm", "run", "dev"]
    depends_on:
      - php

volumes:
  db-data: ~```
#

entrypoint.sh


# if vendor folder does not exist, run composer install
if [ ! -f "vendor/autoload.php" ]; then
    composer install --no-progress --no-interaction
fi


#if .env file does not exist, copy .env.example to .env
if [ ! -f ".env" ]; then
    echo "Creating env file for env $APP_ENV"
    cp .env.example .env
else
    echo "Env file exists"
fi


php artisan migrate
php artisan key:generate
# php artisan cache:clear
# php artisan config:clear
# php artisan route:clear

php artisan serve --port=$PORT --host=0.0.0.0 --env=.env
exec docker-php-entrypoint "$@"```
stoic crag
#

Quick question - why are you not using the Sail default approach?

#

Use Laravel Sail instead of trying to munge a docker file by yourself

#

Sail provides the docker files required for a standard installation, use those as a jumping off point

#

I think you've misunderstood how the stack works to be honest, so start with the default Sail implementation to get a basic understanding

#

For example, why you're separating your node modules into an entirely separate instance for a development environment is beyond me completely, and won't provide anything beneficial

#

Then you're running migrate every time your solution starts, rather than persisting, which I get for some use cases, but will quickly become frustrating if you're not on top of consistently using migrations and seeders

Then you're not actually seeding anything, so you'll have zero data in your database

#

It feels a bit like someone's said "Docker" to you and you've gone off on a tangent

south path
#

unfortunately is for a uni project and I can t use external libraries, and yes, is my first time using docker :))

stoic crag
#

Laravel Sail is an Laravel Core library

#

I'd be really surprised if you cannot use ANY external libraries, given that you're already using Laravel, which uses several dozen external libraries

#

As a former Uni Lecturer, reach out to the module lead, as if you cannot use ANY external libraries, you're already failing by using Laravel

#

If they say you absolutely can't use any core Laravel products, then look at the Sail repo, and perhaps be influenced by how their docker compose files are written

#

I'd be surprised if they veto it though, given that a) it's a core package, and b) the idea of development using open source is to minimise the code you write, maximise the return on investment (your time), and widen the code review audience

#

feel free to add that into your paper, code review is a key topic in most reviews

#

Using a Sail deployment, it's been reviewed around 10k times, your approach has been reviewed a total of 1 time

tough minnow
stoic crag
#

To be fair, back when I was a lecturer, if someone turned in a project based on a framework, I'd be instantly more interested in what they're actually doing

#

Anyone that didn't make me review dozens of lines of repetitive authorisation/authentication code was on my good side instantly

#

But it all depends on what the lecturer has set, I set "ground up" assessments from time to time, and any 3rd party usage was just a straight fail. It depends what @south path lecturer has set