From bf5745ec7273b3eb232effba73a4eda7356fdcd6 Mon Sep 17 00:00:00 2001 From: alufers Date: Wed, 30 Aug 2023 17:11:42 +0200 Subject: [PATCH] Add pre-commit and fix syntax problems --- .github/workflows/build-docker-image.yml | 2 +- .pre-commit-config.yaml | 26 +++++++++++++ .yamllint | 12 ++++++ Dockerfile | 4 +- README.md | 3 +- configs/php.ini | 2 +- scripts/startup.sh | 49 +++++++++++++----------- 7 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 27ce21a..d6761f1 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -20,7 +20,7 @@ jobs: permissions: contents: read packages: write - # + # steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6c2ff45 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-json + - id: detect-private-key + - id: fix-encoding-pragma + - id: check-merge-conflict + - id: check-added-large-files + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.32.0 + hooks: + - id: yamllint + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.35.0 + hooks: + - id: markdownlint-fix + - id: markdownlint + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.9.0 + hooks: + - id: shellcheck + diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8c09765 --- /dev/null +++ b/.yamllint @@ -0,0 +1,12 @@ +extends: default +yaml-files: + - "*.yaml" + - "*.yml" + - ".yamllint" +rules: + line-length: disable + document-start: disable + truthy: disable + brackets: disable + comments: disable + colons: disable diff --git a/Dockerfile b/Dockerfile index c7b3753..9f3e524 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,14 +10,14 @@ ARG PHORGE_SHA=98dfac53ba721467a32b96641f3a18d428fb5441 ARG ARCANIST_SHA=788098096e113f34f0fafef23e4d16a2e80d64ca -ENV GIT_USER=git +ENV GIT_USER=git ENV MYSQL_PORT=3306 ENV PROTOCOL=http EXPOSE 80 443 -# TODO: Once Phorge is updated to support PHP 8.0, +# TODO: Once Phorge is updated to support PHP 8.0, # we can use PHP from debian repo instead of sury.org RUN apt-get update -y && apt-get install -y wget lsb-release && \ diff --git a/README.md b/README.md index 9edaf5a..e36b523 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # README -Dockerfile for running Phorge in a container. Based on: https://github.com/cooperspencer/phorge +Dockerfile for running Phorge in a container. Based on: ## Differences from the original Dockerfile @@ -8,4 +8,3 @@ Dockerfile for running Phorge in a container. Based on: https://github.com/coope - Remove ssh server support - Fetch Phorge commits by sha instead of downloading the latest one at build time - Add mysql configuration as per Phorge suggestions - diff --git a/configs/php.ini b/configs/php.ini index bf6ade6..4683dd0 100644 --- a/configs/php.ini +++ b/configs/php.ini @@ -363,7 +363,7 @@ zend.enable_gc = On ; Allows to include or exclude arguments from stack traces generated for exceptions ; Default: Off -; In production, it is recommended to turn this setting on to prohibit the output +; In production, it is recommended to turn this setting on to prohibit the output ; of sensitive information in stack traces zend.exception_ignore_args = On diff --git a/scripts/startup.sh b/scripts/startup.sh index f3e769d..f0ec2ac 100644 --- a/scripts/startup.sh +++ b/scripts/startup.sh @@ -6,20 +6,20 @@ set -e if id "$GIT_USER" >/dev/null 2>&1; then echo "user $GIT_USER already exists" else - useradd $GIT_USER - usermod -p NP $GIT_USER + useradd "$GIT_USER" + usermod -p NP "$GIT_USER" echo "$GIT_USER ALL=(daemon) SETENV: NOPASSWD: /bin/ls, /usr/bin/git, /usr/bin/git-upload-pack, /usr/bin/git-receive-pack, /usr/bin/ssh" >> /etc/sudoers - chown -R $GIT_USER /var/repo - /var/www/phorge/phorge/bin/config set phd.user $GIT_USER - /var/www/phorge/phorge/bin/config set diffusion.ssh-user $GIT_USER + chown -R "$GIT_USER" /var/repo + /var/www/phorge/phorge/bin/config set phd.user "$GIT_USER" + /var/www/phorge/phorge/bin/config set diffusion.ssh-user "$GIT_USER" fi /var/www/phorge/phorge/bin/config set files.enable-imagemagick true #DB configuration -/var/www/phorge/phorge/bin/config set mysql.host $MYSQL_HOST -/var/www/phorge/phorge/bin/config set mysql.port $MYSQL_PORT -/var/www/phorge/phorge/bin/config set mysql.user $MYSQL_USER +/var/www/phorge/phorge/bin/config set mysql.host "$MYSQL_HOST" +/var/www/phorge/phorge/bin/config set mysql.port "$MYSQL_PORT" +/var/www/phorge/phorge/bin/config set mysql.user "$MYSQL_USER" # if MYSQL_PASSWORD is empty, use check MYSQL_PASSWORD_FILE if [ -z "$MYSQL_PASSWORD" ] @@ -29,43 +29,46 @@ then echo "MYSQL_PASSWORD or MYSQL_PASSWORD_FILE must be set" exit 1 else - MYSQL_PASSWORD=$(cat $MYSQL_PASSWORD_FILE) + MYSQL_PASSWORD=$(cat "$MYSQL_PASSWORD_FILE") fi fi -/var/www/phorge/phorge/bin/config set mysql.pass $MYSQL_PASSWORD +/var/www/phorge/phorge/bin/config set mysql.pass "$MYSQL_PASSWORD" /var/www/phorge/phorge/bin/config set diffusion.allow-http-auth true if [ "$PROTOCOL" == "https" ] then + + # We want to output PHP + # shellcheck disable=SC2016 echo ' /var/www/phorge/phorge/support/preamble.php fi #Large file storage configuration -if [ ! -z "$MINIO_SERVER" ] +if [ -n "$MINIO_SERVER" ] then - /var/www/phorge/phorge/bin/config set storage.s3.bucket $MINIO_BUCKET - if [ ! -z "$MINIO_SERVER_SECRET_KEY_FILE" ] + /var/www/phorge/phorge/bin/config set storage.s3.bucket "$MINIO_BUCKET" + if [ -n "$MINIO_SERVER_SECRET_KEY_FILE" ] then - MINIO_SERVER_SECRET_KEY=$(cat $MINIO_SERVER_SECRET_KEY_FILE) + MINIO_SERVER_SECRET_KEY=$(cat "$MINIO_SERVER_SECRET_KEY_FILE") fi - if [ ! -z "$MINIO_SERVER_ACCESS_KEY_FILE" ] - then`aa` - MINIO_SERVER_ACCESS_KEY=$(cat $MINIO_SERVER_ACCESS_KEY_FILE) + if [ -n "$MINIO_SERVER_ACCESS_KEY_FILE" ] + then + MINIO_SERVER_ACCESS_KEY=$(cat "$MINIO_SERVER_ACCESS_KEY_FILE") fi - /var/www/phorge/phorge/bin/config set amazon-s3.secret-key $MINIO_SERVER_SECRET_KEY - /var/www/phorge/phorge/bin/config set amazon-s3.access-key $MINIO_SERVER_ACCESS_KEY - /var/www/phorge/phorge/bin/config set amazon-s3.endpoint $MINIO_SERVER:$MINIO_PORT + /var/www/phorge/phorge/bin/config set amazon-s3.secret-key "$MINIO_SERVER_SECRET_KEY" + /var/www/phorge/phorge/bin/config set amazon-s3.access-key "$MINIO_SERVER_ACCESS_KEY" + /var/www/phorge/phorge/bin/config set amazon-s3.endpoint "$MINIO_SERVER:$MINIO_PORT" # /var/www/phorge/phorge/bin/config set amazon-s3.region us-west-1 fi -if [ ! -z "$MAILERS_CONFIG_FILE" ] +if [ -n "$MAILERS_CONFIG_FILE" ] then - /var/www/phorge/phorge/bin/config set cluster.mailers --stdin < $MAILERS_CONFIG_FILE + /var/www/phorge/phorge/bin/config set cluster.mailers --stdin < "$MAILERS_CONFIG_FILE" else - if [ ! -z "$SMTP_SERVER" ] && [ ! -z "$SMTP_PORT" ] && [ ! -z "$SMTP_USER" ] && [ ! -z "$SMTP_PASSWORD" ] && [ ! -z "$SMTP_PROTOCOL" ] + if [ -n "$SMTP_SERVER" ] && [ -n "$SMTP_PORT" ] && [ -n "$SMTP_USER" ] && [ -n "$SMTP_PASSWORD" ] && [ -n "$SMTP_PROTOCOL" ] then echo "[ {