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

Make it directly usable in Docker #1336

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion config/initializers/zz_codidact_sites.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Rails.cache.persistent 'codidact_sites', clear: true do
# Do not show codidact_sites for development (allows offline dev)
# Do not spam codidact.com while running the tests.
if Rails.env.development? || Rails.env.test?
if Rails.env.development? || Rails.env.test? || ENV.fetch("COMMUNITY_OTHERS_SHOW", "true") == "false"
[]
else
response = Net::HTTP.get_response(URI('https://codidact.com/communities.json'))
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question - can you clarify a little as to what was the reasoning behind removing this migration? I presume there was a compelling reason for doing so, but lack context.

This file was deleted.

8 changes: 4 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_04_05_113618) do
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.bigint "community_id"
t.string "name"
t.text "description"
Expand All @@ -26,7 +26,7 @@
t.index ["community_id"], name: "index_abilities_on_community_id"
end

create_table "ability_queues", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "ability_queues", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.bigint "community_user_id"
t.text "comment"
t.boolean "completed"
Expand Down Expand Up @@ -370,7 +370,7 @@
t.index ["post_id"], name: "index_pinned_links_on_post_id"
end

create_table "post_flag_types", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "post_flag_types", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.bigint "community_id"
t.string "name"
t.text "description"
Expand Down Expand Up @@ -671,7 +671,7 @@
t.index ["user_id"], name: "index_thread_followers_on_user_id"
end

create_table "user_abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "user_abilities", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.bigint "community_user_id"
t.bigint "ability_id"
t.boolean "is_suspended", default: false
Expand Down
32 changes: 12 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM ruby:3.0.0

# docker build -f docker/Dockerfile -t qpixel_uwsgi .
FROM ruby:3.1.0

ENV RUBYOPT="-KU -E utf-8:utf-8"
RUN apt-get update && \
apt-get install -y gcc && \
apt-get install -y make && \
apt-get install -y \
default-libmysqlclient-dev \
autoconf \
autoconf \
bison \
build-essential \
libssl-dev \
Expand All @@ -17,27 +15,21 @@ RUN apt-get update && \
zlib1g-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev && \
apt-get install -y default-mysql-server

# Install nodejs and imagemagick
WORKDIR /opt
RUN wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz && \
tar xf node-v12.18.3-linux-x64.tar.xz && \
wget https://imagemagick.org/archive/binaries/magick && \
chmod +x magick && \
mv magick /usr/local/bin/magick

ENV NODEJS_HOME=/opt/node-v12.18.3-linux-x64/bin
ENV PATH=$NODEJS_HOME:$PATH
libgdbm-dev \
nodejs \
node-imagemagick \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB!

If anyone decides to port this change, please, review that the Node.js version pulled is compatible or, better, yet, fix it to a specific version range (as we should do with all other dependencies, tbh).

imagemagick

# Add core code to container
WORKDIR /code
COPY . /code
COPY Gemfile Gemfile.lock /code/
RUN gem install bundler -v 2.4.22 && \
bundle install

COPY . /code
RUN bundle exec rails assets:precompile && \
chmod -R 0777 /code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB!

If anyone decides to port this change, please note that we do not have (yet) a separate Dockerfile for development and precompiled assets are not excluded from git tracking via .gitignore, meaning that without changing the above, doing so will heavily pollute the working directory.


EXPOSE 80 443 3000
ENTRYPOINT ["/bin/bash"]
CMD ["/code/docker/entrypoint.sh"]

CMD ["/code/docker/entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/create_admin_and_community.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 1. Create the community
community_name = ENV['COMMUNITY_NAME'] || 'Dinosaur Community'
Community.create(name: community_name, host: "localhost:#{ENV.fetch('LOCAL_DEV_PORT', nil)}")
Community.create(name: community_name, host: "#{ENV.fetch('COMMUNITY_HOST', 'localhost:3000')}")
Rails.cache.clear

# 2. Create the admin user, ensure doesn't require confirmation
Expand Down
14 changes: 9 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/bin/bash

# If not created yet
if [ ! -f "/db-created" ]; then
if [ ! -f "/tmp/db-created" ]; then
echo "Creating database"
rails db:create
rails db:schema:load
rails r db/scripts/create_tags_path_view.rb
echo "Migrating database"
rails db:migrate
rails db:migrate RAILS_ENV=development
rails r db/scripts/create_tags_path_view.rb
echo "Creating community"
rails r docker/create_admin_and_community.rb
echo "Seeding database"
UPDATE_POSTS=true rails db:seed
touch /db-created
touch /tmp/db-created
fi

# If this isn't done again, there is a 500 error on the first page about posts
echo "Seeding database"
rails db:seed

# defaults to port 3000
echo "Starting server 0.0.0.0:3000"
Copy link
Member

@Oaphi Oaphi Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB!

If anyone decides to port this change, do note that the port is configurable, so without making it a variable, this will likely report an incorrect port (I have qpixel running on 3014 myself, for example).

rails server -b 0.0.0.0
Loading