Skip to content
Snippets Groups Projects
Commit 1d75848c authored by Maxime FRIESS's avatar Maxime FRIESS :blue_heart:
Browse files

Merge branch 'feature/docker' into 'develop'

Support running in Docker

Closes #5

See merge request !9
parents e7b8f766 c8d657ee
Branches
Tags
1 merge request!9Support running in Docker
Pipeline #100933 passed with stages
in 52 seconds
vendor
.git
.env
APP_NAME=Bombernyan-api
APP_ENV=local
APP_KEY=
APP_DEBUG=false
APP_URL=http://localhost
PMA_ABSOLUTE_URI=http://localhost/pma/
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=database
DB_PORT=3306
DB_DATABASE=bombernyan
DB_USERNAME=bombernyan
DB_PASSWORD=bombernyan
MARIADB_ROOT_PASSWORD=
MARIADB_DATABASE=bombernyan
MARIADB_USER=bombernyan
MARIADB_PASSWORD=bombernyan
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="Bombernyan"
JWT_SECRET=
......@@ -8,6 +8,7 @@
.env
.env.backup
.env.production
.env.docker
.phpunit.result.cache
Homestead.json
Homestead.yaml
......
FROM docker.io/php:8.2-fpm
# Add composer.lock and composer.json into the working directory
ADD composer.lock composer.json /api/
# Set working directory
WORKDIR /api/
# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
libzip-dev \
unzip \
git \
libonig-dev \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions for php
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add existing application directory contents to the working directory
ADD . /api
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
/api/storage \
/api/bootstrap/cache
# Install dependencies
RUN composer install
# Build the doc
RUN php artisan l5-swagger:generate
# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
# EXPOSE 9000
# CMD ["php-fpm"]
# Export port 9000 and start php artisan serve
EXPOSE 8000
CMD php artisan serve --host=0.0.0.0 --port=8000
......@@ -37,3 +37,30 @@ ## Running the unit tests
```
php artisan test
```
## Running using Docker
To run the API using docker, you first need to copy `.env.docker.example` to `.env.docker` and make the necessary changes.
You can then build the API's Docker container:
```
docker compose build
```
To start the API, run:
```
docker compose up
```
To completely stop it, run:
```
docker compose down
```
You can also use this command to clean the volumes:
```
docker volume rm api_database
docker volume rm api_storage
```
Warning: This will remove all the data used by the API (database and storage).
......@@ -15,8 +15,8 @@
* )
*
* @OA\Server(
* url="http://127.0.0.1:8000/api",
* description="Local API Server"
* url="/api",
* description="API Server"
* )
*
* @OA\Response(
......
......@@ -18,10 +18,6 @@ public function up()
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password');
$table->foreignId('server_id')->nullable()->references('id')->on('servers');
$table->string("server_token")->nullable()->unique();
$table->enum('server_state', ['connecting', 'connected', 'offline'])->default('offline');
$table->dateTime("email_verified_at")->nullable()->default(null);
$table->timestamps();
});
}
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->foreignId('server_id')->nullable()->references('id')->on('servers');
$table->string("server_token")->nullable()->unique();
$table->enum('server_state', ['connecting', 'connected', 'offline'])->default('offline');
$table->dateTime("email_verified_at")->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('server_id');
$table->dropColumn("server_token");
});
}
};
version: '3'
services:
database:
image: docker.io/mariadb:10.7
volumes:
- database:/var/lib/mysql
restart: always
env_file: .env.docker
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MARIADB_USER --password=$$MARIADB_PASSWORD
start_period: 5s
interval: 5s
timeout: 5s
retries: 55
api:
depends_on:
database:
condition: service_healthy
build: .
command: sh -c "php artisan migrate --force && php artisan serve --host 0.0.0.0"
image: bombernyan-api
volumes:
- storage:/api/storage
restart: always
env_file: .env.docker
phpmyadmin:
depends_on:
database:
condition: service_healthy
image: docker.io/phpmyadmin
restart: always
env_file: .env.docker
environment:
- PMA_HOST=database
- PMA_PORT=3306
proxy:
depends_on:
- api
- phpmyadmin
image: docker.io/nginx
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
volumes:
storage:
driver: local
database:
driver: local
server {
listen 80;
location /pma/ {
proxy_pass http://phpmyadmin:80/;
}
location / {
proxy_pass http://api:8000/;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment