Unable to create web_only image for a fresh install

Hello :blush:

I am still trying to create our pipeline to work with Discourse.
I have a fresh Redis container and a fresh Postgres container to use with discourse.
Next step for me is build the image of the web_only container to then connect them and start the installation if I am right, but I am unable to bootsrap the container.

I am getting this error:

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 4632 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
0e576a9672a887d23579100756224f920ab595b819874b5e7cbe4868f4234481
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.

I am confused about why is trying to migrate when I have nothing built yet. Am I doing the steps wrong?
This is the web_only.yml I am using (pretty basic one):

templates:
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
env:
  LANG: en_US.UTF-8
  UNICORN_WORKERS: 2
  DISCOURSE_DB_USERNAME: root
  DISCOURSE_DB_PASSWORD: my-secret-pw
  DISCOURSE_DB_HOST: 127.0.0.1
  DISCOURSE_DB_NAME: communities
  DISCOURSE_DEVELOPER_EMAILS: 'email@mail.com'
  DISCOURSE_HOSTNAME: 'localhost'
  DISCOURSE_REDIS_HOST: 127.0.0.1
  SKIP_POST_DEPLOYMENT_MIGRATIONS: 1
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-voting.git
          - git clone https://github.com/discourse/discourse-slack-official.git
          - git clone https://github.com/discourse/discourse-assign.git
run:
  - exec:
      cd: /var/www/discourse
      cmd:
        - sed -i 's/GlobalSetting.serve_static_assets/true/' config/environments/production.rb
        - bash -c "touch -a /shared/log/rails/{sidekiq,puma.err,puma}.log"
        - bash -c "ln -s /shared/log/rails/{sidekiq,puma.err,puma}.log log/"
        - sed -i 's/default \$scheme;/default https;/' /etc/nginx/conf.d/discourse.conf

Do I need to have a Postgres and a Redis container up and running everytime I need to bootstrap a build? I thought that I could prepare the images to upload them myself and then rerun my environments with them without the need of doing something to my database…

The pipeline I was asked to build is:

  • Github actions: that can bootstrap the image in case of an update is needed.
    • Push the image to a private registry.
  • Then my Kubernetes cluster could get updates and deploy them in my environments, from dev to prod.

Thanks again for all the help and support. :sparkles:

I think that your issue is that 127 doesn’t work inside the container. The bootstrap process migrates the database. If you don’t want it to migrate your database, you’ll need to change the template or use a scratch database.

2 Likes

Thansk for your reply :slight_smile:
Can you tell me how to avoid/skip a database migration, please? I thought it was with SKIP_POST_DEPLOYMENT_MIGRATIONS: 1

I can’t. I recommend that you create a scratch database that you destroy after the migration.

And when you do, you’ll need to see that all those things happen when you deploy the new image.

The point is that I don’t understand why a database migration is happening when there is nothing to migrate because I am creating my first image for a fresh install :frowning:

1 Like

Migration is a technical terms used in context of Rails. Migrations create the correct db structure basically.

2 Likes

Discourse can’t run if the database isn’t populated with the tables and data that it requires. It also needs to precompile assets. You’ll need to understand how those work if you’re going to try to deploy some other way.

1 Like

Thanks for clarifying it for me. I thought the first DB structure could be made in the first launch of the forum.

Thanks a lot for the reply. I will continue thinking about this. It seems that may be it is not possible to prepare a pipeline like the way I need it then. :frowning:

It can, but you’d need to explicitly do that. And the easiest way to build the image is to let it migrate a scratch database.

1 Like

I will try to convince my team to ask for a temporary Postgres DB during the github pipeline then, thank you so much for all the help

1 Like