Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Improve sharp failure fallback #20174

Closed
1 task done
SaadBazaz opened this issue May 9, 2024 · 1 comment
Closed
1 task done

[fix] Improve sharp failure fallback #20174

SaadBazaz opened this issue May 9, 2024 · 1 comment

Comments

@SaadBazaz
Copy link

SaadBazaz commented May 9, 2024

Issue Summary

Summary

I've been racking my head around why my Ghost container on Docker doesn't upload images correctly. A lot of forums pointed out the issue could be with the sharp installation, so I did the following:

  1. Installed older versions of sharp: Versions like 0.24, 0.23, etc with no success. Got tonnes of C++ and Python errors
  2. Disabled imageOptimization in config.production.json

After some debugging, turns out the host machine I was running Ghost on (a beatdown Lenovo Ideapad z575, with Quad Core 1.40GHz AMD A6-3400M Processor) had an extremely old CPU architecture which was not supported by sharp, specially the versions compatible with Ghost.

What to do

I think there should be a more graceful fallback for sharp. I mean, if I don't really want to use it, I should have the option to totally purge it. Plus, it should be able to handle any sort of such issue. Perhaps a try-catch.

Also, if I've disabled imageOptimisation, why does Ghost still try to fetch images of different sizes in production?

Steps to Reproduce

  1. Install docker compose of Ghost on a CPU of old architecture:
services:
  ghost:
    image: 'ghost:5'
    volumes:
      - 'ghost-content-data:/var/lib/ghost/content'
    environment:
      - url=$COMPLETE_FQDN_GHOST
      - database__client=mysql
      - database__connection__host=mysql
      - database__connection__user=$SERVICE_USER_MYSQL
      - database__connection__password=$SERVICE_PASSWORD_MYSQL
      - 'database__connection__database=${MYSQL_DATABASE-ghost}'
      - mail__transport=SMTP
      - 'mail__options__auth__pass=${MAIL_OPTIONS_AUTH_PASS}'
      - 'mail__options__auth__user=${MAIL_OPTIONS_AUTH_USER}'
      - 'mail__options__secure=${MAIL_OPTIONS_SECURE:-true}'
      - 'mail__options__port=${MAIL_OPTIONS_PORT:-465}'
      - 'mail__options__service=${MAIL_OPTIONS_SERVICE:-Mailgun}'
      - 'mail__options__host=${MAIL_OPTIONS_HOST}'
    depends_on:
      mysql:
        condition: service_healthy
    healthcheck:
      test:
        - CMD
        - echo
        - ok
      interval: 5s
      timeout: 20s
      retries: 10
  mysql:
    image: 'mysql:8.0'
    volumes:
      - 'ghost-mysql-data:/var/lib/mysql'
    environment:
      - 'MYSQL_USER=${SERVICE_USER_MYSQL}'
      - 'MYSQL_PASSWORD=${SERVICE_PASSWORD_MYSQL}'
      - 'MYSQL_DATABASE=${MYSQL_DATABASE}'
      - 'MYSQL_ROOT_PASSWORD=${SERVICE_PASSWORD_MYSQLROOT}'
    healthcheck:
      test:
        - CMD
        - mysqladmin
        - ping
        - '-h'
        - localhost
      interval: 5s
      timeout: 20s
      retries: 10
  1. Enter the docker container's bash, and nano config.production.json. Change imageOptimization to false
  2. Upload an image from Ghost Admin ------> SUCCESSFUL
  3. Now when you try viewing that image on the actual live site ------> Entire blog crashes

Ghost Version

5.82.2

Node.js Version

18.20.2

How did you install Ghost?

Docker on Ubuntu 22.04.4 LTS, Lenovo IdeaPad Z575 (https://www.bhphotovideo.com/c/product/793706-REG/Lenovo_129925U_IdeaPad_Z575_15_6_Notebook.html)

Database type

MySQL 5.7

Browser & OS version

No response

Relevant log / error output

No log errors. The blog just crashes.
When I went into the docker container's bash, and ran sharp directly, it gave me "illegal instruction (core dumped)", which made me believe that sharp wasn't built for my CPU's architecture.

Code of Conduct

  • I agree to be friendly and polite to people in this repository
@github-actions github-actions bot added the needs:triage [triage] this needs to be triaged by the Ghost team label May 9, 2024
@SaadBazaz
Copy link
Author

I've found a temporary workaround, after going through some of Ghost's code. It seems like there is a check which prevents sharp from running at all, here.

So the solution was to:

  1. Enter the docker container
  2. cd ./current
  3. Run yarn remove sharp, and then,
  4. Run rm -rf node_modules/sharp
    To completely uninstall and clean sharp.

You would also need to add this to config.production.json:

{
   ...
   imageOptimisation: false
}

Doing the above completely disabled sharp and now allows me to upload images (albeit, the images are a bit large, but I can make do :D)

@github-actions github-actions bot removed the needs:triage [triage] this needs to be triaged by the Ghost team label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant