Here is what worked for me to install Discourse on an isolated CentOS 7 server. In a nutshell, on a machine with internet access I prepared:
- the Git repos that Discourse setup needs:
SamSaffron/pups
,discourse/discourse
,discourse/discourse_docker
anddiscourse/docker_manager
. - the two Docker images:
discourse/base
andsamsaffron/docker-gc
- the complete Ruby Gem cache that
bundle install
downloads during bootstrap.
I copied these to the isolated server, and used them to install offline; below are the full details.I hope this helps.
1. Preparation on a machine with internet access
With Docker-CE and Git installed, run these commands:
mkdir -p ~/local/github.com
mkdir -p ~/local/rubygems.org
mkdir -p ~/local/docker-images
# 1
git clone --bare https://github.com/SamSaffron/pups.git ~/local/github.com/SamSaffron/pups.git
git clone --bare https://github.com/discourse/discourse.git ~/local/github.com/discourse/discourse.git
git clone --bare https://github.com/discourse/discourse_docker.git ~/local/github.com/discourse/discourse_docker.git
git clone --bare https://github.com/discourse/docker_manager.git ~/local/github.com/discourse/docker_manager.git
#2
sudo mkdir -p /var/discourse
sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
Step #1 clones the required Discourse GitHub repositories locally.
Step #2 prepares for the local installation of Discourse, which must run once, to extract Ruby GEMs from the Discourse image (step #4 below).
Search /var/discourse/launcher
to find the line starting with image=discourse/base
e.g.:
image=discourse/base:2.0.20171008
Two Docker images are needed: discourse/base
with the version above, and docker-gc
. To get them locally, run:
#3
docker pull discourse/base:2.0.20171008
docker pull samsaffron/docker-gc
docker save -o ~/local/docker-images/discourse_base discourse/base:2.0.20171008
docker save -o ~/local/docker-images/docker-gc samsaffron/docker-gc
Step #3 downloads the images and exports them to files under ~/local/docker-images/
.
The ~/local
folder now has local copies of the Discourse code, and Docker images required for installation.
However, local copies of the Ruby GEMs that Discourse downloads as part of its bootstrap process are still needed. IMHO it would be much easier if they were just included in the discourse/base
Docker image.
Discourse needs to be bootstrapped to get these files. Follow the official instructions, but stop at the Start Discourse step. That is, configure and bootstrap Discourse, up to the point where the Docker container local_discourse/app
is created.
Then run the following commands:
# 4
docker run -it -v ~/local/rubygems.org:/local-rubygems local_discourse/app /bin/bash
# the commands below run inside the Discourse 'app' container
cp -r /var/www/discourse/vendor/bundle/ruby /local-rubygems
exit
Step #4 copies the full Ruby GEM cache out of the Discourse image into the ~/local/rubygems.org
folder.
Now everything required to set up Discourse offline is available in the ~/local
folder. Copy this folder to the target machine.
2. Install Discourse on the target machine, with no internet access
Copy the ~/local
folder prepared above to the target machine that has no internet access, e.g. to /root/local
.
You will need to be root
through the rest of the setup and bootstrap process:
sudo -s
Import the two Docker images:
docker load -i /root/local/docker-images/discourse_base
docker load -i /root/local/docker-images/docker-gc
Configure Git to use the /root/local/github.com/
folder instead of going out to https://github.com/
:
git config --global url."file:///root/local/github.com/".insteadOf https://github.com/
Create the Discourse folder and clone discourse_docker.git
there:
mkdir -p /var/discourse
git clone https://github.com/discourse/discourse_docker.git /var/discourse/
Run ./discourse-setup
to generate your Discourse configuration. At the end of the configuration process, when you see the message Updates successful. Rebuilding in 5 seconds., press Ctrl+C
.
cd /var/discourse/
./discourse-setup
Edit the /var/discourse/launcher
file and disable updating pups
(the version bundled with Discourse will be used instead), changing from:
if [[ ! "false" = $update_pups ]]; then
run_command="$run_command git pull &&"
fi
to:
# if [[ ! "false" = $update_pups ]]; then
# run_command="$run_command git pull &&"
# fi
Edit the /var/discourse/containers/app.yml
file and update the volumes
section as follows:
volumes:
# these two volumes are already defined
- volume:
host: /var/discourse/shared/standalone
guest: /shared
- volume:
host: /var/discourse/shared/standalone/log/var-log
guest: /var/log
# ADD THE TWO VOLUMES BELOW, making the local copies of github.com repos and Ruby GEM cache
# available inside the Discourse container when it is built
- volume:
host: /root/local/github.com
guest: /local-github.com
- volume:
host: /root/local/rubygems.org
guest: /local-rubygems.org
This makes the local GitHub repo clones, and the Ruby GEM cache, available to the Discourse container.
Edit the /var/discourse/templates/web.template.yml
file, and make the following changes.
(1) Disable updating Bundler (using the version bundled with Discourse instead) by commenting-out the gem update bundler
line, from:
- exec:
cd: $home
hook: web
cmd:
# ensure we are on latest bundler
- gem update bundler
- chown -R discourse $home
to:
- exec:
cd: $home
hook: web
cmd:
# ensure we are on latest bundler
#- gem update bundler
- git config --global url."file:///local-github.com/".insteadOf https://github.com/
- chown -R discourse $home
Instead of updating bundler, Git (the one inside the container) is configured to use the local folder instead of going out to https://github.com/
.
(2) Configure bundle install
to use the local Ruby GEM cache and not connect to rubygems.org
by changing these lines from:
- exec:
cd: $home
hook: bundle_exec
cmd:
- su discourse -c 'bundle install --deployment --verbose --without test --without development'
- su discourse -c 'bundle exec rake db:migrate'
- su discourse -c 'bundle exec rake assets:precompile'
to:
- exec:
cd: $home
hook: bundle_exec
cmd:
# copy the locally-cached Ruby GEMS to /var/www/discourse/vendor/...
- cp -rv /local-rubygems.org/ $home/vendor/bundle/ruby/
# install GEMs from local cache only, using `--local` (see http://bundler.io/v1.15/bundle_install.html)
- su discourse -c 'bundle install --local --deployment --verbose --without test --without development'
- su discourse -c 'bundle exec rake db:migrate'
- su discourse -c 'bundle exec rake assets:precompile'
And that’s it. Run ./launcher bootstrap app
and, hopefully, enjoy your offline Discourse!