Disable CDN causes old images with CDN URL can not be shown

I’ve just disabled CDN to save the cost. However, all the old images, which is uploaded while I was using cloudfront, are failed to load.

For example:

I have CDN URL is cdn.mydomain.com. After disabling CDN, the cdn.mydomain.com is invalid so that all the images should start with mydomain.com instead.

Is there anyway to convert all those urls programmatically?


Note: I am going to use S3 to store all my images. Can I just make use of this opportunity to convert everything from cdn to s3 url?

You will need to rebake all your post to update the urls. There are 2 ways of doing it:

The low-CPU usage but slow way

# ssh into server
cd /var/discourse
./launcher enter app
rails c
Post.update_all(baked_version: nil)

The high-CPU usage but faster way

# ssh into server
cd /var/discourse
./launcher enter app
rake posts:rebake
4 Likes

I tried your post here

https://meta.discourse.org/t/disabled-cdn-emoji-picture-url-error/20878/2?u=trandatnh

But I received this error:

rake posts:rebake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)

(See full trace by running task with --trace)

I think it is because the answer was very old.

I added --trace

root@daynhauhoc:/var/discourse# rake posts:rebake --trace
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/lib/ruby/vendor_ruby/rake/application.rb:584:in `raw_load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:89:in `block in load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:88:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:72:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:70:in `run'
/usr/bin/rake:27:in `<main>'

You need to run that command from inside the container (via ./launcher enter app)

2 Likes

I ran the command but I got this error

root@daynhauhoc:/var/discourse# ./launcher enter app
Error: Command not found: exec
Error: Command not found: -it
Usage: docker [OPTIONS] COMMAND [arg...]

I am using v1.4.0.beta1 +4. I used to be able to rake last time when I migrated from S3 to local. I think docker is up to date outdated.

root@daynhauhoc:/var/discourse# git pull
Already up-to-date.
root@daynhauhoc:/var/discourse# ./launcher rebuild app
Ensuring discourse docker is up to date
Fetching origin
Discourse Docker is up-to-date

I’ve just temporary upgraded Digital Ocean droplet to higher plan using flexible resize feature because I think the rake will take a lot of CPU usage. But I don’t think resizing the droplet causes any issue with docker.

I am using docker 1.2

root@daynhauhoc:/var/discourse# docker -v
Docker version 1.2.0, build fa7b24f

Upgraded to 1.6

apt-get install lxc-docker
root@daynhauhoc:/var# docker -v
Docker version 1.6.2, build 7c8fca2

Update 1 Successfully enter app and raking

root@daynhauhoc:/# rake posts:rebake
Rebaking post markdown for 'default'
      943 / 35451 (  2.7%)

Update 2 All the images are OK now. Thank @zogstrip :+1:

5 Likes