Installer Discourse pour le développement avec Docker

Développer avec Docker

Puisque Discourse s’exécute dans Docker, vous devriez être en mesure d’exécuter Discourse directement à partir de votre répertoire source en utilisant un conteneur de développement Discourse.

:white_check_mark: Avantages : Aucun besoin d’installer de dépendances système, aucune configuration nécessaire pour configurer rapidement un environnement de développement.

:x: Inconvénients : Sera légèrement plus lent que l’environnement de développement natif sur Ubuntu, et beaucoup plus lent qu’une installation native sur MacOS.

Voir aussi Developing Discourse using a Dev Container

Étape 1 : Installer Docker

Ubuntu

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce

19.10

sudo apt-get install docker.io
sudo usermod -a -G docker $USER
sudo reboot

Windows WSL : Ubuntu

Vous pouvez exécuter les commandes ci-dessus dans WSL mais vous devez avoir tous les fichiers à l’intérieur du système de fichiers WSL. Par exemple, cela fonctionne très bien si c’est à l’intérieur de ~/discourse mais cela échoue si c’est placé à l’intérieur de /mnt/c/discourse.

MacOS

:warning: L’image docker de développement Discourse n’est disponible que pour les architectures x86_64. Les Mac M1 sont capables de démarrer l’image en utilisant l’émulation d’architecture, mais il est peu probable que Discourse démarre en raison du manque de support inotify dans QEMU.

Vous devriez plutôt utiliser Install Discourse on macOS for development

Option 1 : Télécharger un .dmg packagé depuis le Docker store
Option 2 : brew install docker

Étape 2 : Démarrer le Conteneur

Clonez le dépôt Discourse sur votre appareil local.

git clone https://github.com/discourse/discourse.git
cd discourse

(depuis la racine de votre source)

d/boot_dev --init
    # attendez pendant que :
    #   - les dépendances sont installées,
    #   - la base de données est migrée, et
    #   - un utilisateur administrateur est créé (vous devrez interagir avec celui-ci)

# Dans un terminal :
d/rails s

# Et dans un terminal séparé
d/ember-cli

…puis ouvrez un navigateur sur http://localhost:4200 et voilà !, vous devriez voir Discourse.

Liens symboliques des Plugins

Le flux de développement Docker prend en charge les liens symboliques sous le répertoire plugins/, avec la mise en garde suivante :

Chaque fois qu’un nouveau lien symbolique de plugin est créé, le conteneur Docker doit être redémarré avec :

d/shutdown_dev; d/boot_dev

Notes :

  • Pour tester les e-mails, exécutez MailHog :

    d/mailhog
    
  • S’il manque des gems, exécutez :

    d/bundle install
    
  • Si une migration de base de données est nécessaire :

    d/rake db:migrate RAILS_ENV=development
    
  • Lorsque vous avez terminé, vous pouvez choisir de tuer le conteneur Docker avec :

    d/shutdown_dev
    
  • Les données sont persistantes entre les invocations du conteneur dans le répertoire tmp/postgres de votre racine source. Si pour une raison quelconque vous souhaitez réinitialiser votre base de données, exécutez :

    sudo rm -fr data
    
  • Si vous voyez des erreurs comme “permission denied while trying to connect to Docker”, exécutez :

    run `sudo usermod -aG docker ${USER}`
    sudo service docker restart
    
  • Si vous souhaitez exposer globalement les ports du conteneur au réseau (désactivé par défaut) utilisez :

    d/boot_dev -p
    
  • Le Dockerfile provient de discourse/discourse_docker sur GitHub, en particulier image/discourse_dev.

Exécution des Tests

d/rake autospec

Pour exécuter des tests de plugins spécifiques, vous pouvez également faire quelque chose comme ceci :

d/rake plugin:spec["discourse-follow"]

Ou même quelque chose comme ceci pour être encore plus spécifique :

my-machine:~/discourse$ d/shell
discourse@discourse:/src$ RAILS_ENV=test /src/bin/rspec plugins/discourse-follow/spec/lib/updater_spec.rb:37

Ce document est contrôlé par version - suggérez des modifications sur github.

72 « J'aime »
Using a launcher built docker image in docker-compose
IDE and comfortable DEV environment for newbies
Docker install on MacOS
Installing Discourse for macOS Development Using asdf and docker-compose
How to install Discourse locally?
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Discourse on local pc
Discourse developement environment setup
How to Install Discourse on LocalHost in Windows?
Unicode (Russian) username validation fails randomly
Qunit in Docker
Is it possible to use a local plugin directory with a docker install?
Is it possible to use a local plugin directory with a docker install?
Problem with development on Windows with Docker and mounted volume
[Resolved] Recent change breaks connectivity in Docker (+ non-Docker)
How might we better structure #howto?
Apple M1 for discourse development
How to open via internal IP?
Fast, efficient plugin development with Docker dev install (Windows WSL2)
How do I install a stable version of Discourse on Docker locally?
Backup fails on localhost with docker
How do I install a stable version of Discourse on Docker locally?
Problems with understanding the development of Discourse
Which is the better option to self-host?
Need to create custom static page as home page
Docker new licensing
Install Discourse Docker on Ubuntu 11
Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”
Install Discourse on macOS for development
Can't build Discourse on Ubuntu 20.10
Installing discourse for development is failing
Create, download, and restore a backup of your Discourse database
Set up a local Discourse Development Environment?
How do you install Discourse using Windows 10 Docker Desktop?
NoMethodError: undefined method `min_tags_from_required_group'
Adding command line tools support for user api keys
Install plugins in your non-Docker development environment
Adding command line tools support for user api keys
NoMethodError: undefined method `min_tags_from_required_group'
Error installing `bullseye-backports` when trying to install for Development
What I should do for migration from Cusdis to Discourse
Migrate a MyBB forum to Discourse
Local installation internal use only
Maintaining an up-to-date development environment
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
Docker-compose.yml to run discourse locally
Can't set up dev environment due to cppjieba_rb failing to install
Allow subscription of predetermined length
Cannot load any images “Uncaught (in promise) no-response: no-response”
Discovery document is missing
Discourse API developers docker-compose basic image
What are the benefits of a dev environment?
Installing Discourse on windows using Docker Desktop
Installing discourse follow plugin in development (boot_dev) setup — no app.yml file
How to troubleshoot database errors in an outdated plugin?
Error when building: discourse does not support compiling scss/sass files via sprockets
Integration into custom auth system where emails are not unique?
Contributing to Discourse development
Install Discourse on Ubuntu or Debian for Development
There was an error while trying to write to `/src/Gemfile.lock`. It is likely that you need to grant write permissions for that path
Availability of OpenID Connect in hosted plans
Tags rearranged, triggering an extra edit
Migrate a phpBB3 forum to Discourse
OAuth2 and Microsoft ADFS
Install Discourse for Development using Docker is Failed
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Install on macOS – Failure: Scheduler::Defer can pause and resume
Ember addons are resolving as incorrect peer dependencies. -- fixed by removing "content-tag@3.1.0": "patches/content-tag@3.1.0.patch",
Trying to install Discourse on portainer but it's not pulling the base container
Developing Discourse using a Dev Container
Subscribe to post an ad
Postgres doesn't seem to be running when running Discourse locally using Docker
Discourse OpenID Connect (OIDC)
Install on macOS – Failure: Scheduler::Defer can pause and resume
How can I install Discourse on Windows? Getting restarting (100) error
Stuck in infinite loop in Mac terminal after source ~/.bashrc
I want to install a plugin for development, what should I do?
Can't set up dev environment due to cppjieba_rb failing to install
Total newbie struggling to preview the signup modal with my test theme, what am I missing?
Configure Discourse to use a separate PostgreSQL server
`script/osx_dev` script is pretty broken
Issue in setup discourse on ubuntu server
Bundle install fails after adding gem "mysql2" and gem "reverse_markdown"
Using a launcher built docker image in docker-compose
Developing Discourse using a Dev Container
Can't uninstall on Ubuntu 18.04
I want to install a plugin for development, what should I do?
Without any coding knowledge, is it possible to install and maintain Discourse?
Using a launcher built docker image in docker-compose
Discourse redirects to the OAuth server after loading `/?authComplete=true`
Hello from Gitpod! (installing on google cloud + automated dev setup)

This is really easy to get set up! Thanks.

I’m surprised, however, by how slow the local installation is. Is there a way to adjust the container specs somehow? I’d expect a slowdown, but maybe not one so dramatic…

Thanks again.

7 « J'aime »

I’m trying to use Docker on Windows 10, and I have a question about the guide. I have Docker installed and it can run an ubuntu container (with basically nothing installed in the container). This docker guide just says to clone the repo next, but I can’t do that since the container doesn’t have git installed.

At this point, should I just follow the Ubuntu Guide and install all of the prerequisites in the container? Or should I be using the discourse_dev image referenced on Github? It seems like this guide is skipping over a lot of steps, but I’ve never used docker before so maybe I’m missing something.

4 « J'aime »

I think what is tripping you is that you are trying to clone the repo within the container, but the git clone should be done on your machine. So if you already have git installed locally, you are close to get it working.

3 « J'aime »

I actually did that first, which is good. So I already have a copy of the repo on my local machine.

Do I automatically have access have my host file system from the docker container? I think I was partly confused by d/boot_dev --init because I didn’t know what the d/ part was (I don’t see a folder called d for example in the repo, even though I do see boot_dev).

3 « J'aime »

The d is on the repo (scroll further down) — it is not a folder but a symlink to bin/docker. You should get it if you do the git clone.

I haven’t used this setup extensively myself, but my understanding is that you edit the source files directly in your host filesystem (that you have just checked out) and the docker containers mount that and run from it. The d/* scripts will to most of the docker setup work for you.

6 « J'aime »

Thanks for that. I didn’t even think to look past the folders. I think I have enough information to make another pass at this.

3 « J'aime »

I’m still getting something wrong. Between this topic, here, and here, nowhere just states what docker command to run. I settled on docker run -ti -v LocalRepoPath:/src discourse/discourse_dev, which initialized a whole bunch of stuff and seemingly mounted the repo to /src. But I can’t run d/boot_dev --init for some reason. Even just running ls in the repo’s top-level directory gives me:

ls: cannot access 'adminjs': Input/output error
ls: cannot access 'd': Input/output error
ls: cannot access 'jsapp': Input/output error

Does anyone know what’s going on here?

3 « J'aime »

You might be overcomplicating this: the tutorial on the first post already has everything you need to get started.

The d/* commands will do all the docker command magic so that you don’t have to. Once you have cloned the repo, the d/boot_dev --init and the d/unicorn commands (that you do on the host machine) should be all it takes to get http://localhost:9292 working. Those scripts will call docker to generate the container and start it for you. The d/shutdown_dev will stop it.

If you are getting those errors while browsing the repo files on the host, then something else seems amiss with your filesystem. Did you run out of disk space perhaps?

4 « J'aime »

sigh, I see. I thought those had to be run in docker. That said, d/boot_dev --init apparently doesn’t work on Windows in Powershell (which I guess is why this docker guide only mentions Mac and Ubuntu hosts). I tried to run the command in my linux subsystem (v1), but of course that fails at the docker step since I installed docker on Windows, not on the linux subsystem.


Next I tried to run it in git bash for Windows. I couldn’t run d/boot_dev --init (error “d/boot_dev: Is a directory”), but I was able to run bin/docker/boot_dev --init. This got a lot further, doing a bunch of pulls, but then it failed with

C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: Mount denied:
The source path “PathToRepo/data/postgres;C”
doesn’t exist and is not known to Docker.

I was able to get past that (I think) by escaping the mount path, per:
Docker mounted volume adds ;C to end of windows path when translating from linux style path - Stack Overflow

After that I got this error:

C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused “exec: "C:/Program Files/Git/sbin/boot": stat C:/Program Files/Git/sbin/boot: no such file or directory”: unknown.

C:/Program Files/Git/sbin/boot doesn’t exist on my file system, so I guess the error’s not surprising. The only thing mentioning sbin/boot in the boot_dev file is this part of the docker command: discourse/discourse_dev:release /sbin/boot.

And that’s pretty much where I’m at right now… I don’t really know what to try at this point.

3 « J'aime »

I’m afraid that’s how far I’m able to help you as I’m not familiar with windows.

Perhaps @rishabh is able to confirm whether this is supposed to work on windows too and update any missing steps for that (or add a note if it doesn’t).

3 « J'aime »

@sam Is what I’m trying to do even a remotely supported way of running Discourse for development? In the Windows development thread you mentioned trying this, but it hasn’t been going great so far. Basic (non-Discourse) Ubuntu containers technically work, but not the specific commands in this thread’s OP.

You originally mentioned this to me:

So unless you have a suggestion to get me through the issues I’m having with Docker on Windows, it’s probably best for me to cut my losses and run it in an Ubuntu VM using something like Virtual Box.

2 « J'aime »

So many of us are on the slow ring with zero issues. Games work, steam works everything works.

I do get the fear here, but it really is not a giant deal. Anyway if this is just too scary for you, I recommend a traditional VM like Hyper-V or VirtualBox. Install Docker in there and use our docker dev setup.

6 « J'aime »

If this wasn’t my primary (and only) computer I would join you on the slow ring, but I just can’t risk it. So I’ll go with a traditional VM with docker. Thanks again for the advice. I hope to have something up and running soon.

What would be sufficient for disk space and RAM to allocate to the VM? I was thinking maybe 16GB of disk space and 4GB of RAM, but I wanted to check first.

1 « J'aime »

That would probably be enough, best way to find the ideal recipe is to experiment

6 « J'aime »

Alright, I’m close to getting this working for real. I have a local instance running using docker in an ubuntu VM. I assume that I should only run d/boot_dev --init the very first time, and after that I’d just run d/boot_dev. Is that accurate? The reason I ask is that d/unicorn works when I include --init, but doesn’t work when I omit the --init from d/boot_dev. When it fails to start I get the error

Could not find aws-partitions-1.270.0 in any of the sources.
Run bundle install to install missing gems.

But then running bundle install fails with

actionview_precompiler-0.2.2 requires ruby version >= 2.6, which is incompatible with the current version, ruby 2.5.1p57

Is there a specific version of ruby I should update to? Or is there something else going on?


My VM is Ubuntu 18.04 (LTS) and this time I was able to directly follow the instructions in the OP, so I’m not sure where I might have gone wrong (if something is wrong).

2 « J'aime »

You would not use bundle install you would use d/bundle install you want to install the bundle inside the container, the VM does not need Ruby.

4 « J'aime »

Yeah, I had a feeling that was the case, just didn’t know what the right way of running it in the container was. Thanks again for the help!

2 « J'aime »

I pulled the latest version of the repo and as usual d/unicorn tells me “Run bundle install to install missing gems.”. However, this time when I run d/bundle install I get the following:

Fetching source index from https://rubygems.org/

Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Could not fetch specs from https://rubygems.org/

So I can’t actually run Discourse at the moment. I have no idea if this is related to the pull (directly or indirectly) or if it’s something completely unrelated. Googling for the error hasn’t been particularly helpful, so I don’t know how to proceed.

1 « J'aime »

We you able to reach rubygems.org?

1 « J'aime »