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

Improvements for Docker setup #1430

Draft
wants to merge 35 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4160c0
removed obsolete version from docker compose
Oaphi Oct 12, 2024
245f1c2
switched restart policy of services to on-failure:3
Oaphi Oct 12, 2024
5f8d218
removed zombie config from Dockerfile
Oaphi Oct 12, 2024
e5d8ab5
there is no sleep command in Dockerfile
Oaphi Oct 12, 2024
25029df
removed unnecessary console output from instructions on how to start …
Oaphi Oct 12, 2024
3a4d1cb
do not start Rails in dev mode immediately
Oaphi Oct 12, 2024
737c6eb
added Dockerfile.dev for local development purposes
Oaphi Oct 12, 2024
d446686
updated README for Docker setup to reflect that dev mode no longer au…
Oaphi Oct 12, 2024
86da6b2
made uwsgi Dockerfile configurable
Oaphi Oct 12, 2024
17d4095
documented usage of custom build configurations for Docker setup
Oaphi Oct 12, 2024
6704543
Merge branch 'develop' into 0valt/1398/docker-fixes
Oaphi Oct 12, 2024
882d79b
fixed typos in CLIENT_DOCKERFILE env variable
Oaphi Oct 12, 2024
00b4670
check for dev mode in entrypoint.sh should actually check against the…
Oaphi Oct 12, 2024
12856af
Merge branch 'develop' into 0valt/1398/docker-fixes
Oaphi Oct 20, 2024
c345552
added initial Dockerfile.amd
Oaphi Oct 20, 2024
796d4e0
installing nokogiri on Mac requires force_ruby_platform
Oaphi Oct 20, 2024
923914f
added amd64-specific deps to Dockerfile.amd
Oaphi Oct 20, 2024
be4f0e3
Merge branch 'develop' into 0valt/1398/docker-fixes
Oaphi Oct 21, 2024
4fc84c5
fixed incorrect Dockerfile for arm64 naming
Oaphi Oct 21, 2024
1ddb25e
assume-yes flag must be set
Oaphi Oct 22, 2024
10ae42a
do not set force-ruby-platform globally
Oaphi Oct 22, 2024
64fd35f
removed patch from installed additional deps
Oaphi Oct 22, 2024
d146b6c
apparently, we need gcc-multilib & g++-multilib
Oaphi Oct 22, 2024
fb3daf3
let's follow the official guidance on nokogiri on MacOS
Oaphi Oct 22, 2024
51abe66
install gcc:amd64 & g++:amd64 as multilib depend on them
Oaphi Oct 22, 2024
1326470
ditch using xcode-select as it's not available from the image
Oaphi Oct 23, 2024
b4792d5
don't forget to use system libraries for nokogiri compilation
Oaphi Oct 23, 2024
de361ae
added pkg-config, libxm2-dev, libxslt-dev deps
Oaphi Oct 23, 2024
8ccc2b3
debugging attempt
Oaphi Oct 23, 2024
5663a43
forgot to not return an error code
Oaphi Oct 23, 2024
8c1a5dc
back to simple install
Oaphi Oct 23, 2024
481ff00
restored libc6 installation
Oaphi Oct 23, 2024
7260c2d
forgot about --assume-yes again
Oaphi Oct 23, 2024
363f7c7
prevent nokogiri install from being overridden by bundle install
Oaphi Oct 23, 2024
add426f
switch to current supported platform name for arm64
Oaphi Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3.9"
services:
db:
restart: on-failure:3
build:
context: "."
dockerfile: docker/Dockerfile.db
Expand All @@ -20,10 +20,10 @@ services:


uwsgi:
restart: always
restart: on-failure:3
build:
context: "."
dockerfile: docker/Dockerfile
dockerfile: ${CLIENT_DOCKERFILE}
depends_on:
db:
condition: service_healthy
Expand All @@ -47,7 +47,7 @@ services:
- db

redis:
restart: always
restart: on-failure:3
image: redis:latest
healthcheck:
test: ["CMD", "redis-cli","ping"]
26 changes: 12 additions & 14 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
FROM ruby:3.0.0

# docker build -f docker/Dockerfile -t qpixel_uwsgi .

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 \
bison \
build-essential \
libssl-dev \
libyaml-dev \
libreadline-dev \
zlib1g-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev && \
apt-get install -y default-mysql-server
default-libmysqlclient-dev \
autoconf \
bison \
build-essential \
libssl-dev \
libyaml-dev \
libreadline-dev \
zlib1g-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev && \
apt-get install -y default-mysql-server

# Install nodejs and imagemagick
WORKDIR /opt
Expand Down
50 changes: 50 additions & 0 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM --platform=linux/arm64/v8 ruby:3.0.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 \
bison \
build-essential \
ruby-dev \
libssl-dev \
libyaml-dev \
libreadline-dev \
zlib1g-dev \
liblzma-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev && \
patch && \
apt-get install -y default-mysql-server

RUN dpkg --add-architecture amd64
RUN apt update
RUN apt install -y libc6:amd64

# 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

# Add core code to container
WORKDIR /code
COPY . /code

RUN gem install bundler -v 2.4.22
RUN bundle install
RUN gem install nokogiri --platform=ruby

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

43 changes: 43 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM ruby:3.0.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 \
bison \
build-essential \
libssl-dev \
libyaml-dev \
libreadline-dev \
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

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

EXPOSE 80 443 3000

RUN /code/docker/entrypoint.sh dev

# ensures continued running of the container
CMD sleep 7d
35 changes: 27 additions & 8 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ chmod +x docker/local-setup.sh
docker/local-setup.sh
```

Editing the `./.env` file will modify the corresponding variables used in the docker-compose.yml file but **NOT** the environment variables in the container. Editing the `./docker/env` file will change environment variables only in the running container.
Editing the `./.env` file will modify the corresponding variables used in the docker-compose.yml file but **NOT** the environment variables in the container.
Editing the `./docker/env` file will change environment variables only in the running container.

### Custom build config

Our Docker setup supports custom build configurations for the uwsgi contianer via the `CLIENT_DOCKERFILE` environment variable (see [compose-env](/docker/compose-env)). The default is `docker/Dockerfile`, which points to a preconfigured [production-like setup](/docker/Dockerfile). For developers who need more control over their setup, we also provide a [configuration](/docker/Dockerfile.dev) that is tailored for local development.

To use a custom build config, change the `CLIENT_DOCKERFILE` variable in the .env file that is automatically created by [local-setup.sh](/docker/local-setup.sh) in the project root.

## 2. Database File
Ensure `config/database.yml` has the username and password as defined in [docker/env](docker/env) file. The `config/database.yml` should already be gitignored.
Expand Down Expand Up @@ -61,17 +68,13 @@ NOTE: If you get an error like "Cannot connect to the Docker daemon at ...", you

## 4. Start Containers

Then start your containers!
Then start your containers:

```bash
docker compose up # append -d if you want to detach the processes, although it can be useful to see output into the terminal
Creating qpixel_redis_1 ... done
Creating qpixel_db_1 ... done
Creating qpixel_uwsgi_1 ... done
docker compose up # append -d (--detach) if you want, although it can be useful to see output in the terminal
```

The uwsgi container has a sleep command for 15 seconds to give the database a chance to start,
so don't expect to see output right away. After about 20 seconds, check to make sure the server is running (and verify port 3000, note that you can change this mapping in the `.env` file)
After about 20 seconds, check to make sure the server is running (and verify port 3000, note that you can change this mapping in the `.env` file)

```
qpixel_uwsgi_1 | => Booting Puma
Expand All @@ -94,6 +97,22 @@ and see the interface.

You can then click "Sign in" to login with what you defined for `$COMMUNITY_ADMIN_EMAIL` and `$COMMUNITY_ADMIN_PASSWORD`. Importantly, your password must be 6 characters or longer, otherwise the user won't be created.

### Custom build configs

If you are using a custom build config that doesn't automatically start Rails or our [config for local development](/docker/Dockerfile.dev), you will also have to manually start the server.

After the containers have started, connect to the uwsgi container (if you are using Docker Desktop, you can connect directly from the application):

```bash
docker exec -it qpixel-uwsgi-1 bash
```

And run the following command to start Rails (starting the server is intentionally disabled to allow for live debugging):

```bash
rails server -b 0.0.0.0
```

## 5. Login

Once you are logged in, you should see your icon in the top right:
Expand Down
1 change: 1 addition & 0 deletions docker/compose-env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ COMMUNITY_NAME=Dev Community
RAILS_ENV=development
CONFIRMABLE_ALLOWED_ACCESS_DAYS=2
ENV_FILE_LOCATION=./docker/env
CLIENT_DOCKERFILE=docker/Dockerfile
6 changes: 4 additions & 2 deletions docker/entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ fi
# If this isn't done again, there is a 500 error on the first page about posts
rails db:seed

# defaults to port 3000
rails server -b 0.0.0.0
# we don't start the server immediately in dev mode
if [[ "$1" != 'dev' ]]; then
rails server -b 0.0.0.0
fi
Loading