4 Commits

Author SHA1 Message Date
Neo
7e75a04d30 Merge b4bcc3b196 into 376f687c38 2025-03-10 20:09:19 +08:00
376f687c38 chore: questionable is not a recognized rating 2025-02-11 21:50:27 +01:00
4fd848abf2 doc: use docker compose instead of docker-compose
The minimum version requirements are rough guesses, in practice any decently modern docker installation should work.
2025-02-11 21:25:10 +01:00
b4bcc3b196 Docker development setup with remote debugging 2024-10-12 00:50:37 +02:00
10 changed files with 143 additions and 20 deletions

View File

@ -315,8 +315,13 @@ function makeOutputDirs() {
} }
function watch() { function watch() {
let wss = new WebSocket.Server({ port: 8080 }); let wss = new WebSocket.Server({ port: 8081 });
const liveReload = !process.argv.includes('--no-live-reload'); const liveReload = !process.argv.includes('--no-live-reload');
const polling = process.argv.includes("--polling");
const chokidarOptions = {
usePolling: polling,
};
function emitReload() { function emitReload() {
if (liveReload) { if (liveReload) {
@ -329,7 +334,7 @@ function watch() {
} }
} }
chokidar.watch('./fonts/**/*').on('change', () => { chokidar.watch('./fonts/**/*', chokidarOptions).on('change', () => {
try { try {
bundleBinaryAssets(); bundleBinaryAssets();
emitReload(); emitReload();
@ -337,7 +342,7 @@ function watch() {
console.error(pe.render(e)); console.error(pe.render(e));
} }
}); });
chokidar.watch('./img/**/*').on('change', () => { chokidar.watch('./img/**/*', chokidarOptions).on('change', () => {
try { try {
bundleWebAppFiles(); bundleWebAppFiles();
emitReload(); emitReload();
@ -345,14 +350,14 @@ function watch() {
console.error(pe.render(e)); console.error(pe.render(e));
} }
}); });
chokidar.watch('./html/**/*.tpl').on('change', () => { chokidar.watch('./html/**/*.tpl', chokidarOptions).on('change', () => {
try { try {
bundleHtml(); bundleHtml();
} catch (e) { } catch (e) {
console.error(pe.render(e)); console.error(pe.render(e));
} }
}); });
chokidar.watch('./css/**/*.styl').on('change', () => { chokidar.watch('./css/**/*.styl', chokidarOptions).on('change', () => {
try { try {
bundleCss() bundleCss()
emitReload(); emitReload();

View File

@ -0,0 +1,11 @@
#!/usr/bin/dumb-init /bin/sh
# Integrate environment variables
sed -i "s|__BACKEND__|${BACKEND_HOST}|" \
/etc/nginx/nginx.conf
# Start server
nginx&
# Watch source for changes and build app
npm run watch -- --polling

View File

@ -3,7 +3,7 @@
const config = require("./config.js"); const config = require("./config.js");
if (config.environment == "development") { if (config.environment == "development") {
var ws = new WebSocket("ws://" + location.hostname + ":8080"); var ws = new WebSocket("ws://" + location.hostname + ":8081");
ws.addEventListener("open", function (event) { ws.addEventListener("open", function (event) {
console.log("Live-reloading websocket connected."); console.log("Live-reloading websocket connected.");
}); });

View File

@ -789,7 +789,7 @@ data.
| `fav-time` | alias of `fav-date` | | `fav-time` | alias of `fav-date` |
| `feature-date` | featured at given date | | `feature-date` | featured at given date |
| `feature-time` | alias of `feature-time` | | `feature-time` | alias of `feature-time` |
| `safety` | having given safety. `<value>` can be either `safe`, `sketchy` (or `questionable`) or `unsafe`. | | `safety` | having given safety. `<value>` can be either `safe`, `sketchy` or `unsafe`. |
| `rating` | alias of `safety` | | `rating` | alias of `safety` |
**Sort style tokens** **Sort style tokens**

View File

@ -1,5 +1,5 @@
This assumes that you have Docker (version 17.05 or greater) This assumes that you have Docker (version 19.03 or greater)
and Docker Compose (version 1.6.0 or greater) already installed. and the Docker Compose CLI (version 1.27.0 or greater) already installed.
### Prepare things ### Prepare things
@ -38,7 +38,7 @@ and Docker Compose (version 1.6.0 or greater) already installed.
This pulls the latest containers from docker.io: This pulls the latest containers from docker.io:
```console ```console
user@host:szuru$ docker-compose pull user@host:szuru$ docker compose pull
``` ```
If you have modified the application's source and would like to manually If you have modified the application's source and would like to manually
@ -49,17 +49,17 @@ and Docker Compose (version 1.6.0 or greater) already installed.
For first run, it is recommended to start the database separately: For first run, it is recommended to start the database separately:
```console ```console
user@host:szuru$ docker-compose up -d sql user@host:szuru$ docker compose up -d sql
``` ```
To start all containers: To start all containers:
```console ```console
user@host:szuru$ docker-compose up -d user@host:szuru$ docker compose up -d
``` ```
To view/monitor the application logs: To view/monitor the application logs:
```console ```console
user@host:szuru$ docker-compose logs -f user@host:szuru$ docker compose logs -f
# (CTRL+C to exit) # (CTRL+C to exit)
``` ```
@ -84,13 +84,13 @@ and Docker Compose (version 1.6.0 or greater) already installed.
2. Build the containers: 2. Build the containers:
```console ```console
user@host:szuru$ docker-compose build user@host:szuru$ docker compose build
``` ```
That will attempt to build both containers, but you can specify `client` That will attempt to build both containers, but you can specify `client`
or `server` to make it build only one. or `server` to make it build only one.
If `docker-compose build` spits out: If `docker compose build` spits out:
``` ```
ERROR: Service 'server' failed to build: failed to parse platform : "" is an invalid component of "": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument ERROR: Service 'server' failed to build: failed to parse platform : "" is an invalid component of "": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument
@ -102,7 +102,7 @@ and Docker Compose (version 1.6.0 or greater) already installed.
user@host:szuru$ export DOCKER_BUILDKIT=1; export COMPOSE_DOCKER_CLI_BUILD=1 user@host:szuru$ export DOCKER_BUILDKIT=1; export COMPOSE_DOCKER_CLI_BUILD=1
``` ```
...and run `docker-compose build` again. ...and run `docker compose build` again.
*Note: If your changes are not taking effect in your builds, consider building *Note: If your changes are not taking effect in your builds, consider building
with `--no-cache`.* with `--no-cache`.*
@ -117,7 +117,7 @@ with `--no-cache`.*
run from docker: run from docker:
```console ```console
user@host:szuru$ docker-compose run server ./szuru-admin --help user@host:szuru$ docker compose run server ./szuru-admin --help
``` ```
will give you a breakdown on all available commands. will give you a breakdown on all available commands.

58
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,58 @@
version: "2"
services:
server:
build:
context: ./server
target: development
depends_on:
- sql
environment:
## These should be the names of the dependent containers listed below,
## or FQDNs/IP addresses if these services are running outside of Docker
POSTGRES_HOST: sql
## Credentials for database:
POSTGRES_USER:
POSTGRES_PASSWORD: ## Commented Values are Default:
#POSTGRES_DB: defaults to same as POSTGRES_USER
#POSTGRES_PORT: 5432
#LOG_SQL: 0 (1 for verbose SQL logs)
DEBUG: 1
WAIT_FOR_CLIENT: 0
volumes:
- "data:/data"
- "./server/:/opt/app/"
ports:
- "5678:5678"
client:
build:
context: ./client
target: development
depends_on:
- server
environment:
BACKEND_HOST: server
BASE_URL:
volumes:
- "data:/data:ro"
- "./client/:/opt/app/"
- "/opt/app/public/"
ports:
- "${PORT}:80"
# Port 8081 is used for the live-reload when the source code is changed.
- "8081:8081"
sql:
image: postgres:11-alpine
restart: unless-stopped
environment:
POSTGRES_USER:
POSTGRES_PASSWORD:
volumes:
- "sql:/var/lib/postgresql/data"
volumes:
data:
sql:

View File

@ -1,9 +1,7 @@
## Example Docker Compose configuration ## Example Docker Compose configuration
## ##
## Use this as a template to set up docker-compose, or as guide to set up other ## Use this as a template to set up docker compose, or as guide to set up other
## orchestration services ## orchestration services
version: '2'
services: services:
server: server:

View File

@ -61,6 +61,35 @@ ENTRYPOINT ["pytest", "--tb=short"]
CMD ["szurubooru/"] CMD ["szurubooru/"]
FROM prereqs as development
WORKDIR /opt/app
ARG PUID=1000
ARG PGID=1000
RUN apk --no-cache add \
dumb-init \
py3-pip \
py3-setuptools \
py3-waitress \
&& pip3 install --no-cache-dir --disable-pip-version-check \
hupper \
debugpy \
&& mkdir -p /opt/app /data \
&& addgroup -g ${PGID} app \
&& adduser -SDH -h /opt/app -g '' -G app -u ${PUID} app \
&& chown -R app:app /opt/app /data
USER app
CMD ["/opt/app/docker-start-dev.sh"]
ARG PORT=6666
ENV PORT=${PORT}
EXPOSE ${PORT}
VOLUME ["/data/"]
FROM prereqs as release FROM prereqs as release
WORKDIR /opt/app WORKDIR /opt/app

View File

@ -0,0 +1,8 @@
#!/usr/bin/dumb-init /bin/sh
set -e
cd /opt/app
alembic upgrade head
echo "Starting szurubooru API on port ${PORT}"
exec hupper -m waitress --port ${PORT} szurubooru.facade:app

View File

@ -162,4 +162,18 @@ def create_app() -> Callable[[Any, Any], Any]:
return rest.application return rest.application
if int(os.getenv("DEBUG", 0)) != 0:
try:
import debugpy
except ModuleNotFoundError:
raise RuntimeError("debugpy is not installed")
# TODO: These print statements don't show up in our docker output. Why is that?
logging.info("debugpy listening on port 5678")
debugpy.listen(("0.0.0.0", 5678))
if int(os.getenv("WAIT_FOR_CLIENT", 0)) != 0:
logging.info("Waiting for debugger attach")
debugpy.wait_for_client()
app = create_app() app = create_app()