stashapp / stash

An organizer for your porn, written in Go. Documentation: https://docs.stashapp.cc
https://stashapp.cc/
GNU Affero General Public License v3.0
8.48k stars 756 forks source link

[Feature] arm64 docker image #1031

Closed blazejp83 closed 3 years ago

blazejp83 commented 3 years ago

Is your feature request related to a problem? Please describe. Currently the only docker image available is for x64 arch. Having an ARM based NAS I am unable to use that.

Describe the solution you'd like Add additional arm64 arch to docker repo.

Describe alternatives you've considered The only alternative is for user to either change hardware, or try to host the solution itself locally, but that is pretty much impossible on a closed NAS (like QNAP, for instance).

Additional context None

SabinBC commented 3 years ago

I made my own arm64 docker image two days ago and have been successfully testing the docker images since then. I don't think there are any missing features.

My system is an Odroid N2+with a semi/custom Ubuntu Minimal 20.04 LTS OS.

Amlogic S922X Processor (12nm fab) Quad-core Cortex-A73(up to 2.4Ghz) and Dual-core Cortex-A53 (up to 2Ghz) ARMv8-A architecture with Neon and Crypto extensions

here is my Dockerfile with 2 basic changes

  1. curl -L -o /stash get the stash-linux-arm64 build
  2. curl --http1.1 -o /ffmpeg point to the arm64 release. Both of those two things have multiple versions, if it isn't working for you visit those sites and change the download to get an exact file matching your configuration
FROM ubuntu:20.04 as prep

RUN apt-get update && \
    apt-get -y install curl xz-utils && \
    apt-get autoclean -y && \
    rm -rf /var/lib/apt/lists/*
WORKDIR /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# explicitly get arm64 build
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases/latest | awk '/browser_download_url/ && /stash-linux-arm64/' | sed -e 's/.*: "\(.*\)"/\1/') && \
    chmod +x /stash

RUN curl --http1.1 -o /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz && \
    tar xf /ffmpeg.tar.xz && \
    rm ffmpeg.tar.xz && \
    mv /ffmpeg*/ /ffmpeg/

FROM ubuntu:20.04 as app
RUN apt-get update && apt-get -y install ca-certificates
COPY --from=prep /stash /ffmpeg/ffmpeg /ffmpeg/ffprobe /usr/bin/
EXPOSE 9999
CMD ["stash"]

and here is my docker-compose.yaml

# APPNICENAME=Stash
# APPDESCRIPTION=An organizer for your porn, written in Go
version: '3.4'
services:
  stash:
    image: stashapp
    restart: unless-stopped
    container_name: stashapp
    ports:
      - "9999:9999"
    logging:
      driver: "json-file"
      options:
        max-file: "10"
        max-size: "2m"
    environment:
      - STASH_STASH=/data/
      - STASH_GENERATED=/generated/
      - STASH_METADATA=/metadata/
      - STASH_CACHE=/cache/
    volumes:
      #- /etc/localtime:/etc/localtime:ro
      ## Adjust below paths (the left part) to your liking.
      ## E.g. you can change ./config:/root/.stash to ./stash:/root/.stash

      ## Keep configs here.
      - /whereeveryoulikeittobe/config:/root/.stash
      ## Point this at your collection.
      - /whereeveryoulikeittobe/data:/data
      ## This is where your stash's metadata lives
      - /whereeveryoulikeittobe/metadata:/metadata
      ## Any other cache content.
      - /whereeveryoulikeittobe/cache:/cache
      ## Where to store generated content (screenshots,previews,transcodes,sprites)
      - /whereeveryoulikeittobe/generated:/generated

You need docker and docker-compose - however you get those for your system. To build image run this code where the Dockerfile is located (you do need the (.) period at the end), -t names the image for you, you can change it here, but you'll need to match it to your docker-compose image: whateveryoufeel/likenamingit

docker build -t stashapp .

after this has run successfully (if it has) from the directory your docker-compose.yaml file is in do:

docker-compose up -d

Hopefully someone with more docker experience can make this a multi-arch build on hub.docker.com in future. If you're paying attention you might notice that this build is missing packr2/yarn/etc... files. There is no arm64 release for packr2. I do not know what it is for. I do not know go language. packr2 is supposed to be replaced by (https://github.com/markbates/pkger) which does have an arm64 build. I'm attempting to get the stash-box working but I'm at least 50% out of my depth on that effort.

Tweeticoats commented 3 years ago

Below is my docker file that I'm working on to build all architectures using the multi platform builder.

This docker file:

  1. copies all binaries to the prep image.
  2. determines what platform it is running on
  3. Downloads the ffmpeg binary for that platform
  4. renames the binary for that platform to /stash
  5. Create a runtime container and install python
  6. Copy ffmpeg and stash from prep
FROM --platform=$BUILDPLATFORM alpine  AS prep
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN apk add --no-cache curl xz
WORKDIR /
COPY stash-*  /
RUN if [ "$TARGETPLATFORM" = "linux/arm/v6" ]; then FFMPEG_URL=https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-armel-static.tar.xz;BIN=stash-pi; elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then FFMPEG_URL=https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-armhf-static.tar.xz;BIN=stash-linux-arm32v7; elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then FFMPEG_URL=https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz;BIN=stash-linux-arm64v8;elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then FFMPEG_URL=https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz;BIN=stash-linux;  fi; \
    curl --http1.1 -o /ffmpeg.tar.xz $FFMPEG_URL && \
    tar xf /ffmpeg.tar.xz && \
    rm ffmpeg.tar.xz && \
    mv /ffmpeg*/ /ffmpeg/ && \
    mv $BIN /stash

FROM alpine as app
run apk add --no-cache python3 py3-requests sqlite-libs && ln -s /usr/bin/python3 /usr/bin/python
COPY --from=prep /ffmpeg/ffmpeg /ffmpeg/ffprobe /stash /usr/bin/

EXPOSE 9999
CMD ["stash"]

What we need to do is set up a multi platform builder and I have this working locally but had problems recreating the setup in travis so I have not created a pull request yet. To do this we need a slightly newer docker and a newer os image (we are using xenial ie ubuntu 16.04) so we should update this to ubuntu 18.04 or newer. We also need to install / configure buildx and create a builder. buildx is an alternate builder from the default included builder and adds support for distributed builds and support for multiple platforms. To build an arm based image you can create a builder that uses an arm emulator to build these images.

mrhotio commented 3 years ago

Give her a test https://hotio.dev/containers/stash/

docker pull hotio/stash docker pull ghcr.io/hotio/stash

both arm and arm64 available

bnkai commented 3 years ago

Closing since arm docker images are now available.