Skip to content

Commit

Permalink
[Setup] Improve docker setup
Browse files Browse the repository at this point in the history
* Reduces the image size by using alpine and cleaning up after some things
* Simplify the initial setup instructions slightly
* Access via localhost:3000 instead of e621.local
  • Loading branch information
Earlopain committed Nov 14, 2021
1 parent 9bdae11 commit ce871e4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 92 deletions.
89 changes: 46 additions & 43 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
FROM ruby:2.7.3
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y gnupg2 wget
RUN apt-get update \
&& apt-get install -y gnupg2 wget \
&& rm -rf /var/lib/apt/lists/*

# Add custom sources
RUN wget -qO - https://deb.nodesource.com/setup_14.x | bash - >/dev/null 2>&1
RUN wget -qO - https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
RUN wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb https://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN wget -qO - https://deb.nodesource.com/setup_14.x | bash - >/dev/null 2>&1 \
&& wget -qO - https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb https://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list

RUN apt-get update
RUN apt-get install -y ffmpeg postgresql-client-12 nodejs yarn nginx build-essential pkg-config sudo
RUN apt-get update \
&& apt-get install -y ffmpeg postgresql-client-12 nodejs yarn nginx build-essential pkg-config sudo nano \
&& rm -rf /var/lib/apt/lists/*

# User setup
RUN useradd -m -s /bin/bash -U danbooru
RUN usermod -aG www-data danbooru
RUN echo "%danbooru ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/danbooru
RUN useradd -m -s /bin/bash -U danbooru \
&& usermod -aG www-data danbooru \
&& echo "%danbooru ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/danbooru

# libvips
RUN apt-get install -y libglib2.0-dev libexpat1-dev liblcms2-dev \
optipng libjpeg62-turbo-dev libjpeg-progs libgif-dev libpng-dev libexif-dev
ARG VIPS_DEPS="libglib2.0-dev libexpat1-dev liblcms2-dev optipng libjpeg62-turbo-dev libjpeg-progs libgif-dev libpng-dev libexif-dev"
ARG VIPS_VERSION=8.10.5
WORKDIR /tmp
RUN wget -q https://github.com/libvips/libvips/releases/download/v$VIPS_VERSION/vips-$VIPS_VERSION.tar.gz
RUN tar xf vips-$VIPS_VERSION.tar.gz
WORKDIR /tmp/vips-$VIPS_VERSION
RUN ./configure --prefix=/usr
RUN make install
RUN apt-get update \
&& apt-get install -y $VIPS_DEPS \
&& rm -rf /var/lib/apt/lists/* \
&& cd /tmp \
&& wget -q https://github.com/libvips/libvips/releases/download/v$VIPS_VERSION/vips-$VIPS_VERSION.tar.gz \
&& tar xf vips-$VIPS_VERSION.tar.gz \
&& cd vips-$VIPS_VERSION \
&& ./configure --prefix=/usr \
&& make install \
&& rm /tmp/vips-$VIPS_VERSION.tar.gz \
&& rm -rf /tmp/vips-$VIPS_VERSION

# shoreman
RUN wget -O /usr/bin/shoreman https://github.com/chrismytton/shoreman/raw/master/shoreman.sh
RUN chmod +x /usr/bin/shoreman
RUN wget -O /usr/bin/shoreman https://github.com/chrismytton/shoreman/raw/master/shoreman.sh \
&& chmod +x /usr/bin/shoreman

# prevent permission issues with volume mounts
RUN mkdir /app
RUN chown danbooru:danbooru /app
RUN mkdir /app/public
RUN chown danbooru:danbooru /app/public

RUN mkdir /app/node_modules
RUN mkdir /app/public/packs
RUN mkdir /app/public/packs-test
RUN mkdir /app/public/data

RUN chown danbooru:danbooru /app/node_modules
RUN chown danbooru:danbooru /app/public/packs
RUN chown danbooru:danbooru /app/public/packs-test
RUN chown danbooru:danbooru /app/public/data

RUN mkdir /home/danbooru/gems
RUN chown danbooru:danbooru /home/danbooru/gems
RUN mkdir /app \
&& chown danbooru:danbooru /app \
&& mkdir /app/public \
&& chown danbooru:danbooru /app/public \
&& mkdir /app/node_modules \
&& mkdir /app/public/packs \
&& mkdir /app/public/packs-test \
&& mkdir /app/public/data \
&& chown danbooru:danbooru /app/node_modules \
&& chown danbooru:danbooru /app/public/packs \
&& chown danbooru:danbooru /app/public/packs-test \
&& chown danbooru:danbooru /app/public/data \
&& mkdir /home/danbooru/gems \
&& chown danbooru:danbooru /home/danbooru/gems

USER danbooru

# Setup secrets
RUN mkdir -p ~/.danbooru/
RUN openssl rand -hex 32 > ~/.danbooru/secret_token
RUN openssl rand -hex 32 > ~/.danbooru/session_secret_key
RUN chmod 600 ~/.danbooru/*
RUN mkdir -p ~/.danbooru/ \
&& openssl rand -hex 32 > ~/.danbooru/secret_token \
&& openssl rand -hex 32 > ~/.danbooru/session_secret_key \
&& chmod 600 ~/.danbooru/*

WORKDIR /app
CMD [ "shoreman" ]
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
2. Clone the repo with `git clone https://github.com/zwagoth/e621ng.git`.
3. `cd` into the repo.
4. Run the following commands:
```
docker-compose build
docker-compose run e621 dropdb danbooru2 -h postgres
docker-compose run e621 /app/bin/setup
docker-compose up
```
After running the commands once only `docker-compose up` is needed to bring up the containers.
5. Add the following to your host file:
`192.168.64.78 e621.local`
```
docker-compose run e621 /app/bin/setup
docker-compose up
```
After running the commands once only `docker-compose up` is needed to bring up the containers.
5. This would be a good time to rewatch your favorite TV series installment, cook & have breakfast/lunch/dinner, walk the dog, clean your room, etc.<br>
By the time you get back the install will surely have completed.<sup>1</sup>
6. To confirm the installation worked, open the web browser of your choice and enter `http://e621.local` into the address bar and see if the website loads correctly.
6. To confirm the installation worked, open the web browser of your choice and enter `http://localhost:3000` into the address bar and see if the website loads correctly.
<sub><sup>1</sup> If the install did not finish by the time an activity is complete please select another activity to avoid crippling boredom.</sub>
Expand Down
5 changes: 2 additions & 3 deletions config/danbooru_default_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def post_sample_size

# List of memcached servers
def memcached_servers
%w(memcached:11211)
%w(127.0.0.1:11211)
end

def alias_implication_forum_category
Expand Down Expand Up @@ -926,7 +926,7 @@ def iqdbs_server
end

def elasticsearch_host
'elastic'
'127.0.0.1'
end

# Use a recaptcha on the signup page to protect against spambots creating new accounts.
Expand Down Expand Up @@ -970,7 +970,6 @@ def recommender_key
end

def redis_url
"redis://redis"
end

def bypass_upload_whitelist?(user)
Expand Down
4 changes: 0 additions & 4 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,4 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.hosts << 'e621ng.local'
config.hosts << 'e621.local'

end
44 changes: 19 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.4"
version: "3"

services:
e621:
Expand All @@ -7,75 +7,69 @@ services:
- .:/app
- node_modules:/app/node_modules
- public_packs:/app/public/packs
- public_packs:/app/public/packs-test
- public_packs_test:/app/public/packs-test
- post_data:/app/public/data
- gems:/home/danbooru/gems
environment:
DATABASE_URL: postgresql://postgres
RAILS_ENV: development
GEM_HOME: /home/danbooru/gems
DANBOORU_HOSTNAME: http://localhost:3000
DANBOORU_REDIS_URL: redis://redis
DANBOORU_ELASTICSEARCH_HOST: elastic
DANBOORU_MEMCACHED_SERVERS: memcached
depends_on:
- postgres
- redis
- memcached
- elastic

nginx:
image: nginx:stable
image: nginx:stable-alpine
volumes:
- ./public:/app/public
- post_data:/app/public/data
- public_packs:/app/public/packs
- public_packs:/app/public/packs-test
- public_packs_test:/app/public/packs-test
- ./docker/default.conf.template:/etc/nginx/templates/default.conf.template
environment:
NGINX_HOST: e621.local
NGINX_HOST: localhost
NGINX_PORT: 3000
depends_on:
- e621
networks:
default:
ipv4_address: 192.168.64.78
ports:
- "3000:3000"

postgres:
build: ./docker/postgres
environment:
- POSTGRES_USER=danbooru
- POSTGRES_DB=danbooru2
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- db_data:/var/lib/postgresql/data
ports:
- "34517:5432"

redis:
image: redis:latest
image: redis:alpine

memcached:
image: memcached:latest
image: memcached:alpine

elastic:
image: elasticsearch:7.14.2
mem_limit: 1gb
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- ES_JAVA_OPTS=-Xms1g -Xmx1g
volumes:
- elastic_data:/usr/share/elasticsearch/data

volumes:
gems:
db_data:
post_data:
elastic_data:
db_data:
gems:
node_modules:
post_data:
public_packs:

networks:
default:
name: e621
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.64.0/24
gateway: 192.168.64.1
public_packs_test:
7 changes: 4 additions & 3 deletions docker/default.conf.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen 80;
listen ${NGINX_PORT};
server_name ${NGINX_HOST};
root /app/public;
index index.html;
Expand Down Expand Up @@ -36,10 +36,11 @@ server {

location @app_server {
proxy_pass http://app_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
}

Expand Down
12 changes: 8 additions & 4 deletions docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM postgres:12
ARG BUILD_DEPS="git build-essential make postgresql-server-dev-12 ca-certificates"

RUN apt-get update
RUN apt-get install -y git build-essential postgresql-server-dev-12
RUN git clone https://github.com/r888888888/test_parser.git /tmp/test_parser
RUN make -C /tmp/test_parser install
RUN apt-get update && apt-get install -y $BUILD_DEPS --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& git clone https://github.com/r888888888/test_parser.git /tmp/test_parser \
&& cd /tmp/test_parser \
&& make install \
&& rm -rf /tmp/test_parser \
&& apt-get purge -y --auto-remove $BUILD_DEPS

0 comments on commit ce871e4

Please sign in to comment.