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

Following developer guide #1

Open
smangham opened this issue Jul 25, 2022 · 8 comments
Open

Following developer guide #1

smangham opened this issue Jul 25, 2022 · 8 comments

Comments

@smangham
Copy link
Member

I'm following the developer installation guide here.

Tried to follow as closely as possible instead of just skipping straight to using a Docker image with NPM already on it, but I've run into a few issues documented here relating to the recommended versions of Node etc. being so old they're unsupported.

The Node official Docker images are Debian-based, so probably fine, but I'll start with Ubuntu 22.04.

@smangham
Copy link
Member Author

smangham commented Jul 25, 2022

Issues:

apt-get:

  • python-apt -> python-apt-common (...Is this still Python 2??? Guess we'll find out.)
  • libreadline6 -> Deprecated, libreadline6-dev installs the prereqs though
  • python-mysqldb -> python3-mysqldb
  • emacs is missing, but we surely don't need or want Emacs (nobody needs Emacs)

rbenv:

  • Need to up Ruby to 2.7
  • Bundler needs --no-document flags instead of obsolete ones
  • Won't install the rails-html-sanitizer gem through Gemfile, but will install manually
  • There's an issue with the tzinfo-data gem - had to remove the Gemfile lock and rebuild.

Running:

  • Rails is not installed
  • Once installed, Rails will not run with this error: https://github.com/collectiveidea/delayed_job is not yet checked out. Run 'bundle install' first.
    • Obviously, bundle install does nothing.
  • Actually, that happens when you try and run both rake commands at once - rake db:schema:load fails with an incorrect number of arguments error. Searching suggests this is down to the version of Rails used (it's old), but the Rails version is pinned in the Gemfile IIRC?

@smangham
Copy link
Member Author

Okay, trying again with ubuntu:latest...

  • ln -s /usr/bin/nodejs /usr/bin/node is unnecessary, crashes as node is already linked.

  • There's a spurious -v on the bundler install.

  • tzinfo-data is missing from the Gemfile, you can't manually install it - it requires you add it to the gemfile.
    Okay, then it builds.

  • Running webpack... we get: Error: Cannot resolve 'file' or 'directory' ./product_page/payment in /considerit/@client @ ./@client/app.coffee 84:2-35 - but we aren't using payment so hopefully this is just a weird oversight

  • ...then Rails is not found. Must not be in the gemfile. Gem install rails works and runs.

  • Rails doesn't like running in a docker container, you need to use rails s -p 3000 -b 0.0.0.0 to ensure it can access the ports out

  • The webpage gives the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2). I had to commit the container to an image and re-launch to map the ports out - possibly this means the mysql stuff went wrong? I'll rerun the MySQL commands.
    It works! You can create an account, and see the landing page. There are no questions and no option to create any - I need to move onto trying to set up my account as admin.

@smangham
Copy link
Member Author

Super-admin process works, background job process works, everything's gravy. Should probably update the .bash_profile file to automatically rerun the MySQL and .profile bits so it works properly on restart so we can hook the image up to Docker compose properly.

@smangham smangham transferred this issue from another repository Jul 28, 2022
@smangham
Copy link
Member Author

smangham commented Aug 2, 2022

So... the .profile and .bash_profile files only execute if the container is run interactively. You can't really run anything to add environment variables dynamically, so I need to do them all as ENV name=value statements instead. Fortunately, it can take ENV PATH /master/go/bin:${PATH}...

The statements the build process adds to the .profile file are:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

And rbenv init - gives:

export PATH="/root/.rbenv/shims:${PATH}"
export RBENV_SHELL=bash
source '/root/.rbenv/libexec/../completions/rbenv.bash'
command rbenv rehash 2>/dev/null
rbenv() {
  local command
  command="${1:-}"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "$(rbenv "sh-$command" "$@")";;
  *)
    command rbenv "$command" "$@";;
  esac
}

So I can stick most of that in the PATH via env variables, and still run rbenv init - anyway.
Actually, this is complicated by the fact that rbenv init - and /root/.rbenv/libexec/../completions/rbenv.bash both define new bash commands. Can I just source (or ., rather) these files?

Turns out $HOME doesn't work in ENV statements even though $PATH does and $PATH is user-specific too right?

OK, now MySQL is erroring:

rake aborted!
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Tasks: TOP => db:schema:load => db:check_protected_environments
(See full trace by running task with --trace)
The command '/bin/sh -c cp config/dev_database.yml config/database.yml &&     cp config/dev_local_environment.yml config/local_environment.yml &&     rm Gemfile.lock &&     gem install rails &&     bundle install &&     npm install &&     rake db:schema:load &&     rake db:migrate' returned a non-zero code: 1

@smangham
Copy link
Member Author

smangham commented Aug 5, 2022

OK, so the MySQL server does not actually run during the Docker build process... only once built. This bug report suggests that the SQL server data can't be changed during the build process... however, it didn't seem to object to me creating the considerit_dev DB on an earlier line? So actually to achieve this I'll just need to manually force the MySQL service to start at the beginning of the RUN command in Docker so it's available for rake.

This works, but now we run into the issue that we want to have multiple services running simultaneously - the bin/webpack command can probably be dropped, but we want to have delayed_job running. Docker doesn't like running multiple commands in one entrypoint... so maybe we can run delayed_job in the build process?

OK, well, attempting to run it fails. Error logs show MySQL is not running. Why is MySQL not started by default in the container?
I guess I'm supposed to use docker-compose to launch a separate MySQL instance...

Possible reason: MySQL gives MySQL won't start - error: su: warning: cannot change directory to /nonexistent: No such file or directory but runs anyway, may be as it's not logged in as a user?
https://stackoverflow.com/questions/62987154/mysql-wont-start-error-su-warning-cannot-change-directory-to-nonexistent

OK, now it errors with No such file or directory @ rb_sysopen - public/build/manifest.json, which looks like it might be down to me removing the webpack (the format given watches the directory, but we also still need it to run at least once).

Sorted! It now also runs using docker-compose. The next step would be to start breaking it up into multiple services - it should use a node.js image for the main server, have the DB in a separate mysql image, and save data to a persistent volume. For now, I'll just build and run using docker build/docker run. Also need to set up an nginx profile for port 3001 on the server.

@smangham
Copy link
Member Author

smangham commented Aug 5, 2022

Building on the VM, will take some time...

@smangham
Copy link
Member Author

smangham commented Aug 8, 2022

Okay, the VM instance errors on Chrome as:

roles.coffee:49 Uncaught TypeError: Cannot read properties of undefined (reading 'editor')
    at window.InitializeProposalRoles (roles.coffee:49:28)
    at BUTTON.onClick (new_proposal.coffee:315:17)
    at Object.s [as executeDispatch] (react.min.js:21:25073)
    at executeDispatch (react.min.js:21:126838)
    at i (react.min.js:21:24982)
    at Object.u [as executeDispatchesInOrder] (react.min.js:21:25126)
    at h (react.min.js:21:20834)
    at o (react.min.js:21:139254)
    at Object.processEventQueue (react.min.js:21:21940)
    at o (react.min.js:21:90460)

My local build errors on Firefox as:

Uncaught TypeError: proposal.roles is undefined
    InitializeProposalRoles roles.coffee:49
    onClick new_proposal.coffee:315
    React 14
[roles.coffee:49:4](webpack:///@client/dashboard/roles.coffee)
    InitializeProposalRoles roles.coffee:49
    onClick new_proposal.coffee:315
    React 14
    dispatchEvent self-hosted:1198

This seems more useful. I'll ask on the original ConsiderIt repo.

@smangham
Copy link
Member Author

The dev hadn't seen this error before, so I'm just syncing my fork .Unfortunately, it still doesn't work. I'm going to write up a short guide on how to run in Docker, and then share with him.

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