From eb40832068f3efb531c843a176ad7f1dcc9340eb Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Fri, 10 May 2019 15:51:02 -0400 Subject: [PATCH] Created ARM and Raspberry Pi Support for Docker builds (markdown) --- ...-Raspberry-Pi-Support-for-Docker-builds.md | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 ARM-and-Raspberry-Pi-Support-for-Docker-builds.md diff --git a/ARM-and-Raspberry-Pi-Support-for-Docker-builds.md b/ARM-and-Raspberry-Pi-Support-for-Docker-builds.md new file mode 100644 index 0000000..ae8a8c3 --- /dev/null +++ b/ARM-and-Raspberry-Pi-Support-for-Docker-builds.md @@ -0,0 +1,190 @@ +Per [this post](https://github.com/rr-/szurubooru/issues/192#issuecomment-476897156) by [WychWitch](https://github.com/WychWitch) + +> Here are my files! If this isn't enough let me know, I might've forgotten one. Again, this is only for rpi3/arm32v7 +> +> replace all of the [name] and [password] with your own! + +**Client/Dockerfile** +```Docker +FROM arm32v7/node:9 as builder +WORKDIR /opt/app + +COPY package.json ./ +RUN npm install + +COPY . ./ + +ARG BUILD_INFO="docker-latest" +ARG CLIENT_BUILD_ARGS="" +RUN BASE_URL="__BASEURL__" node build.js --gzip ${CLIENT_BUILD_ARGS} + + +FROM tobi312/rpi-nginx:alpine +WORKDIR /var/www + +RUN \ + # Create init file + echo "#!/bin/sh" >> /init && \ + echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' >> /init && \ + echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|g" /var/www/index.htm /var/www/manifest.json' >> /init && \ + echo 'exec nginx' >> /init && \ + chmod a+x /init + +CMD ["/init"] +VOLUME ["/data"] + +COPY nginx.conf.docker /etc/nginx/nginx.conf +COPY --from=builder /opt/app/public/ . +``` +**Server/Dockerfile** +``` +FROM scratch as approot +WORKDIR /opt/app + +COPY alembic.ini wait-for-es generate-thumb ./ +COPY szurubooru/ ./szurubooru/ +COPY config.yaml.dist ./ + + +FROM python:3.6-slim +WORKDIR /opt/app + +ARG PUID=1000 +ARG PGID=1000 +ARG PORT=6666 +RUN \ + # Set users + mkdir -p /opt/app /data && \ + groupadd -g ${PGID} app && \ + useradd -d /opt/app -M -c '' -g app -r -u ${PUID} app && \ + chown -R app:app /opt/app /data && \ + # Create init file + echo "#!/bin/sh" >> /init && \ + echo "set -e" >> /init && \ + echo "cd /opt/app" >> /init && \ + echo "./wait-for-es" >> /init && \ + echo "alembic upgrade head" >> /init && \ + echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \ + >> /init && \ + chmod a+x /init && \ + # Install ffmpeg + apt-get -yqq update && \ + apt-get -yq install --no-install-recommends ffmpeg libpq-dev make gcc libffi-dev zlib1g-dev libjpeg-dev libtiff-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl-dev && \ + rm -rf /var/lib/apt/lists/* && \ + # Install waitress + pip3 install --no-cache-dir waitress + +COPY --chown=app:app requirements.txt ./requirements.txt +RUN pip3 install --no-cache-dir -r ./requirements.txt + +# done to minimize number of layers in final image +COPY --chown=app:app --from=approot / / + +VOLUME ["/data/"] +EXPOSE ${PORT} +USER app +CMD ["/init"] +``` +**.env** +``` +# Database credentials +POSTGRES_USER=[name] +POSTGRES_PASSWORD=[password] + +# This shows up on the homescreen, indicating build information +BUILD_INFO=latest + +# Port to expose HTTP service +PORT=[port] + +# Directory to store image data +## remember to chmod this directory +MOUNT_DATA=/var/local/[name]/data + +# Directory to store database files +MOUNT_SQL=/var/local/[name]/sql +``` + +**requirements.txt** +``` +alembic>=0.8.5 +pyyaml>=3.11 +psycopg2-binary>=2.6.1 +SQLAlchemy>=1.0.12 +coloredlogs==5.0 +elasticsearch>=5.0.0 +elasticsearch-dsl>=5.0.0 +numpy>=1.8.2 +pillow>=4.3.0 +pynacl==1.2.1 +pytz>=2018.3 +pyRFC3339>=1.0 +``` + +**docker-compose.yml**; +``` +## Example Docker Compose configuration +## +## Use this as a template to set up docker-compose, or as guide to set up other +## orchestration services +version: '2' + +services: + api: + build: + context: ./server + depends_on: + - sql + - elasticsearch + environment: + ## These should be the names of the dependent containers listed above, + ## or FQDNs/IP addresses if these services are running outside of Docker + POSTGRES_HOST: sql + ESEARCH_HOST: elasticsearch + ## Credentials for database: + POSTGRES_USER: [Name] + POSTGRES_PASSWORD: [pass] + ## Commented Values are Default: + #POSTGRES_DB: defaults to same as POSTGRES_USER + #POSTGRES_PORT: 5432 + #ESEARCH_PORT: 9200 + #ESEARCH_INDEX: szurubooru + #LOG_SQL: 0 (1 for verbose SQL logs) + volumes: + - "${MOUNT_DATA}:/data" + - "./server/config.yaml:/opt/app/config.yaml" + client: + build: + context: ./client + args: + BUILD_INFO: + depends_on: + - api + environment: + BACKEND_HOST: api + volumes: + - "${MOUNT_DATA}:/data:ro" + ports: + - "${PORT}:80" + sql: + image: postgres:alpine + restart: unless-stopped + environment: + POSTGRES_USER: [name] + POSTGRES_PASSWORD: [pass] + volumes: + - "${MOUNT_SQL}:/var/lib/postgresql/data" + elasticsearch: + image: ind3x/rpi-elasticsearch + environment: + ## Specifies the Java heap size used + ## Read + ## https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html + ## for more info + ES_JAVA_OPTS: -Xms512m -Xmx512m + volumes: + - index:/usr/share/elasticsearch/data + +volumes: + index: # Scratch space for ElasticSearch index, will be rebuilt if lost +``` \ No newline at end of file