Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Giraffaman committed Jan 2, 2024
2 parents 6575137 + 47c9289 commit 7091a3c
Show file tree
Hide file tree
Showing 196 changed files with 4,558 additions and 4,507 deletions.
50 changes: 50 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Shimmie Dockerfile",
"build": {
"context": "..",
"dockerfile": "../Dockerfile",
"target": "devcontainer"
},

"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind",
"workspaceFolder": "/app",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8000],

// Uncomment the next line to run commands after the container is created.
"postCreateCommand": "./.docker/entrypoint.sh unitd --no-daemon --control unix:/var/run/control.unit.sock",
"containerEnv": {
"UID": "2000",
"GID": "2000",
"UPLOAD_MAX_FILESIZE": "50M",
},
"customizations": {
"vscode": {
"extensions": [
"recca0120.vscode-phpunit",
"ryanluker.vscode-coverage-gutters",
"xdebug.php-debug",
"DEVSENSE.phptools-vscode",
"ms-azuretools.vscode-docker"
],
"settings": {
"phpunit.args": [
"--configuration", "${workspaceFolder}/tests/phpunit.xml",
"--coverage-clover", "data/coverage.clover"
],
"coverage-gutters.coverageFileNames": [
"data/coverage.clover"
]
}
}
}

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
81 changes: 81 additions & 0 deletions .docker/entrypoint.d/config.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"listeners": {
"*:8000": {
"pass": "routes",
"forwarded": {
"client_ip": "X-Forwarded-For",
"recursive": false,
"source": [
"172.17.0.0/16"
]
}
}
},
"routes": [
{
"match": {
"uri": "~/_(thumbs|images)/.*"
},
"action": {
"share": [
"`/app/data/${uri.replace(/_(thumbs|images)\\/(..)(..)(.*?)\\/.*/, '$1/$2/$3/$2$3$4')}`",
"`/app/data/${uri.replace(/_(thumbs|images)\\/(..)(.*?)\\/.*/, '$1/$2/$2$3')}`"
],
"response_headers": {
"Cache-Control": "public, max-age=31556926"
}
}
},
{
"action": {
"share": [
"/app/$uri"
],
"types": [
"image/*",
"application/javascript",
"text/css",
"application/sourcemap",
"!"
],
"response_headers": {
"Cache-Control": "public, max-age=31556926"
},
"fallback": {
"pass": "applications/shimmie"
}
}
}
],
"applications": {
"shimmie": {
"type": "php",
"user": "shimmie",
"root": "/app/",
"script": "index.php",
"working_directory": "/app/",
"options": {
"admin": {
"memory_limit": "256M",
"upload_max_filesize": "$UPLOAD_MAX_FILESIZE",
"post_max_size": "$UPLOAD_MAX_FILESIZE"
}
},
"processes": {
"max": 8,
"spare": 2,
"idle_timeout": 60
}
}
},
"settings": {
"http": {
"max_body_size": 1048576000,
"static": {
"mime_types": {
"application/sourcemap": [".map"]
}
}
}
}
}
108 changes: 108 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/sh

set -e

# if user shimmie doesn't already exist, create it
if ! id -u shimmie >/dev/null 2>&1; then
groupadd -g $GID shimmie || true
useradd -ms /bin/bash -u $UID -g $GID shimmie || true
fi
mkdir -p /app/data
chown shimmie:shimmie /app/data

rm -rf /var/lib/unit/*

envsubst '$UPLOAD_MAX_FILESIZE' < /app/.docker/entrypoint.d/config.json.tmpl > /app/.docker/entrypoint.d/config.json

WAITLOOPS=5
SLEEPSEC=1

curl_put()
{
RET=$(/usr/bin/curl -s -w '%{http_code}' -X PUT --data-binary @$1 --unix-socket /var/run/control.unit.sock http://localhost/$2)
RET_BODY=$(echo $RET | /bin/sed '$ s/...$//')
RET_STATUS=$(echo $RET | /usr/bin/tail -c 4)
if [ "$RET_STATUS" -ne "200" ]; then
echo "$0: Error: HTTP response status code is '$RET_STATUS'"
echo "$RET_BODY"
return 1
else
echo "$0: OK: HTTP response status code is '$RET_STATUS'"
echo "$RET_BODY"
fi
return 0
}

if [ "$1" = "unitd" ] || [ "$1" = "unitd-debug" ]; then
if /usr/bin/find "/var/lib/unit/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
echo "$0: /var/lib/unit/ is not empty, skipping initial configuration..."
else
echo "$0: Launching Unit daemon to perform initial configuration..."
/usr/sbin/$1 --control unix:/var/run/control.unit.sock

for i in $(/usr/bin/seq $WAITLOOPS); do
if [ ! -S /var/run/control.unit.sock ]; then
echo "$0: Waiting for control socket to be created..."
/bin/sleep $SLEEPSEC
else
break
fi
done
# even when the control socket exists, it does not mean unit has finished initialisation
# this curl call will get a reply once unit is fully launched
/usr/bin/curl -s -X GET --unix-socket /var/run/control.unit.sock http://localhost/
if /usr/bin/find "/app/.docker/entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
echo "$0: /app/.docker/entrypoint.d/ is not empty, applying initial configuration..."

echo "$0: Looking for certificate bundles in /app/.docker/entrypoint.d/..."
for f in $(/usr/bin/find /app/.docker/entrypoint.d/ -type f -name "*.pem"); do
echo "$0: Uploading certificates bundle: $f"
curl_put $f "certificates/$(basename $f .pem)"
done
echo "$0: Looking for JavaScript modules in /app/.docker/entrypoint.d/..."
for f in $(/usr/bin/find /app/.docker/entrypoint.d/ -type f -name "*.js"); do
echo "$0: Uploading JavaScript module: $f"
curl_put $f "js_modules/$(basename $f .js)"
done

echo "$0: Looking for configuration snippets in /app/.docker/entrypoint.d/..."
for f in $(/usr/bin/find /app/.docker/entrypoint.d/ -type f -name "*.json"); do
echo "$0: Applying configuration $f";
curl_put $f "config"
done
echo "$0: Looking for shell scripts in /app/.docker/entrypoint.d/..."
for f in $(/usr/bin/find /app/.docker/entrypoint.d/ -type f -name "*.sh"); do
echo "$0: Launching $f";
"$f"
done

# warn on filetypes we don't know what to do with
for f in $(/usr/bin/find /app/.docker/entrypoint.d/ -type f -not -name "*.sh" -not -name "*.json" -not -name "*.pem" -not -name "*.js"); do
echo "$0: Ignoring $f";
done
else
echo "$0: /app/.docker/entrypoint.d/ is empty, creating 'welcome' configuration..."
curl_put /usr/share/unit/welcome/welcome.json "config"
fi
echo "$0: Stopping Unit daemon after initial configuration..."
kill -TERM $(/bin/cat /var/run/unit.pid)

for i in $(/usr/bin/seq $WAITLOOPS); do
if [ -S /var/run/control.unit.sock ]; then
echo "$0: Waiting for control socket to be removed..."
/bin/sleep $SLEEPSEC
else
break
fi
done
if [ -S /var/run/control.unit.sock ]; then
kill -KILL $(/bin/cat /var/run/unit.pid)
rm -f /var/run/control.unit.sock
fi
echo
echo "$0: Unit initial configuration complete; ready for start up..."
echo
fi
fi

exec "$@"
18 changes: 16 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Publish
on:
workflow_run:
workflows: Tests
branches: main
branches:
- main
- master
types: completed
workflow_dispatch:
push:
Expand All @@ -16,7 +18,18 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
steps:
- uses: actions/checkout@master
- name: Checkout triggering commit
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/checkout@master
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Checkout main commit
if: ${{ github.event_name != 'workflow_run' }}
uses: actions/checkout@master
- name: Set build vars
run: |
echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
echo "BUILD_HASH=$GITHUB_SHA" >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@main
with:
Expand All @@ -25,4 +38,5 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
buildoptions: "--build-arg RUN_TESTS=false"
buildargs: BUILD_TIME,BUILD_HASH
tag_semver: true
15 changes: 11 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Tests

on:
push:
branches:
- main
- master
pull_request:
schedule:
- cron: '0 2 * * 0' # Weekly on Sundays at 02:00
Expand All @@ -26,7 +29,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@master
with:
php-version: 8.1
php-version: 8.3
- name: Format
run: ./vendor/bin/php-cs-fixer fix && git diff --exit-code

Expand Down Expand Up @@ -57,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
php: ['8.1', '8.2', '8.3']
database: ['pgsql', 'mysql', 'sqlite']

runs-on: ubuntu-latest
Expand Down Expand Up @@ -122,9 +125,13 @@ jobs:
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
export TEST_DSN="sqlite:data/shimmie.sqlite"
fi
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
if [[ "${{ matrix.php }}" == "8.3" ]]; then
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
else
vendor/bin/phpunit --configuration tests/phpunit.xml
fi
- name: Upload coverage
if: matrix.php == '8.1'
if: matrix.php == '8.3'
run: |
vendor/bin/ocular code-coverage:upload --format=php-clover data/coverage.clover
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
backup
data
images
thumbs
*.phar
*.sqlite
*.cache
.devcontainer
trace.json
.docker/entrypoint.d/config.json

#Composer
composer.phar
composer.lock
/vendor/

# Created by http://www.gitignore.io
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($_phpcs_finder)
;
->setCacheFile("data/php-cs-fixer.cache")
;
Loading

0 comments on commit 7091a3c

Please sign in to comment.