FROM node:16.15-alpine

WORKDIR /app

RUN apk upgrade --update \
  && apk add bash git ca-certificates \
  && npm install -g bower npm

ADD .bowerrc bower.json package.json package-lock.json ./

RUN npm --unsafe-perm --production install

COPY . /app

RUN apk del git \
  && rm -rf /var/cache/apk/* \
  /app/.git

RUN adduser -H -S -g "Konga service owner" -D -u 1200 -s /sbin/nologin konga \
  && mkdir /app/kongadata /app/.tmp \
  && chown -R 1200:1200 /app/views /app/kongadata /app/.tmp

EXPOSE 1337

VOLUME /app/kongadata

ENTRYPOINT ["/app/start.sh"]
