Improvements to docker setups

This commit is contained in:
Ronald A. Richardson
2025-05-19 17:30:18 +08:00
parent ae89600ae6
commit 86da1bd095
6 changed files with 55 additions and 18 deletions

1
api/EXPECTED_HASH Normal file
View File

@@ -0,0 +1 @@
ae89600ae6433349b62a31a80d8738faf771d0b0

View File

@@ -68,6 +68,7 @@ target "fleetbase-console" {
target "fleetbase-api" {
context = "./"
dockerfile = "docker/Dockerfile"
target = "app-release"
platforms = ["linux/amd64"]
tags = notequal("", REGISTRY) ? formatlist(

View File

@@ -31,13 +31,20 @@ services:
SOCKETCLUSTER_WORKERS: 10
SOCKETCLUSTER_BROKERS: 10
scheduler:
image: fleetbase/fleetbase-api:v0.7.0
command: ["go-crond", "--verbose", "root:./crontab"]
environment:
DATABASE_URL: "mysql://root@database/fleetbase"
QUEUE_CONNECTION: redis
CACHE_DRIVER: redis
CACHE_PATH: /fleetbase/api/storage/framework/cache
CACHE_URL: tcp://cache
REDIS_URL: tcp://cache
queue:
build:
context: .
dockerfile: docker/Dockerfile
target: events-dev
args:
ENVIRONMENT: development
image: fleetbase/fleetbase-api:v0.7.0
command: ["php", "artisan", "queue:work"]
healthcheck:
test: ["CMD", "php", "artisan", "queue:status"]
interval: 30s
@@ -52,21 +59,14 @@ services:
REDIS_URL: tcp://cache
console:
build:
context: ./console
dockerfile: Dockerfile
args:
ENVIRONMENT: development
image: fleetbase/fleetbase-console:v0.7.0
ports:
- "4200:4200"
volumes:
- ./docker/fleetbase.config.json:/usr/share/nginx/html/fleetbase.config.json
application:
build:
context: .
dockerfile: docker/Dockerfile
target: app-dev
args:
ENVIRONMENT: development
image: fleetbase/fleetbase-api:v0.7.0
environment:
ENVIRONMENT: development
DATABASE_URL: "mysql://root@database/fleetbase"

View File

@@ -75,6 +75,7 @@ ENV QUEUE_CONNECTION=redis
ENV CADDYFILE_PATH=/fleetbase/Caddyfile
ENV CONSOLE_PATH=/fleetbase/console
ENV OCTANE_SERVER=frankenphp
ENV FLEETBASE_VERSION=0.7.1
# Set environment
ARG ENVIRONMENT=production
@@ -89,6 +90,16 @@ COPY --chown=www-data:www-data ./Caddyfile $CADDYFILE_PATH
# Create /fleetbase directory and set correct permissions
RUN mkdir -p /fleetbase/api && mkdir -p /fleetbase/console && chown -R www-data:www-data /fleetbase
# Generate and store a UUID in .fleetbase-id
RUN uuidgen > /fleetbase/api/.fleetbase-id
# Export the same ID as an environment variable for use in the container
RUN export FLEETBASE_INSTANCE_ID=$(cat /fleetbase/api/.fleetbase-id) && \
echo "FLEETBASE_INSTANCE_ID=$FLEETBASE_INSTANCE_ID" >> /etc/environment
# Track commit hash
RUN git rev-parse HEAD > /fleetbase/CURRENT_HASH
# Set working directory
WORKDIR /fleetbase/api
@@ -153,7 +164,12 @@ CMD ["php", "artisan", "queue:work"]
# Application dev stage
FROM base AS app-dev
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["sh", "-c", "php artisan octane:frankenphp --max-requests=250 --port=8000 --host=0.0.0.0 --watch"]
CMD ["sh", "-c", "php artisan octane:frankenphp --max-requests=250 --port=8000 --host=0.0.0.0 --watch"]
# Application release stage
FROM base AS app-release
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["sh", "-c", "php artisan octane:frankenphp --max-requests=250 --port=8000 --host=0.0.0.0"]
# Application stage
FROM base AS app

View File

@@ -0,0 +1,14 @@
#!/bin/sh
CURRENT_HASH_FILE="./EXPECTED_HASH"
CURRENT_HASH=$(git rev-parse HEAD)
EXISTING_HASH=$(cat "$CURRENT_HASH_FILE" 2>/dev/null || echo "")
if [ "$CURRENT_HASH" = "$EXISTING_HASH" ]; then
echo "✅ EXPECTED_HASH is already up to date."
exit 0
fi
echo "⚙️ Writing current commit hash to CURRENT_HASH..."
echo "$CURRENT_HASH" > "$CURRENT_HASH_FILE"
git add "$CURRENT_HASH_FILE"

5
scripts/setup-hooks.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
cp ./scripts/pre-commit-hook.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "✅ Git hook installed."