FROM ruby:alpine3.18

RUN apk add imagemagick ruby-full g++ make npm 
RUN apk add --update alpine-sdk

COPY Gemfile .

RUN bundle install --jobs 4 --retry 3

RUN npm install -g mermaid.cli

RUN apk add gcompat

RUN gem uninstall google-protobuf --force
RUN gem install google-protobuf --platform=ruby
RUN gem install ffi -v 1.16.1
RUN gem uninstall ffi -v 1.16.2
RUN gem install unicode-display_width -v 2.4.2
RUN gem install activesupport -v 7.0.8

RUN mkdir -p /usr/app

WORKDIR /usr/app

COPY . .

RUN bundle exec jekyll build

RUN find . -maxdepth 1 ! -name '_site' -exec rm -rf {} \;

RUN mv _site/* .

RUN rm -R _site docker README.md LICENSE.md

FROM cupcakearmy/static

COPY --from=0 /usr/app /srv
