Skip to content

Commit

Permalink
New & Better Docker Image (#29)
Browse files Browse the repository at this point in the history
* WIP

* Build action

* Build action

* migrate when run, not build

* fixed db name lol

* wip

* wip

* WIP

* done

* change image name

* change image name
  • Loading branch information
sethsandaru committed Feb 7, 2024
1 parent 94d0efa commit 76d7950
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 78 deletions.
42 changes: 31 additions & 11 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
### Docking Development Image
# Single image to rule them all
# PHP 8.2
# SQLite
# Nginx
# Local Storage
# Supervisor to run 5 concurrent workers

FROM php:8.2-fpm

WORKDIR /var/www/html
Expand All @@ -30,22 +22,50 @@ COPY . .
COPY ./.docker/docking-worker.conf /etc/supervisor/conf.d/
COPY ./.docker/docking-host.conf /etc/nginx/conf.d/default.conf

RUN cp .docker/entrypoint.sh /entrypoint
RUN chmod +x /entrypoint

# The bundle already built, no need to keep this to save size
RUN rm -rf ./node_modules

RUN php artisan optimize
RUN php artisan storage:link
RUN php artisan migrate

RUN chown -R www-data:www-data storage
RUN chown -R www-data:www-data storage/app
RUN chmod -R 777 storage/logs
RUN chmod -R 777 docking.sqlite

RUN touch /var/www/html/docking.sqlite
RUN chown www-data:www-data docking.sqlite

# Nginx remove default site
RUN rm /etc/nginx/sites-enabled/default

EXPOSE 80

############# Default app ENV
ENV APP_ENV="production"
ENV APP_KEY="base64:/UnGygYvVBmIh+VgNhMj6MyI/ieXTtzUJsUL4OUtZGI="
ENV DB_CONNECTION="sqlite"
ENV DATABASE_URL="sqlite:////var/www/html/docking.sqlite"

############# Storage ENV

# s3|local
ENV FILESYSTEM_DISK=public

# if select s3, these must be defined
ENV AWS_ACCESS_KEY_ID=""
ENV AWS_SECRET_ACCESS_KEY=""
ENV AWS_DEFAULT_REGION="ap-southeast-1"
ENV AWS_BUCKET="shipsaas-docking"

############# Docking Config
ENV DOCKING_PUBLIC_ACCESS_KEY=""
ENV DOCKING_CONSOLE_ENABLED=true
ENV DOCKING_CONSOLE_PASSWORD=""
ENV DOCKING_DEFAULT_PDF_DRIVER="gotenberg"
ENV DOCKING_GOTENBERG_ENDPOINT="http://127.0.0.1:9898"

# Start ALL
CMD ["/usr/bin/supervisord", "-n"]
ENTRYPOINT ["/entrypoint"]
10 changes: 5 additions & 5 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Docker of DocKing

DocKing ships Docker Images too, in case you want boot it up as fast as you can for development, even production usage.
DocKing ships Docker Images too.

## Development
## 2024 updates

Check out: https://docking.shipsaas.tech/getting-started/run-on-local/docker
DocKing image can be used in both development & production 😎. You can inject your own ENVs in runtime.

## Production
## Run DocKing

Check out: https://docking.shipsaas.tech/deployment/docker
TBA
12 changes: 12 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
set -e

# Run user scripts, if they exist
for f in /var/www/html/.docker/scripts/*.sh; do
# Bail out this loop if any script exits with non-zero status code
bash "$f" || break
done

echo "Welcome to DocKing";
echo "Starting the application using supervisor...";
exec /usr/bin/supervisord --nodaemon
39 changes: 30 additions & 9 deletions .docker/octane.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
### Docking Development Image - Octane Mode
# Single image to rule them all
# PHP 8.2
# SQLite
# Local Storage
# Supervisor to run 5 concurrent workers
FROM ghcr.io/roadrunner-server/roadrunner:latest AS roadrunner
FROM php:8.2-fpm

Expand Down Expand Up @@ -31,23 +25,50 @@ COPY . .
COPY ./.docker/docking-octane.conf /etc/supervisor/conf.d/
COPY ./.docker/docking-host-octane.conf /etc/nginx/conf.d/default.conf

RUN cp .docker/entrypoint.sh /entrypoint
RUN chmod +x /entrypoint

# The bundle already built, no need to keep this to save size
RUN rm -rf ./node_modules

RUN php artisan optimize
RUN php artisan storage:link
RUN php artisan migrate

RUN chown -R www-data:www-data storage
RUN chown -R www-data:www-data storage/app
RUN chmod -R 777 storage/logs
RUN chmod -R 777 docking.sqlite

RUN touch /var/www/html/docking.sqlite
RUN chown www-data:www-data docking.sqlite

# Nginx remove default site
RUN rm /etc/nginx/sites-enabled/default

EXPOSE 80

############# Default app ENV
ENV APP_ENV="production"
ENV APP_KEY="base64:/UnGygYvVBmIh+VgNhMj6MyI/ieXTtzUJsUL4OUtZGI="
ENV DB_CONNECTION="sqlite"
ENV DATABASE_URL="sqlite:////var/www/html/docking.sqlite"

############# Storage ENV

# s3|local
ENV FILESYSTEM_DISK=public

# if select s3, these must be defined
ENV AWS_ACCESS_KEY_ID=""
ENV AWS_SECRET_ACCESS_KEY=""
ENV AWS_DEFAULT_REGION="ap-southeast-1"
ENV AWS_BUCKET="shipsaas-docking"

############# Docking Config
ENV DOCKING_PUBLIC_ACCESS_KEY=""
ENV DOCKING_CONSOLE_ENABLED=true
ENV DOCKING_CONSOLE_PASSWORD=""
ENV DOCKING_DEFAULT_PDF_DRIVER="gotenberg"
ENV DOCKING_GOTENBERG_ENDPOINT="http://127.0.0.1:9898"

# Start ALL
CMD ["/usr/bin/supervisord", "-n"]
ENTRYPOINT ["/entrypoint"]
49 changes: 0 additions & 49 deletions .docker/prod.Dockerfile

This file was deleted.

13 changes: 13 additions & 0 deletions .docker/scripts/caches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

echo "Running config:cache...";
php /var/www/html/artisan config:cache --no-ansi -q
echo "Successfully cached the configuration";

echo "Running route:cache...";
php /var/www/html/artisan route:cache --no-ansi -q
echo "Successfully cached the routes";

echo "Running view:cache...";
php /var/www/html/artisan view:cache --no-ansi -q
echo "Successfully cached the views";
5 changes: 5 additions & 0 deletions .docker/scripts/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "Running migration...";
php /var/www/html/artisan migrate --no-ansi -q --force
echo "Successfully migrated";
6 changes: 3 additions & 3 deletions .github/workflows/push-dev-image.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Push Docker Dev Image
name: Push Docker Images
env:
DEV_IMAGE_ENV: ${{ secrets.DEV_IMAGE_ENV }}
IMAGE: 'shipsaas/docking-dev'
OCTANE_IMAGE: 'shipsaas/docking-dev-octane'
IMAGE: 'shipsaas/docking'
OCTANE_IMAGE: 'shipsaas/docking-on-steroid'
REGISTRY: ghcr.io

on:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/test-build-for-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test build Docker Image

on:
pull_request:
branches:
- 'main'
types: [ opened, synchronize, reopened, ready_for_review ]

jobs:
build_image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
if: success()

- name: Setup PHP with coverage driver
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Setup Node 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'

- name: Setup & Build
if: success()
run: |
composer install --no-interaction
npm ci && npm run build
- name: Build Docker - Normal Image
if: success()
run: docker build -t docking:test -f .docker/Dockerfile .

- name: Build Docker - Octane Image
if: success()
run: docker build -t docking:test -f .docker/octane.Dockerfile .
2 changes: 1 addition & 1 deletion resources/js/console/factories/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { authStorage } from '../utils/authStorage';

const options = {
baseURL: import.meta.env.VITE_APP_URL + '/api/v1',
baseURL: '/api/v1',
timeout: 60_000,
};

Expand Down

0 comments on commit 76d7950

Please sign in to comment.