From 47dc83eed8d8c9f046d8a6e591dc95c722347c82 Mon Sep 17 00:00:00 2001 From: Rogerio Lino Date: Mon, 9 Jun 2025 14:35:54 -0300 Subject: [PATCH] feat: Creating image for v2.2 with cron support --- .github/workflows/docker.yaml | 5 +- novosga-2.0/README.md | 60 +--------------- novosga-2.1/README.md | 69 ++----------------- novosga-2.2-standalone/Dockerfile | 37 ++++++++++ novosga-2.2-standalone/README.md | 31 +++++++++ novosga-2.2-standalone/config/crontab | 2 + .../config/supervisord.conf | 32 +++++++++ novosga-2.2-standalone/start.sh | 29 ++++++++ 8 files changed, 144 insertions(+), 121 deletions(-) create mode 100644 novosga-2.2-standalone/Dockerfile create mode 100644 novosga-2.2-standalone/README.md create mode 100644 novosga-2.2-standalone/config/crontab create mode 100644 novosga-2.2-standalone/config/supervisord.conf create mode 100755 novosga-2.2-standalone/start.sh diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index fbd8cc4..5b30acd 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -7,7 +7,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ['2.0', '2.1'] + version: + - '2.0' + - '2.1' + - '2.2-standalone' steps: - name: Git Checkout uses: actions/checkout@v3 diff --git a/novosga-2.0/README.md b/novosga-2.0/README.md index a6348d9..a07f60f 100644 --- a/novosga-2.0/README.md +++ b/novosga-2.0/README.md @@ -30,62 +30,6 @@ You can set the system as you like with environment variables (using docker-comp | NOVOSGA_PLACE_NAME | Box | Place name | yes | | TZ | UTC | Timezone | yes | -### CLI +## Documentation -Minimal setting: - -```shell - docker container run [--rm|-d] \ - -p 80:80 -p 2020:2020 - -e DATABASE_URL="connection_string" \ - novosga/novosga:latest -``` - -### Compose file - -```yaml -version: '2' - -services: - novosga: - image: novosga/novosga:latest - restart: always - depends_on: - - mysqldb - ports: - - "80:80" - - "2020:2020" - environment: - APP_ENV: 'prod' - # database connection - DATABASE_URL: 'mysql://novosga:MySQL_App_P4ssw0rd!@mysqldb:3306/novosga2?charset=utf8mb4&serverVersion=5.7' - # default admin user - NOVOSGA_ADMIN_USERNAME: 'admin' - NOVOSGA_ADMIN_PASSWORD: '123456' - NOVOSGA_ADMIN_FIRSTNAME: 'Administrator' - NOVOSGA_ADMIN_LASTNAME: 'Global' - # default unity - NOVOSGA_UNITY_NAME: 'My Unity' - NOVOSGA_UNITY_CODE: 'U01' - # default no-priority - NOVOSGA_NOPRIORITY_NAME: 'Normal' - NOVOSGA_NOPRIORITY_DESCRIPTION: 'Normal service' - # default priority - NOVOSGA_PRIORITY_NAME: 'Priority' - NOVOSGA_PRIORITY_DESCRIPTION: 'Priority service' - # default place - NOVOSGA_PLACE_NAME: 'Box' - # Set TimeZone and locale - TZ: 'America/Sao_Paulo' - LANGUAGE: 'pt_BR' - mysqldb: - image: mysql:5.7 - restart: always - environment: - MYSQL_USER: 'novosga' - MYSQL_DATABASE: 'novosga2' - MYSQL_ROOT_PASSWORD: 'MySQL_r00t_P4ssW0rd!' - MYSQL_PASSWORD: 'MySQL_App_P4ssw0rd!' - # Set TimeZone - TZ: 'America/Sao_Paulo' -``` +https://novosga.org/docs/#/2.0/install-docker diff --git a/novosga-2.1/README.md b/novosga-2.1/README.md index 8f124ae..d6e41b3 100644 --- a/novosga-2.1/README.md +++ b/novosga-2.1/README.md @@ -1,10 +1,11 @@ # NovoSGA 2.1 ## Docker image milestones -[x] Pre-flight check -[x] Auto setup -[x] Daily ticket reset at 1am -[ ] docker secrets support + +- [x] Pre-flight check +- [x] Auto setup +- [x] Daily ticket reset at 1am +- [ ] docker secrets support ## How to use @@ -29,62 +30,6 @@ You can set the system as you like with environment variables (using docker-comp | NOVOSGA_PLACE_NAME | Box | Place name | yes | | TZ | UTC | Timezone | yes | -### CLI - -Minimal setting: - -```shell - docker container run [--rm|-d] \ - -p 80:80 -p 2020:2020 - -e DATABASE_URL="connection_string" \ - novosga/novosga:latest -``` - -### Compose file - -```yaml -version: '2' +## Documentation -services: - novosga: - image: novosga/novosga:2.1 - restart: always - depends_on: - - mysqldb - ports: - - "80:80" - - "2020:2020" - environment: - APP_ENV: 'prod' - # database connection - DATABASE_URL: 'mysql://novosga:MySQL_App_P4ssw0rd!@mysqldb:3306/novosga2?charset=utf8mb4&serverVersion=5.7' - # default admin user - NOVOSGA_ADMIN_USERNAME: 'admin' - NOVOSGA_ADMIN_PASSWORD: '123456' - NOVOSGA_ADMIN_FIRSTNAME: 'Administrator' - NOVOSGA_ADMIN_LASTNAME: 'Global' - # default unity - NOVOSGA_UNITY_NAME: 'My Unity' - NOVOSGA_UNITY_CODE: 'U01' - # default no-priority - NOVOSGA_NOPRIORITY_NAME: 'Normal' - NOVOSGA_NOPRIORITY_DESCRIPTION: 'Normal service' - # default priority - NOVOSGA_PRIORITY_NAME: 'Priority' - NOVOSGA_PRIORITY_DESCRIPTION: 'Priority service' - # default place - NOVOSGA_PLACE_NAME: 'Box' - # Set TimeZone and locale - TZ: 'America/Sao_Paulo' - LANGUAGE: 'pt_BR' - mysqldb: - image: mysql:5.7 - restart: always - environment: - MYSQL_USER: 'novosga' - MYSQL_DATABASE: 'novosga2' - MYSQL_ROOT_PASSWORD: 'MySQL_r00t_P4ssW0rd!' - MYSQL_PASSWORD: 'MySQL_App_P4ssw0rd!' - # Set TimeZone - TZ: 'America/Sao_Paulo' -``` +https://novosga.org/docs/#/2.1/install-docker diff --git a/novosga-2.2-standalone/Dockerfile b/novosga-2.2-standalone/Dockerfile new file mode 100644 index 0000000..4bfd841 --- /dev/null +++ b/novosga-2.2-standalone/Dockerfile @@ -0,0 +1,37 @@ +FROM novosga/novosga:2.2 + +#Set the default parameters +ENV APP_ENV=prod \ + LANGUAGE=pt_BR \ + NOVOSGA_ADMIN_USERNAME="admin" \ + NOVOSGA_ADMIN_PASSWORD="123456" \ + NOVOSGA_ADMIN_FIRSTNAME="Administrador" \ + NOVOSGA_ADMIN_LASTNAME="Global" \ + NOVOSGA_UNITY_NAME="Minha Unidade" \ + NOVOSGA_UNITY_CODE="U01" \ + NOVOSGA_NOPRIORITY_NAME="Normal" \ + NOVOSGA_NOPRIORITY_DESCRIPTION="Serviço normal" \ + NOVOSGA_PRIORITY_NAME="Prioridade" \ + NOVOSGA_PRIORITY_DESCRIPTION="Serviço prioritário" \ + NOVOSGA_PLACE_NAME="Guichê" + +USER root + +# https://github.com/aptible/supercronic/releases/tag/v0.2.33 +ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.33/supercronic-linux-amd64 \ + SUPERCRONIC_SHA1SUM=71b0d58cc53f6bd72cf2f293e09e294b79c666d8 \ + SUPERCRONIC=supercronic-linux-amd64 + +RUN curl -fsSLO "$SUPERCRONIC_URL" \ + && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \ + && chmod +x "$SUPERCRONIC" \ + && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ + && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic + +COPY start.sh /usr/local/bin +COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY config/crontab /etc/crontab + +USER nobody + +CMD ["start.sh"] diff --git a/novosga-2.2-standalone/README.md b/novosga-2.2-standalone/README.md new file mode 100644 index 0000000..87e34d8 --- /dev/null +++ b/novosga-2.2-standalone/README.md @@ -0,0 +1,31 @@ +# NovoSGA 2.2 + +## Docker image milestones + +- [x] Pre-flight check +- [x] Auto setup +- [x] Daily ticket reset at 1am +- [ ] docker secrets support + +## How to use + +The container will check if the required settings are set and will start the database setup automatically. +You can set the system as you like with environment variables (using docker-compose.yml or `-e` flags at `docker container run`) + +### Settings (environment variables) + +| Option | Default setting | Description | Optional? | +| ------------------------------ | ----------------- | -------------------------------- | :-------: | +| APP_ENV | prod | Environment running the app | yes | +| DATABASE_URL | *blank* | Database connection string | ***no*** | +| NOVOSGA_ADMIN_USERNAME | admin | Admin username | yes | +| NOVOSGA_ADMIN_PASSWORD | 123456 | Admin password | yes | +| NOVOSGA_ADMIN_FIRSTNAME | Administrator | Administrator first name | yes | +| NOVOSGA_ADMIN_LASTNAME | Global | Administrador last name | yes | +| NOVOSGA_UNITY_NAME | My Unity | Unity name | yes | +| NOVOSGA_UNITY_CODE | U01 | Unity code | yes | +| NOVOSGA_NOPRIORITY_DESCRIPTION | Normal service | Non-Priority service description | yes | +| NOVOSGA_PRIORITY_NAME | Priority | Priority service name | yes | +| NOVOSGA_PRIORITY_DESCRIPTION | Priority service | Priority service description | yes | +| NOVOSGA_PLACE_NAME | Box | Place name | yes | +| TZ | UTC | Timezone | yes | diff --git a/novosga-2.2-standalone/config/crontab b/novosga-2.2-standalone/config/crontab new file mode 100644 index 0000000..1b72701 --- /dev/null +++ b/novosga-2.2-standalone/config/crontab @@ -0,0 +1,2 @@ +# m h dom mon dow command +0 1 * * * /var/www/html/bin/console novosga:reset diff --git a/novosga-2.2-standalone/config/supervisord.conf b/novosga-2.2-standalone/config/supervisord.conf new file mode 100644 index 0000000..29cde45 --- /dev/null +++ b/novosga-2.2-standalone/config/supervisord.conf @@ -0,0 +1,32 @@ +[supervisord] +nodaemon=true +logfile=/dev/null +logfile_maxbytes=0 +pidfile=/run/supervisord.pid + +[program:php-fpm] +command=php-fpm82 -F +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0 + +[program:nginx] +command=nginx -g 'daemon off;' +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0 + +[program:supercronic] +command=supercronic /etc/crontab +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=false +startretries=0 diff --git a/novosga-2.2-standalone/start.sh b/novosga-2.2-standalone/start.sh new file mode 100755 index 0000000..2794f0d --- /dev/null +++ b/novosga-2.2-standalone/start.sh @@ -0,0 +1,29 @@ +#!/bin/sh +echo "Starting pre-flight check..." + +echo -n "Database url: " +if [ -z "$DATABASE_URL" ]; then + echo "\nYou need to tell me where the database is and how to connect to it by setting DATABASE_URL environment variable" + echo "e.g.: Using the flag -e DATABASE_URL='mysql://user:pass@127.0.0.1:3306/dbname?charset=utf8mb4&serverVersion=5.7' at docker container run" + exit 1 +fi +echo "Ok" + +bin/console cache:clear --no-debug --no-warmup +bin/console cache:warmup + +# we need to wait until the database is up and accepting connections +until bin/console -q doctrine:query:sql "select version()" > /dev/null 2>&1; do + echo "Waiting for database..."; + sleep 5; +done + +echo "Database is up, configuring schema" + +set -xe + +# Install/Updates the database schema +bin/console novosga:install + +echo "Setup done! Starting application" +exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf